Avoid saving config during initialization of the GUI
This commit is contained in:
parent
6e9b92effa
commit
8e2999241f
|
@ -72,28 +72,33 @@ public class CtbrecPreferencesStorage implements PreferencesStorage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node createGui(Setting setting) throws Exception {
|
public Node createGui(Setting setting) throws Exception {
|
||||||
Property<?> prop = setting.getProperty();
|
config.disableSaving();
|
||||||
if (prop instanceof ExclusiveSelectionProperty) {
|
try {
|
||||||
return createRadioGroup(setting);
|
Property<?> prop = setting.getProperty();
|
||||||
} else if (prop instanceof SimpleRangeProperty) {
|
if (prop instanceof ExclusiveSelectionProperty) {
|
||||||
return createRangeSlider(setting);
|
return createRadioGroup(setting);
|
||||||
} else if (prop instanceof SimpleDirectoryProperty) {
|
} else if (prop instanceof SimpleRangeProperty) {
|
||||||
return createDirectorySelector(setting);
|
return createRangeSlider(setting);
|
||||||
} else if (prop instanceof SimpleFileProperty) {
|
} else if (prop instanceof SimpleDirectoryProperty) {
|
||||||
return createFileSelector(setting);
|
return createDirectorySelector(setting);
|
||||||
} else if (prop instanceof IntegerProperty) {
|
} else if (prop instanceof SimpleFileProperty) {
|
||||||
return createIntegerProperty(setting);
|
return createFileSelector(setting);
|
||||||
} else if (prop instanceof LongProperty) {
|
} else if (prop instanceof IntegerProperty) {
|
||||||
return createLongProperty(setting);
|
return createIntegerProperty(setting);
|
||||||
} else if (prop instanceof BooleanProperty) {
|
} else if (prop instanceof LongProperty) {
|
||||||
return createBooleanProperty(setting);
|
return createLongProperty(setting);
|
||||||
} else if (prop instanceof ListProperty) {
|
} else if (prop instanceof BooleanProperty) {
|
||||||
return createComboBox(setting);
|
return createBooleanProperty(setting);
|
||||||
} else if (prop instanceof StringProperty) {
|
} else if (prop instanceof ListProperty) {
|
||||||
return createStringProperty(setting);
|
return createComboBox(setting);
|
||||||
} else {
|
} else if (prop instanceof StringProperty) {
|
||||||
return new Label("Unsupported Type for key " + setting.getKey() + ": " + setting.getProperty());
|
return createStringProperty(setting);
|
||||||
}
|
} else {
|
||||||
|
return new Label("Unsupported Type for key " + setting.getKey() + ": " + setting.getProperty());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
config.enableSaving();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node createRadioGroup(Setting setting) {
|
private Node createRadioGroup(Setting setting) {
|
||||||
|
|
|
@ -47,6 +47,11 @@ public class Config {
|
||||||
private String filename;
|
private String filename;
|
||||||
private List<Site> sites;
|
private List<Site> sites;
|
||||||
private File configDir;
|
private File configDir;
|
||||||
|
/**
|
||||||
|
* to temporarily disable saving of the config
|
||||||
|
* this is useful for the SettingsTab, because setting the initial values of some components causes an immediate save
|
||||||
|
*/
|
||||||
|
private boolean savingDisabled = false;
|
||||||
public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS";
|
public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS";
|
||||||
|
|
||||||
private Config(List<Site> sites) {
|
private Config(List<Site> sites) {
|
||||||
|
@ -222,6 +227,9 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save() throws IOException {
|
public synchronized void save() throws IOException {
|
||||||
|
if (savingDisabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Moshi moshi = new Moshi.Builder()
|
Moshi moshi = new Moshi.Builder()
|
||||||
.add(Model.class, new ModelJsonAdapter())
|
.add(Model.class, new ModelJsonAdapter())
|
||||||
.add(PostProcessor.class, new PostProcessorJsonAdapter())
|
.add(PostProcessor.class, new PostProcessorJsonAdapter())
|
||||||
|
@ -291,4 +299,12 @@ public class Config {
|
||||||
public String getModelNotes(Model m) {
|
public String getModelNotes(Model m) {
|
||||||
return Config.getInstance().getSettings().modelNotes.getOrDefault(m.getUrl(), "");
|
return Config.getInstance().getSettings().modelNotes.getOrDefault(m.getUrl(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disableSaving() {
|
||||||
|
savingDisabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableSaving() {
|
||||||
|
savingDisabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue