Changeset 15117 in josm


Ignore:
Timestamp:
2019-05-26T19:47:06+02:00 (5 weeks ago)
Author:
Don-vip
Message:

make sure upload comments are not remembered if upload.comment.max-age is <= 0

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

Legend:

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

    r15011 r15117  
    1919import java.util.concurrent.TimeUnit;
    2020
    21 import javax.swing.Action;
    2221import javax.swing.BorderFactory;
    2322import javax.swing.JCheckBox;
     
    162161    }
    163162
    164     public void setUploadTagDownFocusTraversalHandlers(final Action handler) {
     163    void setUploadTagDownFocusTraversalHandlers(final ActionListener handler) {
    165164        setHistoryComboBoxDownFocusTraversalHandler(handler, hcbUploadComment);
    166165        setHistoryComboBoxDownFocusTraversalHandler(handler, hcbUploadSource);
    167166    }
    168167
    169     public void setHistoryComboBoxDownFocusTraversalHandler(final Action handler, final HistoryComboBox hcb) {
     168    private static void setHistoryComboBoxDownFocusTraversalHandler(ActionListener handler, HistoryComboBox hcb) {
    170169        hcb.getEditor().addActionListener(handler);
    171170        hcb.getEditorComponent().addKeyListener(new HistoryComboBoxKeyAdapter(hcb, handler));
     
    177176    public void rememberUserInput() {
    178177        // store the history of comments
    179         hcbUploadComment.addCurrentItemToHistory();
    180         Config.getPref().putList(HISTORY_KEY, hcbUploadComment.getHistory());
    181         Config.getPref().putLong(HISTORY_LAST_USED_KEY, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
     178        if (getHistoryMaxAgeKey() > 0) {
     179            hcbUploadComment.addCurrentItemToHistory();
     180            Config.getPref().putList(HISTORY_KEY, hcbUploadComment.getHistory());
     181            Config.getPref().putLong(HISTORY_LAST_USED_KEY, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
     182        }
    182183        // store the history of sources
    183184        hcbUploadSource.addCurrentItemToHistory();
     
    232233    }
    233234
     235    static long getHistoryMaxAgeKey() {
     236        return Config.getPref().getLong(HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toSeconds(4));
     237    }
     238
     239    static long getHistoryLastUsedKey() {
     240        return Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0);
     241    }
     242
    234243    static final class HistoryComboBoxKeyAdapter extends KeyAdapter {
    235244        private final HistoryComboBox hcb;
    236         private final Action handler;
    237 
    238         HistoryComboBoxKeyAdapter(HistoryComboBox hcb, Action handler) {
     245        private final ActionListener handler;
     246
     247        HistoryComboBoxKeyAdapter(HistoryComboBox hcb, ActionListener handler) {
    239248            this.hcb = hcb;
    240249            this.handler = handler;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r15051 r15117  
    2727import java.util.Map.Entry;
    2828import java.util.Optional;
    29 import java.util.concurrent.TimeUnit;
    3029import java.util.stream.Collectors;
    3130
     
    238237        );
    239238
    240         pnlBasicUploadSettings.setUploadTagDownFocusTraversalHandlers(
    241                 new AbstractAction() {
    242                     @Override
    243                     public void actionPerformed(ActionEvent e) {
    244                         btnUpload.requestFocusInWindow();
    245                     }
    246                 }
    247         );
     239        pnlBasicUploadSettings.setUploadTagDownFocusTraversalHandlers(e -> btnUpload.requestFocusInWindow());
    248240
    249241        setMinimumSize(new Dimension(600, 350));
     
    778770    private static String getLastChangesetTagFromHistory(String historyKey, List<String> def) {
    779771        Collection<String> history = Config.getPref().getList(historyKey, def);
    780         long age = System.currentTimeMillis() / 1000 - Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0);
    781         if (age < Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toSeconds(4))
    782                 && !history.isEmpty()) {
     772        long age = System.currentTimeMillis() / 1000 - BasicUploadSettingsPanel.getHistoryLastUsedKey();
     773        if (age < BasicUploadSettingsPanel.getHistoryMaxAgeKey() && !history.isEmpty()) {
    783774            return history.iterator().next();
    784775        }
Note: See TracChangeset for help on using the changeset viewer.