Changeset 18467 in josm


Ignore:
Timestamp:
2022-06-06T19:16:28+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #20025, #22080: Notify users when changeset tags are programmatically modified

This only works for non-late upload hooks.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r18283 r18467  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
     9import java.util.HashMap;
    910import java.util.LinkedList;
    1011import java.util.List;
     
    243244        dialog.setUploadedPrimitives(apiData);
    244245        dialog.initLifeCycle(layer.getDataSet());
     246        Map<String, String> changesetTags = dialog.getChangeset().getKeys();
     247        Map<String, String> originalChangesetTags = new HashMap<>(changesetTags);
     248        for (UploadHook hook : UPLOAD_HOOKS) {
     249            hook.modifyChangesetTags(changesetTags);
     250        }
     251        dialog.getModel().putAll(changesetTags);
     252        if (!originalChangesetTags.equals(changesetTags)) {
     253            dialog.setChangesetTagsModifiedProgramatically();
     254        }
    245255        dialog.setVisible(true);
    246256        dialog.rememberUserInput();
     
    259269        // Any hooks want to change the changeset tags?
    260270        Changeset cs = dialog.getChangeset();
    261         Map<String, String> changesetTags = cs.getKeys();
    262         for (UploadHook hook : UPLOAD_HOOKS) {
    263             hook.modifyChangesetTags(changesetTags);
    264         }
     271        changesetTags = cs.getKeys();
    265272        for (UploadHook hook : LATE_UPLOAD_HOOKS) {
    266273            hook.modifyChangesetTags(changesetTags);
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r18457 r18467  
    33
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.marktr;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    67import static org.openstreetmap.josm.tools.I18n.trn;
    78
    89import java.awt.BorderLayout;
     10import java.awt.Color;
    911import java.awt.Component;
    1012import java.awt.Dimension;
     
    3436import javax.swing.JSplitPane;
    3537import javax.swing.JTabbedPane;
     38import javax.swing.event.ChangeListener;
    3639
    3740import org.openstreetmap.josm.data.APIDataSet;
     
    3942import org.openstreetmap.josm.data.osm.DataSet;
    4043import org.openstreetmap.josm.data.osm.OsmPrimitive;
     44import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    4145import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    4246import org.openstreetmap.josm.gui.MainApplication;
     
    6569 */
    6670public class UploadDialog extends AbstractUploadDialog implements PreferenceChangedListener, PropertyChangeListener {
     71    /** A warning color to indicate something is non-default in the changeset tags */
     72    private static final Color WARNING_BACKGROUND = new NamedColorProperty(
     73            marktr("Changesets: Non-default advanced settings"), new Color(0xF89042)).get();
    6774    /** the unique instance of the upload dialog */
    6875    private static UploadDialog uploadDialog;
     
    9097
    9198    private transient DataSet dataSet;
     99    private ChangeListener changesetTagListener;
    92100
    93101    /**
     
    148156        pnlSettings.add(pnlTagEditorBorder, GBC.eol().fill(GridBagConstraints.BOTH));
    149157
     158        // if another tab is added, please don't forget to update setChangesetTagsModifiedProgramatically
    150159        tpConfigPanels.add(pnlSettings);
    151160        tpConfigPanels.setTitleAt(1, tr("Settings"));
     
    357366        }
    358367        super.setVisible(visible);
     368    }
     369
     370    /**
     371     * This is called by {@link UploadAction} if {@link org.openstreetmap.josm.actions.upload.UploadHook}s change
     372     * the changeset tags.
     373     */
     374    public void setChangesetTagsModifiedProgramatically() {
     375        final Color originalColor = this.tpConfigPanels.getBackgroundAt(1);
     376        this.tpConfigPanels.setBackgroundAt(1, WARNING_BACKGROUND);
     377        this.tpConfigPanels.setIconAt(1, ImageProvider.get("warning-small"));
     378        if (this.changesetTagListener != null) {
     379            this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
     380        }
     381        this.changesetTagListener = event -> {
     382            if (this.tpConfigPanels.getSelectedIndex() == 1) {
     383                tpConfigPanels.setBackgroundAt(1, originalColor);
     384                tpConfigPanels.setIconAt(1, ImageProvider.get("apply"));
     385                this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
     386                changesetTagListener = null;
     387            }
     388        };
     389
     390        this.tpConfigPanels.addChangeListener(this.changesetTagListener);
    359391    }
    360392
     
    611643        setUploadedPrimitives(null);
    612644        dataSet = null;
     645        if (this.changesetTagListener != null) {
     646            this.changesetTagListener.stateChanged(null);
     647            this.tpConfigPanels.removeChangeListener(this.changesetTagListener);
     648            this.changesetTagListener = null;
     649        }
    613650    }
    614651}
Note: See TracChangeset for help on using the changeset viewer.