mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 23:40:08 -08:00
Remove the default load-from-file behavior from the Abacus core.
This commit is contained in:
parent
1331bf2af2
commit
9efe9be5b4
|
@ -12,7 +12,7 @@ import org.nwapw.abacus.plugin.StandardPlugin;
|
|||
import org.nwapw.abacus.tree.NumberReducer;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
|
@ -53,11 +49,10 @@ public class Abacus {
|
|||
/**
|
||||
* Creates a new instance of the Abacus calculator.
|
||||
*/
|
||||
public Abacus() {
|
||||
public Abacus(Supplier<Configuration> configurationSupplier) {
|
||||
pluginManager = new PluginManager(this);
|
||||
numberReducer = new NumberReducer(this);
|
||||
configuration = new Configuration(CONFIG_FILE);
|
||||
configuration.saveTo(CONFIG_FILE);
|
||||
configuration = configurationSupplier.get();
|
||||
LexerTokenizer lexerTokenizer = new LexerTokenizer();
|
||||
ShuntingYardParser shuntingYardParser = new ShuntingYardParser(this);
|
||||
treeBuilder = new TreeBuilder<>(lexerTokenizer, shuntingYardParser);
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.nwapw.abacus.plugin.PluginManager;
|
|||
import org.nwapw.abacus.plugin.StandardPlugin;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -28,6 +29,10 @@ import java.util.Set;
|
|||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -175,7 +180,7 @@ public class AbacusController implements PluginListener {
|
|||
if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true);
|
||||
});
|
||||
|
||||
abacus = new Abacus();
|
||||
abacus = new Abacus(() -> new Configuration(new java.io.File("config.toml")));
|
||||
PluginManager abacusPluginManager = abacus.getPluginManager();
|
||||
abacusPluginManager.addListener(this);
|
||||
abacusPluginManager.addInstantiated(new StandardPlugin(abacus.getPluginManager()));
|
||||
|
@ -279,7 +284,7 @@ public class AbacusController implements PluginListener {
|
|||
for (ToggleablePlugin pluginEntry : enabledPlugins) {
|
||||
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
|
||||
}
|
||||
configuration.saveTo(Abacus.CONFIG_FILE);
|
||||
configuration.saveTo(CONFIG_FILE);
|
||||
changesMade = false;
|
||||
reloadAlertShown = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user