Changeset 19398 in josm


Ignore:
Timestamp:
2025-05-06T17:25:21+02:00 (7 days ago)
Author:
stoecker
Message:

Auto relation refresh, fix #21840 - patch by Woazboat

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r18794 r19398  
    323323
    324324    /**
    325      * Returns the list of conflicts involving nodes.
    326      * @return The list of conflicts involving nodes.
     325     * Returns the list of conflicts involving ways.
     326     * @return The list of conflicts involving ways.
    327327     * @since 6555
    328328     */
     
    332332
    333333    /**
    334      * Returns the list of conflicts involving nodes.
    335      * @return The list of conflicts involving nodes.
     334     * Returns the list of conflicts involving relations.
     335     * @return The list of conflicts involving relations.
    336336     * @since 6555
    337337     */
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r19397 r19398  
    6565import org.openstreetmap.josm.gui.MainApplication;
    6666import org.openstreetmap.josm.gui.MainMenu;
     67import org.openstreetmap.josm.gui.Notification;
    6768import org.openstreetmap.josm.gui.ScrollViewport;
    6869import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
     
    10621063    public void commandChanged(int queueSize, int redoSize) {
    10631064        Relation r = getRelation();
    1064         if (r != null && r.getDataSet() == null) {
    1065             // see #19915
    1066             setRelation(null);
    1067             applyAction.updateEnabledState();
    1068         }
     1065        if (r != null) {
     1066            if (r.getDataSet() == null) {
     1067                // see #19915
     1068                setRelation(null);
     1069                applyAction.updateEnabledState();
     1070            } else if (isDirtyRelation()) {
     1071                if (!isDirtyEditor()) {
     1072                    reloadDataFromRelation();
     1073                } else {
     1074                    new Notification(tr("Relation modified outside of relation editor with pending changes. Conflict resolution required."))
     1075                    .setIcon(JOptionPane.WARNING_MESSAGE).show();
     1076                }
     1077            }
     1078        }
     1079    }
     1080
     1081    @Override
     1082    public boolean isDirtyEditor() {
     1083        Relation snapshot = getRelationSnapshot();
     1084        Relation relation = getRelation();
     1085        return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) ||
     1086                tagEditorPanel.getModel().isDirty() || relation == null || relation.getDataSet() == null;
    10691087    }
    10701088}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/IRelationEditor.java

    r10113 r19398  
    4040     * @return true if the currently edited relation has been changed elsewhere.
    4141     */
    42     boolean isDirtyRelation();
     42    default boolean isDirtyRelation() {
     43        return isDirtyRelation(false);
     44    }
     45
     46    /**
     47     * Replies true if the currently edited relation has been changed elsewhere.
     48     *
     49     * In this case a relation editor can't apply updates to the relation directly. Rather,
     50     * it has to create a conflict.
     51     *
     52     * @param ignoreUninterestingTags whether to ignore uninteresting tag changes
     53     * @return true if the currently edited relation has been changed elsewhere.
     54     * @since xxx
     55     */
     56    boolean isDirtyRelation(boolean ignoreUninterestingTags);
     57
     58    /**
     59     * Replies true if the relation has been changed in the editor (but not yet applied).
     60     *
     61     * Reloading data from the relation would cause the pending changes to be lost.
     62     *
     63     * @return true if the currently edited relation has been changed in the editor.
     64     * @since xxx
     65     */
     66    boolean isDirtyEditor();
    4367
    4468    /**
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    r17358 r19398  
    148148    @Override
    149149    public final boolean isDirtyRelation() {
    150         return !relation.hasEqualSemanticAttributes(relationSnapshot);
     150        return isDirtyRelation(false);
     151    }
     152
     153    @Override
     154    public final boolean isDirtyRelation(boolean ignoreUninterestingTags) {
     155        if (relation != null && relation.getDataSet() == null &&
     156            relationSnapshot != null && relationSnapshot.getDataSet() == null) {
     157            return false;
     158        }
     159
     160        return !relation.hasEqualSemanticAttributes(relationSnapshot, ignoreUninterestingTags);
    151161    }
    152162
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java

    r17444 r19398  
    6868    @Override
    6969    public void updateEnabledState() {
    70         Relation snapshot = getEditor().getRelationSnapshot();
    71         Relation relation = getEditor().getRelation();
    72         if (relation != null && relation.getDataSet() == null)
    73             relation = null; // see #19915
    74         if (relation != null && snapshot != null && snapshot.getDataSet() == null) {
    75             // relation was changed outside of the editor
    76             // either it was modified or deleted or changed by an undo
    77             setEnabled(!snapshot.hasEqualSemanticAttributes(relation, false /* don't ignore uninteresting keys */));
    78             return;
    79         }
    80         setEnabled(false);
     70        setEnabled(getEditor().isDirtyRelation());
    8171    }
    8272
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r18413 r19398  
    193193
    194194    protected boolean isEditorDirty() {
    195         Relation snapshot = editorAccess.getEditor().getRelationSnapshot();
    196         return (snapshot != null && !getMemberTableModel().hasSameMembersAs(snapshot)) || getTagModel().isDirty()
    197                 || getEditor().getRelation() == null || getEditor().getRelation().getDataSet() == null;
     195        return editorAccess.getEditor().isDirtyEditor();
    198196    }
    199197}
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    r19050 r19398  
    9191            @Override
    9292            public boolean isDirtyRelation() {
     93                return false;
     94            }
     95
     96            @Override
     97            public boolean isDirtyRelation(boolean ignoreUninterestingTags) {
     98                return false;
     99            }
     100
     101            @Override
     102            public boolean isDirtyEditor() {
    93103                return false;
    94104            }
Note: See TracChangeset for help on using the changeset viewer.