Changeset 4563 in josm for trunk/src/org


Ignore:
Timestamp:
2011-11-02T10:34:30+01:00 (13 years ago)
Author:
stoecker
Message:

fix #6880 - patch by Bernhard Hiller - Ask for confirmation when closing relation editor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r4238 r4563  
    6868import org.openstreetmap.josm.gui.DefaultNameFormatter;
    6969import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     70import org.openstreetmap.josm.gui.SideButton;
    7071import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    71 import org.openstreetmap.josm.gui.SideButton;
    7272import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;
    7373import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
     
    11181118                @Override
    11191119                public void run() {
    1120                         // Relation list gets update in EDT so selecting my be postponed to following EDT run
     1120                    // Relation list gets update in EDT so selecting my be postponed to following EDT run
    11211121                    Main.map.relationListDialog.selectRelation(newRelation);
    11221122                }
     
    12681268    }
    12691269
    1270     class CancelAction extends AbstractAction {
     1270    class CancelAction extends SavingAction {
    12711271        public CancelAction() {
    12721272            putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog"));
     
    12811281
    12821282        public void actionPerformed(ActionEvent e) {
     1283            if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) || tagEditorPanel.getModel().isDirty()) {
     1284                //give the user a chance to save the changes
     1285                int ret = confirmClosingByCancel();
     1286                if (ret == 0) { //Yes, save the changes
     1287                    //copied from OKAction.run()
     1288                    Main.pref.put("relation.editor.generic.lastrole", tfRole.getText());
     1289                    if (getRelation() == null) {
     1290                        applyNewRelation();
     1291                    } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot())
     1292                            || tagEditorPanel.getModel().isDirty()) {
     1293                        if (isDirtyRelation()) {
     1294                            if (confirmClosingBecauseOfDirtyState()) {
     1295                                if (getLayer().getConflicts().hasConflictForMy(getRelation())) {
     1296                                    warnDoubleConflict();
     1297                                    return;
     1298                                }
     1299                                applyExistingConflictingRelation();
     1300                            } else
     1301                                return;
     1302                        } else {
     1303                            applyExistingNonConflictingRelation();
     1304                        }
     1305                    }
     1306                }
     1307                else if (ret == 2) //Cancel, continue editing
     1308                    return;
     1309                //in case of "No, discard", there is no extra action to be performed here.
     1310            }
    12831311            setVisible(false);
     1312        }
     1313
     1314        protected int confirmClosingByCancel() {
     1315            ButtonSpec [] options = new ButtonSpec[] {
     1316                    new ButtonSpec(
     1317                            tr("Yes, save the changes and close"),
     1318                            ImageProvider.get("ok"),
     1319                            tr("Click to save the changes and close this relation editor") ,
     1320                            null /* no specific help topic */
     1321                    ),
     1322                    new ButtonSpec(
     1323                            tr("No, discard the changes and close"),
     1324                            ImageProvider.get("cancel"),
     1325                            tr("Click to discard the changes and close this relation editor") ,
     1326                            null /* no specific help topic */
     1327                    ),
     1328                    new ButtonSpec(
     1329                            tr("Cancel, continue editing"),
     1330                            ImageProvider.get("cancel"),
     1331                            tr("Click to return to the relation editor and to resume relation editing") ,
     1332                            null /* no specific help topic */
     1333                    )
     1334            };
     1335
     1336            int ret = HelpAwareOptionPane.showOptionDialog(
     1337                    Main.parent,
     1338                    tr("<html>The relation has been changed.<br>"
     1339                            + "<br>"
     1340                            + "Do you want to save your changes?</html>"),
     1341                            tr("Unsaved changes"),
     1342                            JOptionPane.WARNING_MESSAGE,
     1343                            null,
     1344                            options,
     1345                            options[0], // OK is default,
     1346                            "/Dialog/RelationEditor#DiscardChanges"
     1347            );
     1348            return ret;
    12841349        }
    12851350    }
Note: See TracChangeset for help on using the changeset viewer.