mirror of
https://github.com/DanilaFe/abacus
synced 2024-09-07 00:03:05 -07:00
Refresh all settings on plugin load.
This commit is contained in:
parent
df94f698c3
commit
3650d1eec7
|
@ -11,6 +11,8 @@ import javafx.util.StringConverter;
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.config.Configuration;
|
import org.nwapw.abacus.config.Configuration;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
|
import org.nwapw.abacus.plugin.PluginListener;
|
||||||
|
import org.nwapw.abacus.plugin.PluginManager;
|
||||||
import org.nwapw.abacus.tree.TreeNode;
|
import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -20,7 +22,7 @@ import java.util.Set;
|
||||||
* The controller for the abacus FX UI, responsible
|
* The controller for the abacus FX UI, responsible
|
||||||
* for all the user interaction.
|
* for all the user interaction.
|
||||||
*/
|
*/
|
||||||
public class AbacusController {
|
public class AbacusController implements PluginListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant string that is displayed if the text could not be lexed or parsed.
|
* Constant string that is displayed if the text could not be lexed or parsed.
|
||||||
|
@ -109,16 +111,8 @@ public class AbacusController {
|
||||||
outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty());
|
outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty());
|
||||||
|
|
||||||
abacus = new Abacus();
|
abacus = new Abacus();
|
||||||
Configuration configuration = abacus.getConfiguration();
|
abacus.getPluginManager().addListener(this);
|
||||||
Set<String> disabledPlugins = configuration.getDisabledPlugins();
|
abacus.getPluginManager().reload();
|
||||||
numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers());
|
|
||||||
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
|
@FXML
|
||||||
|
@ -155,4 +149,23 @@ public class AbacusController {
|
||||||
abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE);
|
abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(PluginManager manager) {
|
||||||
|
Configuration configuration = abacus.getConfiguration();
|
||||||
|
Set<String> disabledPlugins = configuration.getDisabledPlugins();
|
||||||
|
numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers());
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnload(PluginManager manager) {
|
||||||
|
enabledPlugins.clear();
|
||||||
|
numberImplementationOptions.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user