1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-23 07:50:09 -08:00

Add warnings that trigger if configuration has been changed.

This commit is contained in:
Danila Fedorin 2017-08-03 18:12:40 -07:00
parent 6cce975bcf
commit 963871d7b6

View File

@ -91,11 +91,26 @@ public class AbacusController implements PluginListener {
* Boolean which represents whether changes were made to the configuration. * Boolean which represents whether changes were made to the configuration.
*/ */
private boolean changesMade; private boolean changesMade;
/**
* Whether an alert about changes to the configuration was already shown.
*/
private boolean reloadAlertShown;
/** /**
* The alert shown when a press to "apply" is needed. * The alert shown when a press to "apply" is needed.
*/ */
private Alert reloadAlert; private Alert reloadAlert;
/**
* Alerts the user if the changes they made
* have not yet been applied.
*/
private void alertIfApplyNeeded(boolean ignorePrevious){
if(changesMade && (!reloadAlertShown || ignorePrevious)) {
reloadAlertShown = true;
reloadAlert.showAndWait();
}
}
@FXML @FXML
public void initialize(){ public void initialize(){
Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory = Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory =
@ -117,6 +132,7 @@ public class AbacusController implements PluginListener {
historyTable.setItems(historyData); historyTable.setItems(historyData);
numberImplementationOptions = FXCollections.observableArrayList(); numberImplementationOptions = FXCollections.observableArrayList();
numberImplementationBox.setItems(numberImplementationOptions); numberImplementationBox.setItems(numberImplementationOptions);
numberImplementationBox.getSelectionModel().selectedIndexProperty().addListener(e -> changesMade = true);
historyTable.getSelectionModel().setCellSelectionEnabled(true); historyTable.getSelectionModel().setCellSelectionEnabled(true);
enabledPlugins = FXCollections.observableArrayList(); enabledPlugins = FXCollections.observableArrayList();
enabledPluginView.setItems(enabledPlugins); enabledPluginView.setItems(enabledPlugins);
@ -133,10 +149,11 @@ public class AbacusController implements PluginListener {
abacus.getPluginManager().reload(); abacus.getPluginManager().reload();
changesMade = false; changesMade = false;
reloadAlertShown = false;
reloadAlert = new Alert(Alert.AlertType.WARNING); reloadAlert = new Alert(Alert.AlertType.WARNING);
reloadAlert.setTitle(APPLY_MSG_TITLE); reloadAlert.setTitle(APPLY_MSG_TITLE);
reloadAlert.setTitle(APPLY_MSG_HEADER); reloadAlert.setHeaderText(APPLY_MSG_HEADER);
reloadAlert.setContentText(APPLY_MSG_TEXT); reloadAlert.setContentText(APPLY_MSG_TEXT);
} }
@ -164,6 +181,7 @@ public class AbacusController implements PluginListener {
@FXML @FXML
private void performReload(){ private void performReload(){
alertIfApplyNeeded(true);
abacus.getPluginManager().reload(); abacus.getPluginManager().reload();
} }
@ -178,6 +196,7 @@ public class AbacusController implements PluginListener {
} }
configuration.saveTo(Abacus.CONFIG_FILE); configuration.saveTo(Abacus.CONFIG_FILE);
changesMade = false; changesMade = false;
reloadAlertShown = false;
} }
@Override @Override
@ -190,7 +209,9 @@ public class AbacusController implements PluginListener {
numberImplementationBox.getSelectionModel().select(toSelect); numberImplementationBox.getSelectionModel().select(toSelect);
for(Class<?> pluginClass : abacus.getPluginManager().getLoadedPluginClasses()){ for(Class<?> pluginClass : abacus.getPluginManager().getLoadedPluginClasses()){
String fullName = pluginClass.getName(); String fullName = pluginClass.getName();
enabledPlugins.add(new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName)); ToggleablePlugin plugin = new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName);
plugin.enabledProperty().addListener(e -> changesMade = true);
enabledPlugins.add(plugin);
} }
} }