mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Ability to disable syntax highlighting
This commit is contained in:
parent
7d151188b6
commit
d2e85e1b87
@ -13,6 +13,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.concurrent.Task;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
@ -28,7 +29,7 @@ public class SyntaxHighlighter {
|
||||
private Set<String> nodeFunctions;
|
||||
private Map<HotaruTokenId, String> operatorClasses;
|
||||
|
||||
public void init() {
|
||||
public void init(BooleanProperty enabledProperty) {
|
||||
operatorClasses = new HashMap<>();
|
||||
operatorClasses.put(HotaruTokenId.AT, "keyframes-extractor");
|
||||
nodeFunctions = BundleLoader.functions().entrySet().stream()
|
||||
@ -36,6 +37,7 @@ public class SyntaxHighlighter {
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toSet());
|
||||
editor.richChanges()
|
||||
.filter(ch -> enabledProperty.get())
|
||||
.filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
|
||||
.successionEnds(Duration.ofMillis(500))
|
||||
.supplyTask(this::computeHighlightingAsync)
|
||||
|
@ -28,6 +28,7 @@ import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckMenuItem;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TitledPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
@ -39,6 +40,9 @@ import org.fxmisc.richtext.LineNumberFactory;
|
||||
|
||||
public class EditorController implements Initializable, DocumentListener {
|
||||
|
||||
@FXML
|
||||
private CheckMenuItem syntaxHighlightingItem;
|
||||
|
||||
@FXML
|
||||
private Button undoButton, redoButton;
|
||||
|
||||
@ -157,9 +161,8 @@ public class EditorController implements Initializable, DocumentListener {
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
editor.setParagraphGraphicFactory(LineNumberFactory.get(editor));
|
||||
syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor());
|
||||
syntaxHighlighter.init();
|
||||
documentManager = new FileManager();
|
||||
initSyntaxHighlighter();
|
||||
initUndoRedo();
|
||||
openSample();
|
||||
editor.getUndoManager().forgetHistory();
|
||||
@ -167,6 +170,22 @@ public class EditorController implements Initializable, DocumentListener {
|
||||
Platform.runLater(editor::requestFocus);
|
||||
}
|
||||
|
||||
private void initSyntaxHighlighter() {
|
||||
val highlightProperty = syntaxHighlightingItem.selectedProperty();
|
||||
highlightProperty.addListener((observable, oldValue, highlightEnabled) -> {
|
||||
if (highlightEnabled) {
|
||||
// create event to reinit highlighter
|
||||
val pos = editor.getCaretPosition();
|
||||
editor.insertText(pos, " ");
|
||||
editor.replaceText(pos, pos + 1, "");
|
||||
} else {
|
||||
editor.clearStyle(0, editor.getLength());
|
||||
}
|
||||
});
|
||||
syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor());
|
||||
syntaxHighlighter.init(highlightProperty);
|
||||
}
|
||||
|
||||
private void initUndoRedo() {
|
||||
undoButton.disableProperty().bind(
|
||||
Bindings.not(editor.undoAvailableProperty()));
|
||||
|
@ -33,6 +33,9 @@
|
||||
<MenuItem onAction="#handleMenuSaveAs" text="Save As" accelerator="Shift+Shortcut+S"/>
|
||||
<MenuItem onAction="#handleMenuExit" text="Exit"/>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="View">
|
||||
<CheckMenuItem fx:id="syntaxHighlightingItem" text="Syntax Highlighting" selected="true" />
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Composition">
|
||||
<MenuItem onAction="#handleMenuPlay" text="Preview" accelerator="F5"/>
|
||||
</Menu>
|
||||
|
Loading…
Reference in New Issue
Block a user