Changeset 14562 in josm


Ignore:
Timestamp:
2018-12-15T17:19:00+01:00 (10 months ago)
Author:
GerdP
Message:

fix #16911 regression from r13729 : make sure that redo tree is cleared when a command is added after one or more undos

Location:
trunk
Files:
2 edited

Legend:

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

    r14281 r14562  
    362362    }
    363363
     364    protected boolean redoTreeIsEmpty() {
     365        return redoTree.getRowCount() == 0;
     366    }
     367
    364368    @Override
    365369    public void cleaned(CommandQueueCleanedEvent e) {
     
    374378            undoRoot.add(getNodeForCommand(e.getCommand()));
    375379            undoTreeModel.nodeStructureChanged(undoRoot);
     380            // fix 16911: make sure that redo tree is rebuild with empty list
     381            if (!redoTreeIsEmpty())
     382                buildRedoTree();
    376383            ensureTreesConsistency();
    377384        }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java

    r14281 r14562  
    7373        }
    7474    }
     75
     76    /**
     77     * Unit test of {@link CommandStackDialog} class - undo followed by addCommand should empty redo tree.
     78     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/16911">Bug #16911</a>.
     79     */
     80    @Test
     81    public void testCommandStackDialogUndoAddCommand() {
     82        DataSet ds = new DataSet();
     83        OsmDataLayer layer = new OsmDataLayer(ds, "", null);
     84        MainApplication.getLayerManager().addLayer(layer);
     85        try {
     86            Command cmd1 = TestUtils.newCommand(ds);
     87            Command cmd2 = TestUtils.newCommand(ds);
     88            Command cmd3 = TestUtils.newCommand(ds);
     89            MapFrame map = MainApplication.getMap();
     90            CommandStackDialog dlg = new CommandStackDialog();
     91            map.addToggleDialog(dlg);
     92            dlg.unfurlDialog();
     93            assertTrue(dlg.isVisible());
     94            assertTrue(dlg.redoTreeIsEmpty());
     95            UndoRedoHandler.getInstance().add(cmd1);
     96            assertTrue(dlg.redoTreeIsEmpty());
     97            UndoRedoHandler.getInstance().add(cmd2);
     98            assertTrue(dlg.redoTreeIsEmpty());
     99            UndoRedoHandler.getInstance().undo(1);
     100            assertFalse(dlg.redoTreeIsEmpty());
     101            UndoRedoHandler.getInstance().add(cmd3);
     102            assertTrue(dlg.redoTreeIsEmpty());
     103
     104            assertTrue(UndoRedoHandler.getInstance().hasUndoCommands());
     105            assertFalse(UndoRedoHandler.getInstance().hasRedoCommands());
     106
     107            map.removeToggleDialog(dlg);
     108            dlg.hideDialog();
     109            assertFalse(dlg.isVisible());
     110        } finally {
     111            UndoRedoHandler.getInstance().clean();
     112            MainApplication.getLayerManager().removeLayer(layer);
     113        }
     114    }
    75115}
Note: See TracChangeset for help on using the changeset viewer.