quit menu item

This commit is contained in:
Craig Raw 2020-06-19 18:17:39 +02:00
parent efba293564
commit d33ccfb672
3 changed files with 28 additions and 2 deletions

View file

@ -53,6 +53,8 @@ public class AppController implements Initializable {
public static final String DRAG_OVER_CLASS = "drag-over"; public static final String DRAG_OVER_CLASS = "drag-over";
private MainApp application;
@FXML @FXML
private MenuItem exportWallet; private MenuItem exportWallet;
@ -96,7 +98,7 @@ public class AppController implements Initializable {
} }
void initializeView() { void initializeView() {
//setOsxApplicationMenu(); setOsxApplicationMenu();
rootStack.setOnDragOver(event -> { rootStack.setOnDragOver(event -> {
if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) { if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) {
@ -201,6 +203,10 @@ public class AppController implements Initializable {
return connectionService; return connectionService;
} }
public void setApplication(MainApp application) {
this.application = application;
}
private void setOsxApplicationMenu() { private void setOsxApplicationMenu() {
if(org.controlsfx.tools.Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) { if(org.controlsfx.tools.Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) {
MenuToolkit tk = MenuToolkit.toolkit(); MenuToolkit tk = MenuToolkit.toolkit();
@ -347,6 +353,14 @@ public class AppController implements Initializable {
tabs.getTabs().remove(tabs.getSelectionModel().getSelectedItem()); tabs.getTabs().remove(tabs.getSelectionModel().getSelectedItem());
} }
public void quit(ActionEvent event) {
try {
application.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
public void showTxHex(ActionEvent event) { public void showTxHex(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource(); CheckMenuItem item = (CheckMenuItem)event.getSource();
EventManager.get().post(new TransactionTabChangedEvent(tabs.getSelectionModel().getSelectedItem(), item.isSelected())); EventManager.get().post(new TransactionTabChangedEvent(tabs.getSelectionModel().getSelectedItem(), item.isSelected()));

View file

@ -19,8 +19,12 @@ import java.util.Optional;
public class MainApp extends Application { public class MainApp extends Application {
public static final String APP_NAME = "Sparrow"; public static final String APP_NAME = "Sparrow";
private Stage mainStage;
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
this.mainStage = stage;
GlyphFontRegistry.register(new FontAwesome5()); GlyphFontRegistry.register(new FontAwesome5());
GlyphFontRegistry.register(new FontAwesome5Brands()); GlyphFontRegistry.register(new FontAwesome5Brands());
@ -42,6 +46,7 @@ public class MainApp extends Application {
FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("app.fxml")); FXMLLoader transactionLoader = new FXMLLoader(getClass().getResource("app.fxml"));
Parent root = transactionLoader.load(); Parent root = transactionLoader.load();
AppController appController = transactionLoader.getController(); AppController appController = transactionLoader.getController();
appController.setApplication(this);
Scene scene = new Scene(root); Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("app.css").toExternalForm()); scene.getStylesheets().add(getClass().getResource("app.css").toExternalForm());
@ -57,6 +62,11 @@ public class MainApp extends Application {
stage.show(); stage.show();
} }
@Override
public void stop() throws Exception {
mainStage.close();
}
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }

View file

@ -28,8 +28,10 @@
<MenuItem fx:id="exportWallet" mnemonicParsing="false" text="Export Wallet..." onAction="#exportWallet"/> <MenuItem fx:id="exportWallet" mnemonicParsing="false" text="Export Wallet..." onAction="#exportWallet"/>
<SeparatorMenuItem styleClass="macHide" /> <SeparatorMenuItem styleClass="macHide" />
<MenuItem styleClass="macHide" mnemonicParsing="false" text="Preferences..." onAction="#openPreferences"/> <MenuItem styleClass="macHide" mnemonicParsing="false" text="Preferences..." onAction="#openPreferences"/>
<SeparatorMenuItem />
<MenuItem mnemonicParsing="false" text="Close Tab" onAction="#closeTab"/>
<SeparatorMenuItem styleClass="macHide" /> <SeparatorMenuItem styleClass="macHide" />
<MenuItem styleClass="macHide" mnemonicParsing="false" text="Close" onAction="#closeTab"/> <MenuItem styleClass="macHide" mnemonicParsing="false" text="Quit" onAction="#quit"/>
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="View"> <Menu mnemonicParsing="false" text="View">