Permalink
Browse files

No longer use menu buttons from FXML

  • Loading branch information...
iAmGio committed Jan 7, 2019
1 parent 7320ef3 commit 3c3499ec641b3df3eeb108c015dc46974fd3ef34
@@ -30,87 +30,7 @@
</VBox>
<VBox fx:id="vbox" prefHeight="600.0" prefWidth="950.0">
<children>
<MenuBar fx:id="menuBar" prefHeight="10.0" prefWidth="950.0">
<menus>
<Menu mnemonicParsing="false" text="%bar.file" id="File">
<items>
<MenuItem mnemonicParsing="false" id="CreateFile" text="%bar.file.new">
<accelerator>
<KeyCodeCombination alt="UP" code="N" control="DOWN" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="Open" text="%bar.file.open">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="OpenFromSFTP" text="%bar.file.sftp">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="DOWN"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="OpenFromFTP" text="%bar.file.ftp"/>
<MenuItem mnemonicParsing="false" id="Refresh" text="%bar.file.refresh">
<accelerator>
<KeyCodeCombination alt="UP" code="F5" control="UP" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="TestFile" text="%bar.file.test">
<accelerator>
<KeyCodeCombination alt="UP" code="T" control="DOWN" meta="UP" shift="DOWN"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="Settings" text="%bar.file.settings">
<accelerator>
<KeyCodeCombination alt="DOWN" code="S" control="DOWN" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" id="Edit" text="%bar.edit">
<items>
<MenuItem mnemonicParsing="false" id="Undo" text="%bar.edit.undo"/>
<MenuItem mnemonicParsing="false" id="Redo" text="%bar.edit.redo"/>
<MenuItem mnemonicParsing="false" id="Copy" text="%bar.edit.copy"/>
<MenuItem mnemonicParsing="false" id="Paste" text="%bar.edit.paste"/>
<MenuItem mnemonicParsing="false" id="Search" text="%bar.edit.search">
<accelerator>
<KeyCodeCombination alt="UP" code="F" control="DOWN" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="Replace" text="%bar.edit.replace">
<accelerator>
<KeyCodeCombination alt="UP" code="R" control="DOWN" meta="UP" shift="UP"
shortcut="UP"/>
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" id="Variables" text="%bar.edit.variables">
<accelerator>
<KeyCodeCombination alt="UP" code="V" control="DOWN" meta="UP" shift="DOWN"
shortcut="UP"/>
</accelerator>
</MenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" id="Help" text="%bar.help">
<items>
<MenuItem mnemonicParsing="false" id="Credits" text="%bar.help.credits"/>
<MenuItem mnemonicParsing="false" id="ReportABug" text="%bar.help.report_a_bug"/>
<MenuItem mnemonicParsing="false" id="Donate" text="%bar.help.donate"/>
<MenuItem mnemonicParsing="false" id="DonatorsList" text="%bar.help.donators_list"/>
<MenuItem mnemonicParsing="false" id="License" text="%bar.help.license"/>
<MenuItem mnemonicParsing="false" id="CheckForUpdates" text="%bar.help.check_for_updates"/>
</items>
</Menu>
</menus>
</MenuBar>
<MenuBar fx:id="menuBar" prefHeight="10.0" prefWidth="950.0" />
<TabPane fx:id="tabPane" prefHeight="654.0" prefWidth="950.0" tabClosingPolicy="ALL_TABS"/>
</children>
</VBox>
@@ -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) {
@@ -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())
)
)
)
}
@@ -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)
}
}
@@ -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<MenuBarButton>) : Menu(translate("bar.$translateKey")) {

init {
items.addAll(buttons)
}
}

0 comments on commit 3c3499e

Please sign in to comment.