Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

fixed menu shortcuts: When the editor control (RichTextFX) is focused, it consumes all key events and the menu accelerators do not work. Workaround: install keyboard shortcuts into the editor component.

AuthorKarl Tauber <email>
Date2015-07-28 22:37:15 GMT+0200
Commitab482110c83e66a80675d6b4d0526dd0b5e32dff
Parent1605e3d
Delta31 lines added, 0 lines removed, 31-line increase
src/main/java/org/markdownwriterfx/editor/MarkdownEditorPane.java
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
+import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.ScrollBar;
+import javafx.scene.input.KeyEvent;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.undo.UndoManager;
+import org.fxmisc.wellbehaved.event.EventHandlerHelper;
import org.markdownwriterfx.util.Utils;
import org.pegdown.Extensions;
}
});
+ }
+
+ public void installEditorShortcuts(EventHandler<KeyEvent> editorShortcuts) {
+ EventHandlerHelper.install(textArea.onKeyPressedProperty(), editorShortcuts);
}
src/main/java/org/markdownwriterfx/MainWindow.java
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
+import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
+import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Window;
import javafx.stage.WindowEvent;
+import org.fxmisc.wellbehaved.event.EventHandlerHelper;
+import org.fxmisc.wellbehaved.event.EventPattern;
import de.jensd.fx.glyphs.GlyphIcons;
import de.jensd.fx.glyphs.GlyphsDude;
alert.initOwner(getScene().getWindow());
return alert;
+ }
+
+ /**
+ * When the editor control (RichTextFX) is focused, it consumes all key events
+ * and the menu accelerators do not work. Looks like a bug to me...
+ * Workaround: install keyboard shortcuts into the editor component.
+ */
+ private EventHandler<KeyEvent> editorShortcuts;
+ EventHandler<KeyEvent> getEditorShortcuts() {
+ if (editorShortcuts != null)
+ return editorShortcuts;
+
+ editorShortcuts = EventHandlerHelper
+ .on(EventPattern.keyPressed(KeyCode.N, KeyCombination.SHORTCUT_DOWN)).act(e -> fileNew())
+ .on(EventPattern.keyPressed(KeyCode.O, KeyCombination.SHORTCUT_DOWN)).act(e -> fileOpen())
+ .on(EventPattern.keyPressed(KeyCode.W, KeyCombination.SHORTCUT_DOWN)).act(e -> fileClose())
+ .on(EventPattern.keyPressed(KeyCode.S, KeyCombination.SHORTCUT_DOWN)).act(e -> fileSave())
+ .on(EventPattern.keyPressed(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)).act(e -> fileSaveAll())
+ .create();
+ return editorShortcuts;
}