diff --git a/src/main/java/app/MainController.java b/src/main/java/app/MainController.java index d80c36b..d61b1ab 100644 --- a/src/main/java/app/MainController.java +++ b/src/main/java/app/MainController.java @@ -4,6 +4,8 @@ import java.net.URL; import java.util.List; import java.util.ResourceBundle; +import javax.swing.JOptionPane; + import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -66,6 +68,7 @@ public class MainController implements Initializable { /** * Set a reference to the global Host Services API + * * @param hostServices The JavaFX HostServices object * @see #getHostServices() */ @@ -75,11 +78,12 @@ public class MainController implements Initializable { /** * Replace a CSS file in a specific location in the application CSS array + * * @param position The position of the CSS file to replace - * @param cssPath The path in resources to the new CSS file + * @param cssPath The path in resources to the new CSS file */ private void setCSSAt(int position, String cssPath) { - //TODO: Error check that position in range 0 to 1 + // TODO: Error check that position in range 0 to 1 String nextStyleSheet = getClass().getResource(cssPath).toExternalForm(); Model.getScene().getStylesheets().set(position, nextStyleSheet); @@ -87,6 +91,7 @@ public class MainController implements Initializable { /** * Change the CSS according to which language is being used + * * @param event */ @Subscribe @@ -96,6 +101,7 @@ public class MainController implements Initializable { /** * Change the CSS according to which theme the user chooses + * * @param event */ @Subscribe @@ -105,6 +111,7 @@ public class MainController implements Initializable { /** * Open a link in the browser. + * * @param event */ @Subscribe @@ -113,14 +120,24 @@ public class MainController implements Initializable { } /** - * Handle an exit request for the whole program + * Handle an exit request for the whole program Checking if all is saved before + * closing the app. The user can either choose to exit or go back to the + * application and save. + * * @param event */ @Subscribe private void handle(ExitApplicationEvent event) { - // TODO: send save file event, exit application safely. + if (!Model.getFileIsSaved()) { + int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nSave before you exit?", "Exit", + JOptionPane.YES_NO_OPTION); + + if (!(g == JOptionPane.YES_OPTION)) { + Platform.exit(); + } + } else { + Platform.exit(); + } - Platform.exit(); } - -} \ No newline at end of file +} diff --git a/src/main/java/app/controllers/EditorController.java b/src/main/java/app/controllers/EditorController.java index ba99179..4962bba 100644 --- a/src/main/java/app/controllers/EditorController.java +++ b/src/main/java/app/controllers/EditorController.java @@ -8,9 +8,6 @@ import java.util.Collection; import java.util.ResourceBundle; import java.util.Scanner; -import javax.swing.JOptionPane; -import javax.swing.WindowConstants; - import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -24,7 +21,7 @@ import org.fxmisc.richtext.model.TwoDimensional.Position; import app.events.CopyEvent; import app.events.CutEvent; import app.events.EditorChangedEvent; -import app.events.ExitApplicationEvent; + import app.events.LanguageChangedEvent; import app.events.PasteEvent; import app.events.RedoEvent; @@ -196,22 +193,9 @@ public class EditorController implements Initializable, Controller { /** * Checking if all is saved before closing the app. The user can either choose - * to exit or go back and save. + * to exit or go back to the application and save. */ - private void exitApp(boolean exit) { - if (!exit) { - int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nSave before you exit?", "Exit", - JOptionPane.YES_NO_OPTION); - - if (g == JOptionPane.YES_OPTION) { - // Got stuk here, to get back to "default" and keep condition of file that is - // not saved - } - } - - } - /* ------------------------------------------------------------------------ */ /* SUBSCRIPTIONS */ /* ------------------------------------------------------------------------ */ @@ -232,11 +216,6 @@ public class EditorController implements Initializable, Controller { this.saveCodeArea(event.getPath()); } - @Subscribe - private void handle(ExitApplicationEvent event) { - this.exitApp(event.getIsSaved()); - } - @Subscribe private void handle(LanguageChangedEvent event) { this.refreshHighlighting(); diff --git a/src/main/java/app/controllers/MenubarController.java b/src/main/java/app/controllers/MenubarController.java index c74b004..934ffe7 100644 --- a/src/main/java/app/controllers/MenubarController.java +++ b/src/main/java/app/controllers/MenubarController.java @@ -1,15 +1,11 @@ package app.controllers; import java.io.File; -import java.io.IOException; import java.net.URL; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ResourceBundle; -import javax.swing.JOptionPane; - import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -32,12 +28,10 @@ import app.model.Model; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.Alert; import javafx.scene.control.CheckMenuItem; import javafx.scene.control.MenuBar; import javafx.scene.control.RadioMenuItem; import javafx.scene.control.ToggleGroup; -import javafx.scene.control.Alert.AlertType; import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; diff --git a/src/main/java/app/events/ExitApplicationEvent.java b/src/main/java/app/events/ExitApplicationEvent.java index cc71bb8..62953d8 100644 --- a/src/main/java/app/events/ExitApplicationEvent.java +++ b/src/main/java/app/events/ExitApplicationEvent.java @@ -1,29 +1,8 @@ package app.events; -import app.model.Model; - /** * Event signalizing a shutdown request for the whole applicaton */ public class ExitApplicationEvent extends Event { - private boolean isSaved; - - /** - * Event signalizing if a file is saved or modified. - * - * - */ - - public ExitApplicationEvent() { - this.isSaved = Model.getFileIsSaved(); - } - - /** - * @return Whether or not the file has been modified or saved - */ - public boolean getIsSaved() { - return this.isSaved; - } - }