mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Add undo/redo functionality
This commit is contained in:
parent
8001d99a85
commit
ca97bfc554
@ -20,9 +20,11 @@ import java.util.Arrays;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.Executors;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TitledPane;
|
||||
import javafx.stage.Stage;
|
||||
@ -32,6 +34,9 @@ import org.fxmisc.richtext.LineNumberFactory;
|
||||
|
||||
public class EditorController implements Initializable, DocumentListener {
|
||||
|
||||
@FXML
|
||||
private Button undoButton, redoButton;
|
||||
|
||||
@FXML
|
||||
private CodeArea editor;
|
||||
|
||||
@ -120,7 +125,18 @@ public class EditorController implements Initializable, DocumentListener {
|
||||
syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor());
|
||||
syntaxHighlighter.init();
|
||||
documentManager = new FileManager();
|
||||
initUndoRedo();
|
||||
openSample();
|
||||
editor.getUndoManager().forgetHistory();
|
||||
}
|
||||
|
||||
private void initUndoRedo() {
|
||||
undoButton.disableProperty().bind(
|
||||
Bindings.not(editor.undoAvailableProperty()));
|
||||
redoButton.disableProperty().bind(
|
||||
Bindings.not(editor.redoAvailableProperty()));
|
||||
undoButton.setOnAction(a -> editor.undo());
|
||||
redoButton.setOnAction(a -> editor.redo());
|
||||
}
|
||||
|
||||
public void setPrimaryStage(Stage primaryStage) {
|
||||
|
@ -31,12 +31,12 @@
|
||||
</Menu>
|
||||
</MenuBar>
|
||||
<ToolBar>
|
||||
<Button>
|
||||
<Button fx:id="undoButton">
|
||||
<graphic>
|
||||
<FontAwesomeIcon icon="undo"/>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button>
|
||||
<Button fx:id="redoButton">
|
||||
<graphic>
|
||||
<FontAwesomeIcon icon="redo"/>
|
||||
</graphic>
|
||||
|
Loading…
Reference in New Issue
Block a user