1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-11-19 00:49:32 -08:00

Remove the default load-from-file behavior from the Abacus core.

This commit is contained in:
Danila Fedorin 2017-08-05 17:04:07 -07:00
parent 1331bf2af2
commit 9efe9be5b4
3 changed files with 19 additions and 10 deletions

View File

@ -12,7 +12,7 @@ import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.tree.NumberReducer; import org.nwapw.abacus.tree.NumberReducer;
import org.nwapw.abacus.tree.TreeNode; import org.nwapw.abacus.tree.TreeNode;
import java.io.File; import java.util.function.Supplier;
/** /**
* The main calculator class. This is responsible * The main calculator class. This is responsible
@ -25,10 +25,6 @@ public class Abacus {
* The default number implementation to be used if no other one is available / selected. * The default number implementation to be used if no other one is available / selected.
*/ */
public static final NumberImplementation DEFAULT_IMPLEMENTATION = StandardPlugin.IMPLEMENTATION_NAIVE; public static final NumberImplementation DEFAULT_IMPLEMENTATION = StandardPlugin.IMPLEMENTATION_NAIVE;
/**
* The file used for saving and loading configuration.
*/
public static final File CONFIG_FILE = new File("config.toml");
/** /**
* The plugin manager responsible for * The plugin manager responsible for
@ -53,11 +49,10 @@ public class Abacus {
/** /**
* Creates a new instance of the Abacus calculator. * Creates a new instance of the Abacus calculator.
*/ */
public Abacus() { public Abacus(Supplier<Configuration> configurationSupplier) {
pluginManager = new PluginManager(this); pluginManager = new PluginManager(this);
numberReducer = new NumberReducer(this); numberReducer = new NumberReducer(this);
configuration = new Configuration(CONFIG_FILE); configuration = configurationSupplier.get();
configuration.saveTo(CONFIG_FILE);
LexerTokenizer lexerTokenizer = new LexerTokenizer(); LexerTokenizer lexerTokenizer = new LexerTokenizer();
ShuntingYardParser shuntingYardParser = new ShuntingYardParser(this); ShuntingYardParser shuntingYardParser = new ShuntingYardParser(this);
treeBuilder = new TreeBuilder<>(lexerTokenizer, shuntingYardParser); treeBuilder = new TreeBuilder<>(lexerTokenizer, shuntingYardParser);

View File

@ -85,6 +85,15 @@ public class Configuration {
} }
} }
/**
* Gets the value of this configuration as a string.
*
* @return the string that represents this configuration.
*/
public String asTomlString(){
return TOML_WRITER.write(this);
}
/** /**
* Gets the number implementation from this configuration. * Gets the number implementation from this configuration.
* *

View File

@ -18,6 +18,7 @@ import org.nwapw.abacus.plugin.PluginManager;
import org.nwapw.abacus.plugin.StandardPlugin; import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.tree.TreeNode; import org.nwapw.abacus.tree.TreeNode;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
@ -28,6 +29,10 @@ import java.util.Set;
*/ */
public class AbacusController implements PluginListener { public class AbacusController implements PluginListener {
/**
* The file used for saving and loading configuration.
*/
public static final File CONFIG_FILE = new File("config.toml");
/** /**
* The title for the apply alert dialog. * The title for the apply alert dialog.
*/ */
@ -175,7 +180,7 @@ public class AbacusController implements PluginListener {
if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true); if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true);
}); });
abacus = new Abacus(); abacus = new Abacus(() -> new Configuration(new java.io.File("config.toml")));
PluginManager abacusPluginManager = abacus.getPluginManager(); PluginManager abacusPluginManager = abacus.getPluginManager();
abacusPluginManager.addListener(this); abacusPluginManager.addListener(this);
abacusPluginManager.addInstantiated(new StandardPlugin(abacus.getPluginManager())); abacusPluginManager.addInstantiated(new StandardPlugin(abacus.getPluginManager()));
@ -279,7 +284,7 @@ public class AbacusController implements PluginListener {
for (ToggleablePlugin pluginEntry : enabledPlugins) { for (ToggleablePlugin pluginEntry : enabledPlugins) {
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName()); if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
} }
configuration.saveTo(Abacus.CONFIG_FILE); configuration.saveTo(CONFIG_FILE);
changesMade = false; changesMade = false;
reloadAlertShown = false; reloadAlertShown = false;
} }