Changeset 13817 in josm for trunk


Ignore:
Timestamp:
2018-05-22T02:42:11+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #15828 - Allow copy/pasting author names from user list dialog

File:
1 edited

Legend:

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

    r13434 r13817  
    2121import java.util.Map;
    2222import java.util.Set;
     23import java.util.stream.Collectors;
    2324
    2425import javax.swing.AbstractAction;
     26import javax.swing.JPopupMenu;
    2527import javax.swing.JTable;
    2628import javax.swing.ListSelectionModel;
     
    3840import org.openstreetmap.josm.gui.MainApplication;
    3941import org.openstreetmap.josm.gui.SideButton;
     42import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    4043import org.openstreetmap.josm.gui.layer.Layer;
    4144import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     
    4346import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4447import org.openstreetmap.josm.gui.util.GuiHelper;
     48import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    4549import org.openstreetmap.josm.tools.ImageProvider;
    4650import org.openstreetmap.josm.tools.Logging;
     
    5256 * Displays a dialog with all users who have last edited something in the
    5357 * selection area, along with the number of objects.
    54  *
     58 * @since 237
    5559 */
    5660public class UserListDialog extends ToggleDialog implements DataSelectionListener, ActiveLayerChangeListener {
     
    6266    private UserTableModel model;
    6367    private SelectUsersPrimitivesAction selectionUsersPrimitivesAction;
     68    private final JPopupMenu popupMenu = new JPopupMenu();
    6469
    6570    /**
     
    104109            new SideButton(showUserInfoAction)
    105110        ));
     111
     112        // -- popup menu
     113        popupMenu.add(new AbstractAction(tr("Copy")) {
     114            @Override
     115            public void actionPerformed(ActionEvent e) {
     116                ClipboardUtils.copyString(getSelectedUsers().stream().map(User::getName).collect(Collectors.joining(", ")));
     117            }
     118        });
     119        userTable.addMouseListener(new PopupMenuLauncher(popupMenu));
    106120    }
    107121
     
    144158        super.showDialog();
    145159        refreshForActiveLayer(MainApplication.getLayerManager().getActiveLayer());
     160    }
     161
     162    private List<User> getSelectedUsers() {
     163        int[] rows = userTable.getSelectedRows();
     164        return rows.length == 0 ? Collections.emptyList() : model.getSelectedUsers(rows);
    146165    }
    147166
     
    195214        @Override
    196215        public void actionPerformed(ActionEvent e) {
    197             int[] rows = userTable.getSelectedRows();
    198             if (rows.length == 0)
    199                 return;
    200             List<User> users = model.getSelectedUsers(rows);
     216            List<User> users = getSelectedUsers();
    201217            if (users.isEmpty())
    202218                return;
Note: See TracChangeset for help on using the changeset viewer.