Changeset 13943 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-06-17T17:23:47+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16389 - fix wrong undo/redo behaviour in command stack dialog (regression from r13729)

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

Legend:

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

    r11048 r13943  
    1313
    1414    protected final transient PseudoCommand cmd;
    15     protected final int idx;
    1615
    1716    /**
    1817     * Constructs a new {@code CommandListMutableTreeNode}.
    1918     * @param cmd command
    20      * @param idx index
    2119     */
    22     public CommandListMutableTreeNode(PseudoCommand cmd, int idx) {
     20    public CommandListMutableTreeNode(PseudoCommand cmd) {
    2321        super(new JLabel(cmd.getDescriptionText(), cmd.getDescriptionIcon(), JLabel.HORIZONTAL));
    2422        this.cmd = cmd;
    25         this.idx = idx;
    2623    }
    2724
     
    3936     */
    4037    public int getIndex() {
    41         return idx;
     38        return getParent().getIndex(this);
    4239    }
    4340}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r13824 r13943  
    273273        undoRoot = new DefaultMutableTreeNode();
    274274        for (int i = 0; i < undoCommands.size(); ++i) {
    275             undoRoot.add(getNodeForCommand(undoCommands.get(i), i));
     275            undoRoot.add(getNodeForCommand(undoCommands.get(i)));
    276276        }
    277277        undoTreeModel.setRoot(undoRoot);
     
    282282        redoRoot = new DefaultMutableTreeNode();
    283283        for (int i = 0; i < redoCommands.size(); ++i) {
    284             redoRoot.add(getNodeForCommand(redoCommands.get(i), i));
     284            redoRoot.add(getNodeForCommand(redoCommands.get(i)));
    285285        }
    286286        redoTreeModel.setRoot(redoRoot);
     
    330330     * Recursively adds child commands.
    331331     * @param c the command
    332      * @param idx index
    333332     * @return the resulting node
    334333     */
    335     protected CommandListMutableTreeNode getNodeForCommand(PseudoCommand c, int idx) {
    336         CommandListMutableTreeNode node = new CommandListMutableTreeNode(c, idx);
     334    protected CommandListMutableTreeNode getNodeForCommand(PseudoCommand c) {
     335        CommandListMutableTreeNode node = new CommandListMutableTreeNode(c);
    337336        if (c.getChildren() != null) {
    338337            List<PseudoCommand> children = new ArrayList<>(c.getChildren());
    339338            for (int i = 0; i < children.size(); ++i) {
    340                 node.add(getNodeForCommand(children.get(i), i));
     339                node.add(getNodeForCommand(children.get(i)));
    341340            }
    342341        }
     
    371370    public void commandAdded(CommandAddedEvent e) {
    372371        if (isVisible()) {
    373             undoRoot.add(getNodeForCommand(e.getCommand(), undoRoot.getChildCount()));
     372            undoRoot.add(getNodeForCommand(e.getCommand()));
    374373            undoTreeModel.nodeStructureChanged(undoRoot);
    375374            ensureTreesConsistency();
Note: See TracChangeset for help on using the changeset viewer.