Changeset 14977 in josm for trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
- Timestamp:
- 2019-04-09T01:32:56+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r14355 r14977 283 283 */ 284 284 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) { 285 301 final Map<String, String> tags = new HashMap<>(); 286 302 287 303 // 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 } 290 308 291 309 // obtain from dataset … … 318 336 } 319 337 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 320 344 pnlTagSettings.initFromTags(tags); 321 345 pnlTagSettings.tableChanged(null); 346 pnlBasicUploadSettings.discardAllUndoableEdits(); 322 347 } 323 348 … … 519 544 @Override 520 545 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 521 549 if (isUploadCommentTooShort(dialog.getUploadComment()) && warnUploadComment()) { 522 550 // abort for missing comment … … 620 648 if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) { 621 649 Changeset cs = (Changeset) evt.getNewValue(); 622 setChangesetTags(dataSet );650 setChangesetTags(dataSet, cs == null); // keep comment/source of first tab for new changesets 623 651 if (cs == null) { 624 652 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset")); … … 634 662 @Override 635 663 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) { 639 682 final String url; 640 683 if (newValue == null || newValue.getValue() == null) { … … 648 691 private static String getLastChangesetTagFromHistory(String historyKey, List<String> def) { 649 692 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)) 652 695 && !history.isEmpty()) { 653 696 return history.iterator().next(); 654 } else { 655 return null; 656 } 697 } 698 return null; 657 699 } 658 700 … … 661 703 * @return the last changeset comment from history 662 704 */ 663 public String getLastChangesetCommentFromHistory() {705 public static String getLastChangesetCommentFromHistory() { 664 706 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.HISTORY_KEY, new ArrayList<String>()); 665 707 } … … 669 711 * @return the last changeset source from history 670 712 */ 671 public String getLastChangesetSourceFromHistory() {713 public static String getLastChangesetSourceFromHistory() { 672 714 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.SOURCE_HISTORY_KEY, BasicUploadSettingsPanel.getDefaultSources()); 673 715 } … … 695 737 } 696 738 739 @Override 740 public void forceUpdateActiveField() { 741 if (tpConfigPanels.getSelectedComponent() == pnlBasicUploadSettings) { 742 pnlBasicUploadSettings.forceUpdateActiveField(); 743 } 744 } 745 697 746 /** 698 747 * Clean dialog state and release resources.
Note:
See TracChangeset
for help on using the changeset viewer.