mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 15:30:09 -08:00
Write disabled / enabled plugins to the configuration.
This commit is contained in:
parent
e49f28a850
commit
2502c90837
|
@ -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<String> newDisabled){
|
||||
disabledPlugins.clear();
|
||||
disabledPlugins.addAll(newDisabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Class<?>> getLoadedPluginClasses() {
|
||||
return loadedPluginClasses;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@
|
|||
<ListView fx:id="enabledPluginView"
|
||||
GridPane.rowIndex="1" GridPane.columnIndex="0"
|
||||
GridPane.columnSpan="2" maxHeight="100"/>
|
||||
<Button fx:id="reloadButton" text="Reload" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
|
||||
<Button fx:id="reloadButton" text="Reload" GridPane.rowIndex="2" GridPane.columnIndex="0"
|
||||
onAction="#performReload"/>
|
||||
</GridPane>
|
||||
</Tab>
|
||||
</TabPane>
|
||||
|
|
Loading…
Reference in New Issue
Block a user