Changeset 15751 in josm for trunk/src


Ignore:
Timestamp:
2020-01-22T21:18:17+01:00 (5 years ago)
Author:
simon04
Message:

fix #18598 - CopyKeyValueAction: count values going to be copied

This fixes the nasty i18n string "Copy selected Key(s)/Value(s)".

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/properties
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/AbstractCopyAction.java

    r15717 r15751  
    99import java.util.function.Supplier;
    1010import java.util.stream.Collectors;
     11import java.util.stream.Stream;
    1112
    1213import javax.swing.AbstractAction;
     
    4041    protected abstract Collection<String> getString(Tagged p, String key);
    4142
    42     @Override
    43     public void actionPerformed(ActionEvent ae) {
     43    protected Stream<String> valueStream() {
    4444        int[] rows = tagTable.getSelectedRows();
    4545        Collection<? extends Tagged> sel = objectSupplier.get();
    46         if (rows.length == 0 || sel == null || sel.isEmpty()) return;
    47 
    48         final String values = Arrays.stream(rows)
     46        if (rows.length == 0 || sel == null || sel.isEmpty()) return Stream.empty();
     47        return Arrays.stream(rows)
    4948                .mapToObj(keySupplier)
    5049                .flatMap(key -> sel.stream().map(p -> getString(p, key)))
    5150                .filter(Objects::nonNull)
    52                 .flatMap(Collection::stream)
     51                .flatMap(Collection::stream);
     52    }
     53
     54    @Override
     55    public void actionPerformed(ActionEvent ae) {
     56        final String values = valueStream()
    5357                .sorted()
    5458                .collect(Collectors.joining("\n"));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/CopyKeyValueAction.java

    r13849 r15751  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.util.Collection;
     
    1011
    1112import javax.swing.JTable;
     13import javax.swing.event.PopupMenuEvent;
     14import javax.swing.event.PopupMenuListener;
    1215
    1316import org.openstreetmap.josm.data.osm.Tag;
     
    1821 * @since 13521
    1922 */
    20 public class CopyKeyValueAction extends AbstractCopyAction {
     23public class CopyKeyValueAction extends AbstractCopyAction implements PopupMenuListener {
    2124
    2225    /**
     
    2831    public CopyKeyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) {
    2932        super(tagTable, keyFn, objectSp);
    30         putValue(NAME, tr("Copy selected Key(s)/Value(s)"));
     33        setName(0);
    3134        putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag(s) to clipboard"));
     35    }
     36
     37    private void setName(long n) {
     38        putValue(NAME, trn("Copy selected {0} Key/Value", "Copy selected {0} Keys/Values", n, n));
    3239    }
    3340
     
    3744        return v == null ? null : Collections.singleton(new Tag(key, v).toString());
    3845    }
     46
     47    @Override
     48    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     49        setName(valueStream().count());
     50    }
     51
     52    @Override
     53    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
     54        // Do nothing
     55    }
     56
     57    @Override
     58    public void popupMenuCanceled(PopupMenuEvent e) {
     59        // Do nothing
     60    }
    3961}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r15707 r15751  
    447447        tagMenu.add(copyValueAction);
    448448        tagMenu.add(copyKeyValueAction);
     449        tagMenu.addPopupMenuListener(copyKeyValueAction);
    449450        tagMenu.add(copyAllKeyValueAction);
    450451        tagMenu.addSeparator();
Note: See TracChangeset for help on using the changeset viewer.