exit dialog
This commit is contained in:
parent
1156b827ac
commit
fcab3df9fc
@ -4,6 +4,8 @@ import java.net.URL;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
@ -66,6 +68,7 @@ public class MainController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a reference to the global Host Services API
|
* Set a reference to the global Host Services API
|
||||||
|
*
|
||||||
* @param hostServices The JavaFX HostServices object
|
* @param hostServices The JavaFX HostServices object
|
||||||
* @see #getHostServices()
|
* @see #getHostServices()
|
||||||
*/
|
*/
|
||||||
@ -75,11 +78,12 @@ public class MainController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace a CSS file in a specific location in the application CSS array
|
* Replace a CSS file in a specific location in the application CSS array
|
||||||
|
*
|
||||||
* @param position The position of the CSS file to replace
|
* @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) {
|
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();
|
String nextStyleSheet = getClass().getResource(cssPath).toExternalForm();
|
||||||
|
|
||||||
Model.getScene().getStylesheets().set(position, nextStyleSheet);
|
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
|
* Change the CSS according to which language is being used
|
||||||
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -96,6 +101,7 @@ public class MainController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the CSS according to which theme the user chooses
|
* Change the CSS according to which theme the user chooses
|
||||||
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -105,6 +111,7 @@ public class MainController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a link in the browser.
|
* Open a link in the browser.
|
||||||
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@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
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void handle(ExitApplicationEvent event) {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,9 +8,6 @@ import java.util.Collection;
|
|||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.WindowConstants;
|
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
@ -24,7 +21,7 @@ import org.fxmisc.richtext.model.TwoDimensional.Position;
|
|||||||
import app.events.CopyEvent;
|
import app.events.CopyEvent;
|
||||||
import app.events.CutEvent;
|
import app.events.CutEvent;
|
||||||
import app.events.EditorChangedEvent;
|
import app.events.EditorChangedEvent;
|
||||||
import app.events.ExitApplicationEvent;
|
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
import app.events.PasteEvent;
|
import app.events.PasteEvent;
|
||||||
import app.events.RedoEvent;
|
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
|
* 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 */
|
/* SUBSCRIPTIONS */
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
@ -232,11 +216,6 @@ public class EditorController implements Initializable, Controller {
|
|||||||
this.saveCodeArea(event.getPath());
|
this.saveCodeArea(event.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
private void handle(ExitApplicationEvent event) {
|
|
||||||
this.exitApp(event.getIsSaved());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void handle(LanguageChangedEvent event) {
|
private void handle(LanguageChangedEvent event) {
|
||||||
this.refreshHighlighting();
|
this.refreshHighlighting();
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
package app.controllers;
|
package app.controllers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
@ -32,12 +28,10 @@ import app.model.Model;
|
|||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import javafx.scene.control.CheckMenuItem;
|
import javafx.scene.control.CheckMenuItem;
|
||||||
import javafx.scene.control.MenuBar;
|
import javafx.scene.control.MenuBar;
|
||||||
import javafx.scene.control.RadioMenuItem;
|
import javafx.scene.control.RadioMenuItem;
|
||||||
import javafx.scene.control.ToggleGroup;
|
import javafx.scene.control.ToggleGroup;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
|
||||||
import javafx.stage.DirectoryChooser;
|
import javafx.stage.DirectoryChooser;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
@ -1,29 +1,8 @@
|
|||||||
package app.events;
|
package app.events;
|
||||||
|
|
||||||
import app.model.Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event signalizing a shutdown request for the whole applicaton
|
* Event signalizing a shutdown request for the whole applicaton
|
||||||
*/
|
*/
|
||||||
public class ExitApplicationEvent extends Event {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user