codeArea.richChanges() .filter(ch -> !ch.getInserted().equals(ch.getRemoved())) .subscribe(change -> codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()))); SearchBar searchBar = new SearchBar(codeArea); searchBar.setCloseAction(e -> { setShowDetailNode(false); codeArea.requestFocus(); }); setMasterNode(new VirtualizedScrollPane(codeArea)); setDetailNode(searchBar); setDetailSide(Side.TOP); setShowDetailNode(false); setOnKeyPressed((KeyEvent ke) -> { if (searchKeyCombination.match(ke)) { if (codeArea.getSelectedText() != null && !"".equals(codeArea.getSelectedText())) { searchBar.setSearchPattern(codeArea.getSelectedText()); if (!isShowDetailNode()) { setShowDetailNode(true);
@Override public void save() { if (!saved.getValue()) { // write script but remove listener before to avoid double update storableScript.removeListener(this); storableScript.writeScript(codeEditor.getCode()); storableScript.addListener(this); saved.setValue(true); } }
Token token = tokenStream.nextToken(); while (token.getType() != Token.EOF_TYPE) { String styleClass = styleClass(token.getType()); int length = length((GroovySourceToken) token); if (styleClass != null) { spansBuilder.add(Collections.singleton(styleClass), length);
private void updateScript() { scriptUpdateService = GseUtil.createService(new Task<String>() { @Override protected String call() { return storableScript.readScript(); } }, context.getExecutor()); progressIndicator.visibleProperty().bind(scriptUpdateService.runningProperty()); codeEditor.disableProperty().bind(scriptUpdateService.runningProperty()); scriptUpdateService.setOnSucceeded(event -> { String scriptContent = (String) event.getSource().getValue(); codeEditor.setCode(scriptContent); saved.set(true); }); scriptUpdateService.start(); }
public ModificationScriptEditor(StorableScript storableScript, Scene scene, GseContext context) { this.storableScript = storableScript; this.context = context; codeEditor = new GroovyCodeEditor(scene); Text saveGlyph = Glyph.createAwesomeFont('\uf0c7').size("1.3em"); saveButton = new Button("", saveGlyph); saveButton.getStyleClass().add("gse-toolbar-button"); saveButton.disableProperty().bind(saved); saveButton.setOnAction(event -> save()); codeEditorWithProgressIndicator = new StackPane(codeEditor, new Group(progressIndicator)); codeEditor.codeProperty().addListener((observable, oldValue, newValue) -> saved.set(false)); splitPane = new SplitPane(codeEditorWithProgressIndicator); toolBar = new ToolBar(saveButton); splitPane.setOrientation(Orientation.VERTICAL); splitPane.setDividerPosition(0, 0.8); setTop(toolBar); setCenter(splitPane); // listen to modifications storableScript.addListener(this); }
public void setCode(String code) { codeArea.clear(); codeArea.replaceText(0, 0, code); codeArea.showParagraphAtTop(0); resetDividerPosition(); }