Ignore:
Timestamp:
2019-04-09T01:32:56+02:00 (6 years ago)
Author:
Don-vip
Message:

ensures consistency of upload comment:

  • fix #11168 - ctrl-z/undo could reset unwanted old changeset comment
  • fix #13474 - selecting "new changeset" after having entered a changeset comment did reset it to the previous value
  • fix #17452 - ctrl-enter while typing a changeset comment did upload with the previous value
  • fix behaviour of upload.comment.max-age: values were reset after 5 months instead of intended 4 hours because seconds were compared to milliseconds
  • avoid creation of unneeded undo/redo internal classes for non-editable text fields
  • ensures consistency of upload dialog if upload.comment properties are modified manually from advanced preferences
  • add a source attribute to preference events to know which class modified the preference entry
  • refactor reflection utils
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r14355 r14977  
    283283     */
    284284    public void setChangesetTags(DataSet dataSet) {
     285        setChangesetTags(dataSet, false);
     286    }
     287
     288    /**
     289     * Sets the tags for this upload based on (later items overwrite earlier ones):
     290     * <ul>
     291     * <li>previous "source" and "comment" input</li>
     292     * <li>the tags set in the dataset (see {@link DataSet#getChangeSetTags()})</li>
     293     * <li>the tags from the selected open changeset</li>
     294     * <li>the JOSM user agent (see {@link Version#getAgentString(boolean)})</li>
     295     * </ul>
     296     *
     297     * @param dataSet to obtain the tags set in the dataset
     298     * @param keepSourceComment if {@code true}, keep upload {@code source} and {@code comment} current values from models
     299     */
     300    private void setChangesetTags(DataSet dataSet, boolean keepSourceComment) {
    285301        final Map<String, String> tags = new HashMap<>();
    286302
    287303        // obtain from previous input
    288         tags.put("source", getLastChangesetSourceFromHistory());
    289         tags.put("comment", getLastChangesetCommentFromHistory());
     304        if (!keepSourceComment) {
     305            tags.put("source", getLastChangesetSourceFromHistory());
     306            tags.put("comment", getLastChangesetCommentFromHistory());
     307        }
    290308
    291309        // obtain from dataset
     
    318336        }
    319337
     338        // ignore source/comment to keep current values from models ?
     339        if (keepSourceComment) {
     340            tags.put("source", changesetSourceModel.getComment());
     341            tags.put("comment", changesetCommentModel.getComment());
     342        }
     343
    320344        pnlTagSettings.initFromTags(tags);
    321345        pnlTagSettings.tableChanged(null);
     346        pnlBasicUploadSettings.discardAllUndoableEdits();
    322347    }
    323348
     
    519544        @Override
    520545        public void actionPerformed(ActionEvent e) {
     546            // force update of model in case dialog is closed before focus lost event, see #17452
     547            dialog.forceUpdateActiveField();
     548
    521549            if (isUploadCommentTooShort(dialog.getUploadComment()) && warnUploadComment()) {
    522550                // abort for missing comment
     
    620648        if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) {
    621649            Changeset cs = (Changeset) evt.getNewValue();
    622             setChangesetTags(dataSet);
     650            setChangesetTags(dataSet, cs == null); // keep comment/source of first tab for new changesets
    623651            if (cs == null) {
    624652                tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
     
    634662    @Override
    635663    public void preferenceChanged(PreferenceChangeEvent e) {
    636         if (e.getKey() == null || !"osm-server.url".equals(e.getKey()))
    637             return;
    638         final Setting<?> newValue = e.getNewValue();
     664        if (e.getKey() != null
     665                && e.getSource() != getClass()
     666                && e.getSource() != BasicUploadSettingsPanel.class) {
     667            switch (e.getKey()) {
     668                case "osm-server.url":
     669                    osmServerUrlChanged(e.getNewValue());
     670                    break;
     671                case BasicUploadSettingsPanel.HISTORY_KEY:
     672                case BasicUploadSettingsPanel.SOURCE_HISTORY_KEY:
     673                    pnlBasicUploadSettings.refreshHistoryComboBoxes();
     674                    break;
     675                default:
     676                    return;
     677            }
     678        }
     679    }
     680
     681    private void osmServerUrlChanged(Setting<?> newValue) {
    639682        final String url;
    640683        if (newValue == null || newValue.getValue() == null) {
     
    648691    private static String getLastChangesetTagFromHistory(String historyKey, List<String> def) {
    649692        Collection<String> history = Config.getPref().getList(historyKey, def);
    650         int age = (int) (System.currentTimeMillis() / 1000 - Config.getPref().getInt(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0));
    651         if (history != null && age < Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toMillis(4))
     693        long age = System.currentTimeMillis() / 1000 - Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0);
     694        if (age < Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toSeconds(4))
    652695                && !history.isEmpty()) {
    653696            return history.iterator().next();
    654         } else {
    655             return null;
    656         }
     697        }
     698        return null;
    657699    }
    658700
     
    661703     * @return the last changeset comment from history
    662704     */
    663     public String getLastChangesetCommentFromHistory() {
     705    public static String getLastChangesetCommentFromHistory() {
    664706        return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.HISTORY_KEY, new ArrayList<String>());
    665707    }
     
    669711     * @return the last changeset source from history
    670712     */
    671     public String getLastChangesetSourceFromHistory() {
     713    public static String getLastChangesetSourceFromHistory() {
    672714        return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.SOURCE_HISTORY_KEY, BasicUploadSettingsPanel.getDefaultSources());
    673715    }
     
    695737    }
    696738
     739    @Override
     740    public void forceUpdateActiveField() {
     741        if (tpConfigPanels.getSelectedComponent() == pnlBasicUploadSettings) {
     742            pnlBasicUploadSettings.forceUpdateActiveField();
     743        }
     744    }
     745
    697746    /**
    698747     * Clean dialog state and release resources.
Note: See TracChangeset for help on using the changeset viewer.