| | 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 de.jensd.fx.glyphs.GlyphsDude; |
| | import static de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon.*; |
| | +import java.util.function.Consumer; |
| | import java.util.function.Function; |
| | |
 |
| | private final Scene scene; |
| | private final FileEditorTabPane fileEditorTabPane; |
| | + private MenuBar menuBar; |
| | |
| | MainWindow() { |
 |
| | helpAboutMenuItem); |
| | |
| | - MenuBar menuBar = new MenuBar(fileMenu, editMenu, insertMenu, helpMenu); |
| | + menuBar = new MenuBar(fileMenu, editMenu, insertMenu, helpMenu); |
| | |
| | |
 |
| | return editorShortcuts; |
| | |
| | - editorShortcuts = EventHandlerHelper |
| | - // File |
| | - .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()) |
| | - // Insert |
| | - .on(EventPattern.keyPressed(KeyCode.B, KeyCombination.SHORTCUT_DOWN)).act(e -> insertBold()) |
| | - .on(EventPattern.keyPressed(KeyCode.I, KeyCombination.SHORTCUT_DOWN)).act(e -> insertItalic()) |
| | - .create(); |
| | + EventHandlerHelper.Builder<KeyEvent> builder = null; |
| | + for (Menu menu : menuBar.getMenus()) { |
| | + for (MenuItem menuItem : menu.getItems()) { |
| | + KeyCombination accelerator = menuItem.getAccelerator(); |
| | + if (accelerator != null) { |
| | + Consumer<? super KeyEvent> action = e -> menuItem.getOnAction().handle(null); |
| | + if (builder != null) |
| | + builder = builder.on(EventPattern.keyPressed(accelerator)).act(action); |
| | + else |
| | + builder = EventHandlerHelper.on(EventPattern.keyPressed(accelerator)).act(action); |
| | + } |
| | + } |
| | + } |
| | + editorShortcuts = builder.create(); |
| | return editorShortcuts; |
| | } |