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
@@ -19,9 +19,11 @@ import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.*;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import com.sparrowwallet.sparrow.transaction.TransactionController;
import com.sparrowwallet.sparrow.wallet.WalletController;
import com.sparrowwallet.sparrow.wallet.WalletForm;
import de.codecentric.centerdevice.MenuToolkit;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
@@ -40,6 +42,7 @@ import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Duration;
import org.controlsfx.control.StatusBar;
import org.controlsfx.tools.Platform;
import java.io.*;
import java.net.URL;
@@ -56,6 +59,9 @@ public class AppController implements Initializable {
@FXML
private MenuItem exportWallet;
@FXML
private Menu fileMenu;
@FXML
private CheckMenuItem showTxHex;
@@ -83,6 +89,8 @@ public class AppController implements Initializable {
}
void initializeView() {
setOsxApplicationMenu();
rootStack.setOnDragOver(event -> {
if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
@@ -172,6 +180,21 @@ public class AppController implements Initializable {
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) {
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) {
try {
String name = storage.getWalletFile().getName();
@@ -17,6 +17,7 @@ import org.controlsfx.glyphfont.GlyphFontRegistry;
import java.util.Optional;
public class MainApp extends Application {
public static final String APP_NAME = "Sparrow";
@Override
public void start(Stage stage) throws Exception {
@@ -12,6 +12,10 @@ import org.controlsfx.tools.Borders;
import java.io.IOException;
public class PreferencesDialog extends Dialog<Void> {
public PreferencesDialog() {
this(null);
}
public PreferencesDialog(PreferenceGroup initialGroup) {
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());
PreferencesController preferencesController = preferencesLoader.getController();
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);
dialogPane.getButtonTypes().addAll(closeButtonType);
+1
View File
@@ -16,5 +16,6 @@ open module com.sparrowwallet.sparrow {
requires simple.json.rpc.core;
requires org.jetbrains.annotations;
requires com.fasterxml.jackson.databind;
requires centerdevice.nsmenufx;
requires javafx.swing;
}