Merge pull request #1515 from SiboVG/issue-1513

[#1513] Combine 'Add component' and 'Modify new component' undo action
This commit is contained in:
SiboVG 2022-07-14 15:12:37 +02:00 committed by GitHub
commit 6cb334fedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -230,8 +230,9 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
* @param document the document to configure.
* @param component the component to configure.
* @param rememberPreviousTab if true, the previous tab will be remembered and used for the new dialog
* @param includeUndoModify if true, include a 'Modify component' undo action
*/
public static void showDialog(Window parent, OpenRocketDocument document, RocketComponent component, boolean rememberPreviousTab) {
public static void showDialog(Window parent, OpenRocketDocument document, RocketComponent component, boolean rememberPreviousTab, boolean includeUndoModify) {
if (dialog != null) {
// Don't remember the previous tab for rockets or stages, because this will leave you in the override tab for
// the next component, which is generally not what you want.
@ -258,13 +259,27 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
dialog.setVisible(true);
////Modify
if (component.getConfigListeners().size() == 0) {
document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName());
} else {
document.addUndoPosition(trans.get("ComponentCfgDlg.ModifyComponents"));
if (includeUndoModify) {
if (component.getConfigListeners().size() == 0) {
document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName());
} else {
document.addUndoPosition(trans.get("ComponentCfgDlg.ModifyComponents"));
}
}
}
/**
* A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists.
*
* @param document the document to configure.
* @param component the component to configure.
* @param rememberPreviousTab if true, the previous tab will be remembered and used for the new dialog
*/
public static void showDialog(Window parent, OpenRocketDocument document, RocketComponent component, boolean rememberPreviousTab) {
ComponentConfigDialog.showDialog(parent, document, component, rememberPreviousTab, true);
}
/**
* A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists.

View File

@ -488,7 +488,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
}
}
ComponentConfigDialog.showDialog(parent, document, component, false);
ComponentConfigDialog.showDialog(parent, document, component, false, false);
}
}