[#1715] Add button in preferences for clearing cached preferences

This commit is contained in:
SiboVG 2022-10-12 19:16:18 +02:00
parent 304289350a
commit 7557b67dbb
3 changed files with 32 additions and 3 deletions

View File

@ -276,6 +276,10 @@ pref.dlg.tab.Simulation = Simulation
pref.dlg.tab.Launch = Launch
pref.dlg.tab.Miscellaneousoptions = Miscellaneous options
pref.dlg.lbl.RockSimWarning = Show warning when saving in RockSim format
pref.dlg.but.clearCachedPreferences = Clear cached preferences
pref.dlg.but.clearCachedPreferences.ttip = Clear cached preferences (UI settings, recent files, etc.)
pref.dlg.clearCachedPreferences.title = Clear cached preferences?
pref.dlg.clearCachedPreferences.message = Are you sure you want to clear cached preferences?
pref.dlg.tab.Graphics = Graphics
pref.dlg.lbl.DecalEditor = Graphics Editor

View File

@ -246,7 +246,21 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
}
});
this.add(rocksimWarningDialogBox,"spanx, wrap");
//// Clear cached preferences
final JButton clearCachedPreferences = new SelectColorButton(trans.get("pref.dlg.but.clearCachedPreferences"));
clearCachedPreferences.setToolTipText(trans.get("pref.dlg.but.clearCachedPreferences.ttip"));
clearCachedPreferences.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int resultYesNo = JOptionPane.showConfirmDialog(parent, trans.get("pref.dlg.clearCachedPreferences.message"),
trans.get("pref.dlg.clearCachedPreferences.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (resultYesNo == JOptionPane.YES_OPTION) {
preferences.clearPreferences();
}
}
});
this.add(clearCachedPreferences, "spanx, pushy, bottom, wrap");
}

View File

@ -71,7 +71,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
*/
private static final String NODENAME = (DEBUG ? "OpenRocket-debug" : "OpenRocket");
private final Preferences PREFNODE;
private Preferences PREFNODE;
public SwingPreferences() {
@ -93,7 +93,18 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
//////////////////////
public void clearPreferences() {
try {
Preferences root = Preferences.userRoot();
if (root.nodeExists(NODENAME)) {
root.node(NODENAME).removeNode();
}
PREFNODE = root.node(NODENAME);
log.info("Cleared preferences");
} catch (BackingStoreException e) {
throw new BugException("Unable to clear preference node", e);
}
}
/**
* Store the current OpenRocket version into the preferences to allow for preferences migration.