From 3c3499ec641b3df3eeb108c015dc46974fd3ef34 Mon Sep 17 00:00:00 2001 From: iAmGio Date: Mon, 7 Jan 2019 16:47:28 +0100 Subject: [PATCH] No longer use menu buttons from FXML --- src/assets/views/Editor.fxml | 82 +------------------ .../chorus/editor/EditorController.java | 15 +--- src/org/chorusmc/chorus/menubar/MenuBar.kt | 53 ++++++++++++ .../chorusmc/chorus/menubar/MenuBarButton.kt | 19 +++++ .../chorus/menubar/MenuBarMainButton.kt | 14 ++++ 5 files changed, 88 insertions(+), 95 deletions(-) create mode 100644 src/org/chorusmc/chorus/menubar/MenuBar.kt create mode 100644 src/org/chorusmc/chorus/menubar/MenuBarButton.kt create mode 100644 src/org/chorusmc/chorus/menubar/MenuBarMainButton.kt diff --git a/src/assets/views/Editor.fxml b/src/assets/views/Editor.fxml index e4c5d914..67681e65 100644 --- a/src/assets/views/Editor.fxml +++ b/src/assets/views/Editor.fxml @@ -30,87 +30,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/org/chorusmc/chorus/editor/EditorController.java b/src/org/chorusmc/chorus/editor/EditorController.java index d9db1442..5015c2ca 100644 --- a/src/org/chorusmc/chorus/editor/EditorController.java +++ b/src/org/chorusmc/chorus/editor/EditorController.java @@ -11,9 +11,7 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import org.chorusmc.chorus.Chorus; -import org.chorusmc.chorus.editor.events.Events; import org.chorusmc.chorus.file.LocalFile; -import org.chorusmc.chorus.menubar.MenuBarAction; import org.chorusmc.chorus.nodes.Tab; import java.net.URL; @@ -60,18 +58,7 @@ public void initialize(URL location, ResourceBundle resources) { } }); - menuBar.getMenus().forEach(menu -> menu.getItems().forEach(item -> { - try { - Class clazz = - Class.forName("org.chorusmc.chorus.menubar." + menu.getId().toLowerCase() + "." + item.getId()); - MenuBarAction action = (MenuBarAction) clazz.newInstance(); - Events.getMenuActions().add(action); - item.setOnAction(e -> action.onAction()); - item.disableProperty().bind(action.getBinding()); - } catch(Exception e) { - e.printStackTrace(); - } - })); + menuBar.getMenus().addAll(org.chorusmc.chorus.menubar.MenuBar.INSTANCE.getMenuBarButtons()); tabPane.setOnKeyPressed(e -> { if(e.getCode() == KeyCode.UP || e.getCode() == KeyCode.DOWN || e.getCode() == KeyCode.LEFT || e.getCode() == KeyCode.RIGHT) { diff --git a/src/org/chorusmc/chorus/menubar/MenuBar.kt b/src/org/chorusmc/chorus/menubar/MenuBar.kt new file mode 100644 index 00000000..33c60226 --- /dev/null +++ b/src/org/chorusmc/chorus/menubar/MenuBar.kt @@ -0,0 +1,53 @@ +package org.chorusmc.chorus.menubar + +import javafx.scene.input.KeyCode +import javafx.scene.input.KeyCodeCombination +import javafx.scene.input.KeyCombination +import org.chorusmc.chorus.menubar.edit.* +import org.chorusmc.chorus.menubar.file.* +import org.chorusmc.chorus.menubar.help.* + +/** + * @author Gio + */ +object MenuBar { + + val menuBarButtons + get() = listOf( + MenuBarMainButton( + "file", + listOf( + MenuBarButton("file.new", CreateFile(), KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN)), + MenuBarButton("file.open", Open(), KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN)), + MenuBarButton("file.sftp", OpenFromSFTP(), KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)), + MenuBarButton("file.ftp", OpenFromFTP()), + MenuBarButton("file.refresh", Refresh(), KeyCodeCombination(KeyCode.F5)), + MenuBarButton("file.test", TestFile(), KeyCodeCombination(KeyCode.T, KeyCombination.CONTROL_DOWN)), + MenuBarButton("file.settings", Settings(), KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN, KeyCombination.ALT_DOWN)) + ) + ), + MenuBarMainButton( + "edit", + listOf( + MenuBarButton("edit.undo", Undo()), + MenuBarButton("edit.redo", Redo()), + MenuBarButton("edit.copy", Copy()), + MenuBarButton("edit.paste", Paste()), + MenuBarButton("edit.search", Search(), KeyCodeCombination(KeyCode.F, KeyCombination.CONTROL_DOWN)), + MenuBarButton("edit.replace", Replace(), KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN)), + MenuBarButton("edit.variables", Variables(), KeyCodeCombination(KeyCode.V, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)) + ) + ), + MenuBarMainButton( + "help", + listOf( + MenuBarButton("help.credits", Credits()), + MenuBarButton("help.report_a_bug", ReportABug()), + MenuBarButton("help.donate", Donate()), + MenuBarButton("help.donators_list", DonatorsList()), + MenuBarButton("help.license", License()), + MenuBarButton("help.check_for_updates", CheckForUpdates()) + ) + ) + ) +} \ No newline at end of file diff --git a/src/org/chorusmc/chorus/menubar/MenuBarButton.kt b/src/org/chorusmc/chorus/menubar/MenuBarButton.kt new file mode 100644 index 00000000..95633ebc --- /dev/null +++ b/src/org/chorusmc/chorus/menubar/MenuBarButton.kt @@ -0,0 +1,19 @@ +package org.chorusmc.chorus.menubar + +import javafx.scene.control.MenuItem +import javafx.scene.input.KeyCodeCombination +import org.chorusmc.chorus.editor.events.Events +import org.chorusmc.chorus.util.translate + +/** + * @author Gio + */ +class MenuBarButton(translateKey: String, action: MenuBarAction, combination: KeyCodeCombination? = null) : MenuItem(translate("bar.$translateKey")) { + + init { + if(combination != null) super.setAccelerator(combination) + Events.getMenuActions().add(action) + setOnAction {action.onAction()} + disableProperty().bind(action.binding) + } +} \ No newline at end of file diff --git a/src/org/chorusmc/chorus/menubar/MenuBarMainButton.kt b/src/org/chorusmc/chorus/menubar/MenuBarMainButton.kt new file mode 100644 index 00000000..3339736b --- /dev/null +++ b/src/org/chorusmc/chorus/menubar/MenuBarMainButton.kt @@ -0,0 +1,14 @@ +package org.chorusmc.chorus.menubar + +import javafx.scene.control.Menu +import org.chorusmc.chorus.util.translate + +/** + * @author Gio + */ +class MenuBarMainButton(translateKey: String, buttons: List) : Menu(translate("bar.$translateKey")) { + + init { + items.addAll(buttons) + } +} \ No newline at end of file