Changeset 17772 in josm for trunk


Ignore:
Timestamp:
2021-04-13T22:20:19+02:00 (4 years ago)
Author:
simon04
Message:

see #20756 - Extract CommandStackDialog.getSelectedCommand

File:
1 edited

Legend:

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

    r17399 r17772  
    347347    /**
    348348     * Return primitives that are affected by some command
    349      * @param path GUI elements
    350      * @return collection of affected primitives, onluy usable ones
    351      */
    352     protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(TreePath path) {
    353         PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
     349     * @param c the command
     350     * @return collection of affected primitives, only usable ones
     351     */
     352    protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(PseudoCommand c) {
    354353        final OsmDataLayer currentLayer = MainApplication.getLayerManager().getEditLayer();
    355354        return new SubclassFilteredCollection<>(
     
    425424        @Override
    426425        public void actionPerformed(ActionEvent e) {
    427             TreePath path;
    428             if (!undoTree.isSelectionEmpty()) {
    429                 path = undoTree.getSelectionPath();
    430             } else if (!redoTree.isSelectionEmpty()) {
    431                 path = redoTree.getSelectionPath();
    432             } else {
    433                 // see #19514 for a possible cause
     426            PseudoCommand command = getSelectedCommand();
     427            if (command == null) {
    434428                return;
    435429            }
     
    437431            DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
    438432            if (dataSet == null) return;
    439             dataSet.setSelected(getAffectedPrimitives(path));
     433            dataSet.setSelected(getAffectedPrimitives(command));
    440434        }
    441435
     
    444438            setEnabled(!undoTree.isSelectionEmpty() || !redoTree.isSelectionEmpty());
    445439        }
     440    }
     441
     442    /**
     443     * Returns the selected undo/redo command
     444     * @return the selected undo/redo command or {@code null}
     445     */
     446    public PseudoCommand getSelectedCommand() {
     447        TreePath path;
     448        if (!undoTree.isSelectionEmpty()) {
     449            path = undoTree.getSelectionPath();
     450        } else if (!redoTree.isSelectionEmpty()) {
     451            path = redoTree.getSelectionPath();
     452        } else {
     453            // see #19514 for a possible cause
     454            return null;
     455        }
     456        return path != null ? ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand() : null;
    446457    }
    447458
Note: See TracChangeset for help on using the changeset viewer.