From 8ae9b2fcbd5bfad1154fe93d16353258674489d0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 2 Aug 2017 19:01:01 -0700 Subject: [PATCH] Write disabled / enabled plugins to the configuration. --- .../nwapw/abacus/config/Configuration.java | 26 ------------------- .../org/nwapw/abacus/fx/AbacusController.java | 23 +++++++++++++++- .../nwapw/abacus/plugin/PluginManager.java | 10 ++++++- src/main/resources/abacus.fxml | 3 ++- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/config/Configuration.java b/src/main/java/org/nwapw/abacus/config/Configuration.java index 9a511cf..69e1272 100644 --- a/src/main/java/org/nwapw/abacus/config/Configuration.java +++ b/src/main/java/org/nwapw/abacus/config/Configuration.java @@ -6,7 +6,6 @@ import com.moandjiezana.toml.TomlWriter; import java.io.File; import java.io.IOException; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -100,29 +99,4 @@ public class Configuration { return disabledPlugins; } - /** - * Adds the given plugin to the disabled plugins list. - * @param pluginClass the plugin to disable. - */ - public void disablePlugin(String pluginClass){ - disabledPlugins.add(pluginClass); - } - - /** - * Removes the given plugin from the disabled plugins list. - * @param pluginClass the plugin to enable. - */ - public void enablePlugin(String pluginClass){ - disabledPlugins.remove(pluginClass); - } - - /** - * Sets the disabled plugins to be as specified. - * @param newDisabled the new list of disabled plugins. - */ - public void setDisabledPlugins(Collection newDisabled){ - disabledPlugins.clear(); - disabledPlugins.addAll(newDisabled); - } - } diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index b9adac9..5b7b4c5 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -9,9 +9,12 @@ import javafx.scene.text.Text; import javafx.util.Callback; import javafx.util.StringConverter; import org.nwapw.abacus.Abacus; +import org.nwapw.abacus.config.Configuration; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.tree.TreeNode; +import java.util.Set; + /** * The controller for the abacus FX UI, responsible @@ -106,10 +109,16 @@ public class AbacusController { outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty()); abacus = new Abacus(); + Configuration configuration = abacus.getConfiguration(); + Set disabledPlugins = configuration.getDisabledPlugins(); numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers()); - String actualImplementation = abacus.getConfiguration().getNumberImplementation(); + String actualImplementation = configuration.getNumberImplementation(); String toSelect = (numberImplementationOptions.contains(actualImplementation)) ? actualImplementation : "naive"; numberImplementationBox.getSelectionModel().select(toSelect); + for(Class pluginClass : abacus.getPluginManager().getLoadedPluginClasses()){ + String fullName = pluginClass.getName(); + enabledPlugins.add(new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName)); + } } @FXML @@ -134,4 +143,16 @@ public class AbacusController { inputField.setText(""); } + @FXML + private void performReload(){ + Configuration configuration = abacus.getConfiguration(); + Set disabledPlugins = configuration.getDisabledPlugins(); + disabledPlugins.clear(); + for(ToggleablePlugin pluginEntry : enabledPlugins){ + if(!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName()); + } + abacus.getPluginManager().reload(); + abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE); + } + } diff --git a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 757ac67..1c8748e 100644 --- a/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -185,7 +185,7 @@ public class PluginManager { */ public void reload() { unload(); - reload(); + load(); } /** @@ -233,4 +233,12 @@ public class PluginManager { listeners.remove(listener); } + /** + * Gets a list of all the plugin class files that have been + * added to the plugin manager. + * @return the list of all the added plugin classes. + */ + public Set> getLoadedPluginClasses() { + return loadedPluginClasses; + } } diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 0cd471b..14e809f 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -49,7 +49,8 @@ -