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
|
||||
public Node createGui(Setting setting) throws Exception {
|
||||
Property<?> prop = setting.getProperty();
|
||||
if (prop instanceof ExclusiveSelectionProperty) {
|
||||
return createRadioGroup(setting);
|
||||
} else if (prop instanceof SimpleRangeProperty) {
|
||||
return createRangeSlider(setting);
|
||||
} else if (prop instanceof SimpleDirectoryProperty) {
|
||||
return createDirectorySelector(setting);
|
||||
} else if (prop instanceof SimpleFileProperty) {
|
||||
return createFileSelector(setting);
|
||||
} else if (prop instanceof IntegerProperty) {
|
||||
return createIntegerProperty(setting);
|
||||
} else if (prop instanceof LongProperty) {
|
||||
return createLongProperty(setting);
|
||||
} else if (prop instanceof BooleanProperty) {
|
||||
return createBooleanProperty(setting);
|
||||
} else if (prop instanceof ListProperty) {
|
||||
return createComboBox(setting);
|
||||
} else if (prop instanceof StringProperty) {
|
||||
return createStringProperty(setting);
|
||||
} else {
|
||||
return new Label("Unsupported Type for key " + setting.getKey() + ": " + setting.getProperty());
|
||||
}
|
||||
config.disableSaving();
|
||||
try {
|
||||
Property<?> prop = setting.getProperty();
|
||||
if (prop instanceof ExclusiveSelectionProperty) {
|
||||
return createRadioGroup(setting);
|
||||
} else if (prop instanceof SimpleRangeProperty) {
|
||||
return createRangeSlider(setting);
|
||||
} else if (prop instanceof SimpleDirectoryProperty) {
|
||||
return createDirectorySelector(setting);
|
||||
} else if (prop instanceof SimpleFileProperty) {
|
||||
return createFileSelector(setting);
|
||||
} else if (prop instanceof IntegerProperty) {
|
||||
return createIntegerProperty(setting);
|
||||
} else if (prop instanceof LongProperty) {
|
||||
return createLongProperty(setting);
|
||||
} else if (prop instanceof BooleanProperty) {
|
||||
return createBooleanProperty(setting);
|
||||
} else if (prop instanceof ListProperty) {
|
||||
return createComboBox(setting);
|
||||
} else if (prop instanceof StringProperty) {
|
||||
return createStringProperty(setting);
|
||||
} else {
|
||||
return new Label("Unsupported Type for key " + setting.getKey() + ": " + setting.getProperty());
|
||||
}
|
||||
} finally {
|
||||
config.enableSaving();
|
||||
}
|
||||
}
|
||||
|
||||
private Node createRadioGroup(Setting setting) {
|
||||
|
|
|
@ -47,6 +47,11 @@ public class Config {
|
|||
private String filename;
|
||||
private List<Site> sites;
|
||||
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";
|
||||
|
||||
private Config(List<Site> sites) {
|
||||
|
@ -222,6 +227,9 @@ public class Config {
|
|||
}
|
||||
|
||||
public synchronized void save() throws IOException {
|
||||
if (savingDisabled) {
|
||||
return;
|
||||
}
|
||||
Moshi moshi = new Moshi.Builder()
|
||||
.add(Model.class, new ModelJsonAdapter())
|
||||
.add(PostProcessor.class, new PostProcessorJsonAdapter())
|
||||
|
@ -291,4 +299,12 @@ public class Config {
|
|||
public String getModelNotes(Model m) {
|
||||
return Config.getInstance().getSettings().modelNotes.getOrDefault(m.getUrl(), "");
|
||||
}
|
||||
|
||||
public void disableSaving() {
|
||||
savingDisabled = true;
|
||||
}
|
||||
|
||||
public void enableSaving() {
|
||||
savingDisabled = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue