1
0
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:
Victor 2017-09-06 14:58:15 +03:00
parent 8001d99a85
commit ca97bfc554
2 changed files with 18 additions and 2 deletions

View File

@ -20,9 +20,11 @@ import java.util.Arrays;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane; import javafx.scene.control.TitledPane;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -32,6 +34,9 @@ import org.fxmisc.richtext.LineNumberFactory;
public class EditorController implements Initializable, DocumentListener { public class EditorController implements Initializable, DocumentListener {
@FXML
private Button undoButton, redoButton;
@FXML @FXML
private CodeArea editor; private CodeArea editor;
@ -120,7 +125,18 @@ public class EditorController implements Initializable, DocumentListener {
syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor()); syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor());
syntaxHighlighter.init(); syntaxHighlighter.init();
documentManager = new FileManager(); documentManager = new FileManager();
initUndoRedo();
openSample(); 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) { public void setPrimaryStage(Stage primaryStage) {

View File

@ -31,12 +31,12 @@
</Menu> </Menu>
</MenuBar> </MenuBar>
<ToolBar> <ToolBar>
<Button> <Button fx:id="undoButton">
<graphic> <graphic>
<FontAwesomeIcon icon="undo"/> <FontAwesomeIcon icon="undo"/>
</graphic> </graphic>
</Button> </Button>
<Button> <Button fx:id="redoButton">
<graphic> <graphic>
<FontAwesomeIcon icon="redo"/> <FontAwesomeIcon icon="redo"/>
</graphic> </graphic>