Add exit handler

This commit is contained in:
Oystein Kristoffer Tveit 2021-02-23 15:10:09 +01:00
parent 26bcb9f29c
commit 0ba350395b
3 changed files with 26 additions and 1 deletions

View File

@ -8,8 +8,10 @@ import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import app.controllers.*;
import app.events.ExitApplicationEvent;
import app.events.LanguageChangedEvent;
import app.model.Model;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@ -71,4 +73,11 @@ public class MainController implements Initializable {
Model.getScene().getStylesheets().add(nextStyleSheet);
}
@Subscribe
private void handle(ExitApplicationEvent event) {
// TODO: send save file event, exit application safely.
Platform.exit();
}
}

View File

@ -7,8 +7,8 @@ import java.util.ResourceBundle;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import app.events.ExitApplicationEvent;
import app.events.LanguageChangedEvent;
import app.model.Model;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@ -84,6 +84,7 @@ public class MenubarController implements Initializable, Controller {
/**
* Handles the event where the language was change from the menu.
* @param event
*/
@FXML
private void handleLanguageChange(ActionEvent event) {
@ -92,8 +93,18 @@ public class MenubarController implements Initializable, Controller {
((RadioMenuItem) event.getSource()).getText()));
}
/**
* Handles the event where there was an exit request from the menu.
* @param event
*/
@FXML
private void handleExitApplication(ActionEvent event) {
this.eventBus.post(new ExitApplicationEvent());
}
/**
* Updates menubuttons whenever the language is changed
* @param event
*/
@Subscribe
private void handle(LanguageChangedEvent event) {

View File

@ -0,0 +1,5 @@
package app.events;
public class ExitApplicationEvent {
}