Merge pull request #2011 from SiboVG/issue-2009
[#2009] When canceling a component change, check for an unmodified component earlier on
This commit is contained in:
commit
ae87efe189
@ -306,6 +306,8 @@ pref.dlg.checkbox.Markers = Only show pod set/booster markers when the pod set/b
|
||||
pref.dlg.checkbox.Markers.ttip = <html>If checked, pod set/booster markers will only be shown when the pod set/booster is selected.<br>If unchecked, pod set/booster markers will always be shown.</html>
|
||||
pref.dlg.checkbox.AlwaysOpenLeftmost = Always open leftmost tab when opening a component edit dialog
|
||||
pref.dlg.checkbox.AlwaysOpenLeftmost.ttip = <html>If checked, a component edit dialog will always pop up with the first tab selected.<br>If unchecked, the previous selected tab will be used.</html>
|
||||
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)
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user