mac application menu setup

This commit is contained in:
Craig Raw 2020-06-05 17:25:55 +02:00
parent c5bcefd331
commit 3a65261326
6 changed files with 59 additions and 6 deletions

View file

@ -34,6 +34,7 @@ dependencies {
implementation('no.tornado:tornadofx-controls:1.0.4') implementation('no.tornado:tornadofx-controls:1.0.4')
implementation('com.google.zxing:javase:3.4.0') implementation('com.google.zxing:javase:3.4.0')
implementation('com.github.arteam:simple-json-rpc-client:1.0') implementation('com.github.arteam:simple-json-rpc-client:1.0')
implementation('de.codecentric.centerdevice:centerdevice-nsmenufx:2.1.7')
implementation('org.controlsfx:controlsfx:11.0.1' ) { implementation('org.controlsfx:controlsfx:11.0.1' ) {
exclude group: 'org.openjfx', module: 'javafx-base' exclude group: 'org.openjfx', module: 'javafx-base'
exclude group: 'org.openjfx', module: 'javafx-graphics' exclude group: 'org.openjfx', module: 'javafx-graphics'
@ -64,7 +65,13 @@ run {
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls", "--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
"--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls", "--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls",
"--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow", "--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow",
"--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow"] "--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow",
"--add-opens=javafx.graphics/com.sun.javafx.tk=centerdevice.nsmenufx",
"--add-opens=javafx.graphics/com.sun.javafx.tk.quantum=centerdevice.nsmenufx",
"--add-opens=javafx.graphics/com.sun.glass.ui=centerdevice.nsmenufx",
"--add-opens=javafx.controls/com.sun.javafx.scene.control=centerdevice.nsmenufx",
"--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx",
"--add-opens=javafx.graphics/com.sun.glass.ui.mac=centerdevice.nsmenufx"]
} }
jlink { jlink {
@ -87,7 +94,13 @@ jlink {
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls", "--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
"--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls", "--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls",
"--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow", "--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow",
"--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow"] "--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow",
"--add-opens=javafx.graphics/com.sun.javafx.tk=com.sparrowwallet.merged.module",
"--add-opens=javafx.graphics/com.sun.javafx.tk.quantum=com.sparrowwallet.merged.module",
"--add-opens=javafx.graphics/com.sun.glass.ui=com.sparrowwallet.merged.module",
"--add-opens=javafx.controls/com.sun.javafx.scene.control=com.sparrowwallet.merged.module",
"--add-opens=javafx.graphics/com.sun.javafx.menu=com.sparrowwallet.merged.module",
"--add-opens=javafx.graphics/com.sun.glass.ui.mac=com.sparrowwallet.merged.module"]
} }
addExtraDependencies("javafx") addExtraDependencies("javafx")
jpackage { jpackage {

View file

@ -19,9 +19,11 @@ import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.*; import com.sparrowwallet.sparrow.io.*;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import com.sparrowwallet.sparrow.transaction.TransactionController; import com.sparrowwallet.sparrow.transaction.TransactionController;
import com.sparrowwallet.sparrow.wallet.WalletController; import com.sparrowwallet.sparrow.wallet.WalletController;
import com.sparrowwallet.sparrow.wallet.WalletForm; import com.sparrowwallet.sparrow.wallet.WalletForm;
import de.codecentric.centerdevice.MenuToolkit;
import javafx.animation.Animation; import javafx.animation.Animation;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.KeyValue; import javafx.animation.KeyValue;
@ -40,6 +42,7 @@ import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
import org.controlsfx.control.StatusBar; import org.controlsfx.control.StatusBar;
import org.controlsfx.tools.Platform;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
@ -56,6 +59,9 @@ public class AppController implements Initializable {
@FXML @FXML
private MenuItem exportWallet; private MenuItem exportWallet;
@FXML
private Menu fileMenu;
@FXML @FXML
private CheckMenuItem showTxHex; private CheckMenuItem showTxHex;
@ -83,6 +89,8 @@ public class AppController implements Initializable {
} }
void initializeView() { void initializeView() {
setOsxApplicationMenu();
rootStack.setOnDragOver(event -> { rootStack.setOnDragOver(event -> {
if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) { if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE); event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
@ -172,6 +180,21 @@ public class AppController implements Initializable {
return pingService; return pingService;
} }
private void setOsxApplicationMenu() {
if(Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) {
MenuToolkit tk = MenuToolkit.toolkit();
MenuItem preferences = new MenuItem("Preferences...");
preferences.setOnAction(this::openPreferences);
Menu defaultApplicationMenu = new Menu("Apple", null, tk.createAboutMenuItem(MainApp.APP_NAME, null), new SeparatorMenuItem(),
preferences, new SeparatorMenuItem(),
tk.createHideMenuItem(MainApp.APP_NAME), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(), new SeparatorMenuItem(),
tk.createQuitMenuItem(MainApp.APP_NAME));
tk.setApplicationMenu(defaultApplicationMenu);
fileMenu.getItems().removeIf(item -> item.getStyleClass().contains("macHide"));
}
}
public void openFromFile(ActionEvent event) { public void openFromFile(ActionEvent event) {
Stage window = new Stage(); Stage window = new Stage();
@ -413,6 +436,11 @@ public class AppController implements Initializable {
} }
} }
public void openPreferences(ActionEvent event) {
PreferencesDialog preferencesDialog = new PreferencesDialog();
preferencesDialog.showAndWait();
}
public Tab addWalletTab(Storage storage, Wallet wallet) { public Tab addWalletTab(Storage storage, Wallet wallet) {
try { try {
String name = storage.getWalletFile().getName(); String name = storage.getWalletFile().getName();

View file

@ -17,6 +17,7 @@ import org.controlsfx.glyphfont.GlyphFontRegistry;
import java.util.Optional; import java.util.Optional;
public class MainApp extends Application { public class MainApp extends Application {
public static final String APP_NAME = "Sparrow";
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {

View file

@ -12,6 +12,10 @@ import org.controlsfx.tools.Borders;
import java.io.IOException; import java.io.IOException;
public class PreferencesDialog extends Dialog<Void> { public class PreferencesDialog extends Dialog<Void> {
public PreferencesDialog() {
this(null);
}
public PreferencesDialog(PreferenceGroup initialGroup) { public PreferencesDialog(PreferenceGroup initialGroup) {
final DialogPane dialogPane = getDialogPane(); final DialogPane dialogPane = getDialogPane();
@ -20,7 +24,11 @@ public class PreferencesDialog extends Dialog<Void> {
dialogPane.setContent(Borders.wrap(preferencesLoader.load()).lineBorder().outerPadding(0).innerPadding(0).buildAll()); dialogPane.setContent(Borders.wrap(preferencesLoader.load()).lineBorder().outerPadding(0).innerPadding(0).buildAll());
PreferencesController preferencesController = preferencesLoader.getController(); PreferencesController preferencesController = preferencesLoader.getController();
preferencesController.initializeView(Config.get()); preferencesController.initializeView(Config.get());
preferencesController.selectGroup(initialGroup); if(initialGroup != null) {
preferencesController.selectGroup(initialGroup);
} else {
preferencesController.selectGroup(PreferenceGroup.SERVER);
}
final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE); final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
dialogPane.getButtonTypes().addAll(closeButtonType); dialogPane.getButtonTypes().addAll(closeButtonType);

View file

@ -16,5 +16,6 @@ open module com.sparrowwallet.sparrow {
requires simple.json.rpc.core; requires simple.json.rpc.core;
requires org.jetbrains.annotations; requires org.jetbrains.annotations;
requires com.fasterxml.jackson.databind; requires com.fasterxml.jackson.databind;
requires centerdevice.nsmenufx;
requires javafx.swing; requires javafx.swing;
} }

View file

@ -11,7 +11,7 @@
<children> <children>
<MenuBar useSystemMenuBar="true"> <MenuBar useSystemMenuBar="true">
<menus> <menus>
<Menu mnemonicParsing="false" text="File"> <Menu fx:id="fileMenu" mnemonicParsing="false" text="File">
<items> <items>
<MenuItem mnemonicParsing="false" text="New Wallet" onAction="#newWallet"/> <MenuItem mnemonicParsing="false" text="New Wallet" onAction="#newWallet"/>
<MenuItem mnemonicParsing="false" text="Open Wallet..." onAction="#openWallet"/> <MenuItem mnemonicParsing="false" text="Open Wallet..." onAction="#openWallet"/>
@ -25,8 +25,10 @@
<SeparatorMenuItem /> <SeparatorMenuItem />
<MenuItem mnemonicParsing="false" text="Import Wallet..." onAction="#importWallet"/> <MenuItem mnemonicParsing="false" text="Import Wallet..." onAction="#importWallet"/>
<MenuItem fx:id="exportWallet" mnemonicParsing="false" text="Export Wallet..." onAction="#exportWallet"/> <MenuItem fx:id="exportWallet" mnemonicParsing="false" text="Export Wallet..." onAction="#exportWallet"/>
<SeparatorMenuItem /> <SeparatorMenuItem styleClass="macHide" />
<MenuItem mnemonicParsing="false" text="Close" onAction="#closeTab"/> <MenuItem styleClass="macHide" mnemonicParsing="false" text="Preferences..." onAction="#openPreferences"/>
<SeparatorMenuItem styleClass="macHide" />
<MenuItem styleClass="macHide" mnemonicParsing="false" text="Close" onAction="#closeTab"/>
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="View"> <Menu mnemonicParsing="false" text="View">