diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index df63ec5e2..76cbc88c3 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -306,6 +306,8 @@ pref.dlg.checkbox.Markers = Only show pod set/booster markers when the pod set/b pref.dlg.checkbox.Markers.ttip = If checked, pod set/booster markers will only be shown when the pod set/booster is selected.
If unchecked, pod set/booster markers will always be shown. pref.dlg.checkbox.AlwaysOpenLeftmost = Always open leftmost tab when opening a component edit dialog pref.dlg.checkbox.AlwaysOpenLeftmost.ttip = If checked, a component edit dialog will always pop up with the first tab selected.
If unchecked, the previous selected tab will be used. +pref.dlg.checkbox.ShowDiscardConfirmation = Show confirmation dialog for discarding component changes +pref.dlg.checkbox.ShowDiscardConfirmation.ttip = If checked, you will be asked if you want really want to discard component configuration configuration changes. pref.dlg.lbl.User-definedthrust = User-defined thrust curves: pref.dlg.lbl.Windspeed = Wind speed pref.dlg.Allthrustcurvefiles = All thrust curve files (*.eng; *.rse; *.zip; directories) diff --git a/core/src/net/sf/openrocket/startup/Preferences.java b/core/src/net/sf/openrocket/startup/Preferences.java index f9c31bd82..2916e7366 100644 --- a/core/src/net/sf/openrocket/startup/Preferences.java +++ b/core/src/net/sf/openrocket/startup/Preferences.java @@ -76,6 +76,7 @@ public abstract class Preferences implements ChangeSource { public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors"; private static final String AUTO_OPEN_LAST_DESIGN = "AUTO_OPEN_LAST_DESIGN"; private static final String OPEN_LEFTMOST_DESIGN_TAB = "OPEN_LEFTMOST_DESIGN_TAB"; + private static final String SHOW_DISCARD_CONFIRMATION = "IgnoreDiscardEditingWarning"; public static final String MARKER_STYLE_ICON = "MARKER_STYLE_ICON"; private static final String SHOW_MARKERS = "SHOW_MARKERS"; private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING"; @@ -506,6 +507,22 @@ public abstract class Preferences implements ChangeSource { this.putBoolean(OPEN_LEFTMOST_DESIGN_TAB, enabled); } + /** + * Answer if a confirmation dialog should be shown when canceling a component config operation. + * + * @return true if the confirmation dialog should be shown. + */ + public final boolean isShowDiscardConfirmation() { + return this.getBoolean(SHOW_DISCARD_CONFIRMATION, true); + } + + /** + * Enable/Disable showing a confirmation warning when canceling a component config operation. + */ + public final void setShowDiscardConfirmation(boolean enabled) { + this.putBoolean(SHOW_DISCARD_CONFIRMATION, enabled); + } + /** * Answer if the always open leftmost tab is enabled. * diff --git a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index c7b12c99d..4b2f0e654 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -64,9 +64,6 @@ import net.sf.openrocket.util.Invalidatable; public class RocketComponentConfig extends JPanel { private static final long serialVersionUID = -2925484062132243982L; - // Preference key - private static final String IGNORE_DISCARD_EDITING_WARNING = "IgnoreDiscardEditingWarning"; - private static final Translator trans = Application.getTranslator(); private static final Preferences preferences = Application.getPreferences(); @@ -276,16 +273,18 @@ public class RocketComponentConfig extends JPanel { cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - if (preferences.getBoolean(IGNORE_DISCARD_EDITING_WARNING, false)) { + // Don't do anything on cancel if you are editing an existing component, and it is not modified + if (!isNewComponent && parent != null && !parent.isModified()) { + ComponentConfigDialog.disposeDialog(); + return; + } + // Apply the cancel operation if set to auto discard in preferences + if (!preferences.isShowDiscardConfirmation()) { ComponentConfigDialog.clearConfigListeners = false; // Undo action => config listeners of new component will be cleared ComponentConfigDialog.disposeDialog(); document.undo(); return; } - if (!isNewComponent && parent != null && !parent.isModified()) { - ComponentConfigDialog.disposeDialog(); - return; - } // Yes/No dialog: Are you sure you want to discard your changes? JPanel msg = createCancelOperationContent(); @@ -327,9 +326,9 @@ public class RocketComponentConfig extends JPanel { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { - preferences.putBoolean(IGNORE_DISCARD_EDITING_WARNING, true); + preferences.setShowDiscardConfirmation(false); } - // Unselected state should be impossible + // Unselected state should be not be possible and thus not be handled } }); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/preferences/DesignPreferencesPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/preferences/DesignPreferencesPanel.java index 1df5d5a51..c91962d7c 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preferences/DesignPreferencesPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preferences/DesignPreferencesPanel.java @@ -2,6 +2,8 @@ package net.sf.openrocket.gui.dialogs.preferences; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -92,15 +94,27 @@ public class DesignPreferencesPanel extends PreferencesPanel { trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost")); alwaysOpenLeftmostTab.setSelected(preferences.isAlwaysOpenLeftmostTab()); alwaysOpenLeftmostTab.setToolTipText(trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost.ttip")); - alwaysOpenLeftmostTab.addActionListener(new ActionListener() { + alwaysOpenLeftmostTab.addItemListener(new ItemListener() { @Override - public void actionPerformed(ActionEvent e) { - preferences.setAlwaysOpenLeftmostTab(alwaysOpenLeftmostTab - .isSelected()); + public void itemStateChanged(ItemEvent e) { + preferences.setAlwaysOpenLeftmostTab(e.getStateChange() == ItemEvent.SELECTED); } }); this.add(alwaysOpenLeftmostTab, "wrap, growx, spanx"); + // // Show confirmation dialog for discarding component configuration changes + final JCheckBox showDiscardConfirmation = new JCheckBox( + trans.get("pref.dlg.checkbox.ShowDiscardConfirmation")); + showDiscardConfirmation.setSelected(preferences.isShowDiscardConfirmation()); + showDiscardConfirmation.setToolTipText(trans.get("pref.dlg.checkbox.ShowDiscardConfirmation.ttip")); + showDiscardConfirmation.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + preferences.setShowDiscardConfirmation(e.getStateChange() == ItemEvent.SELECTED); + } + }); + this.add(showDiscardConfirmation, "wrap, growx, spanx"); + // // Update flight estimates in the design window final JCheckBox updateEstimates = new JCheckBox( trans.get("pref.dlg.checkbox.Updateestimates"));