Пример #1
0
    def setUp(self):
        self.stack = CommandStack()
        self.undo_manager = UndoManager()
        self.stack.undo_manager = self.undo_manager
        self.undo_manager.active_stack = self.stack

        self.command = SimpleCommand()
Пример #2
0
class TestUndoManager(unittest.TestCase, UnittestTools):
    def setUp(self):
        self.stack_a = CommandStack()
        self.stack_b = CommandStack()
        self.undo_manager = UndoManager()
        self.stack_a.undo_manager = self.undo_manager
        self.stack_b.undo_manager = self.undo_manager

        self.undo_manager.active_stack = self.stack_a

        self.command = SimpleCommand()

    # Command pushing tests ---------------------------------------------------

    def test_undo(self):
        self.assertEqual(self.stack_a._index, -1)
        self.stack_a.push(self.command)
        self.assertEqual(self.stack_a._index, 0)
        with self.assertTraitChanges(self.undo_manager,
                                     'stack_updated',
                                     count=1):
            self.undo_manager.undo()
        self.assertEqual(self.stack_a._index, -1)

    def test_redo(self):
        self.assertEqual(self.stack_a._index, -1)
        self.stack_a.push(self.command)
        self.undo_manager.undo()
        self.assertEqual(self.stack_a._index, -1)
        with self.assertTraitChanges(self.undo_manager,
                                     'stack_updated',
                                     count=1):
            self.undo_manager.redo()
        self.assertEqual(self.stack_a._index, 0)

    def test_change_active_stack(self):
        for _ in range(5):
            self.stack_a.push(self.command)
        self.assertEqual(self.stack_a._index, 4)
        self.undo_manager.active_stack = self.stack_b
        for _ in range(5):
            self.stack_b.push(self.command)
        self.assertEqual(self.stack_b._index, 4)
        for _ in range(3):
            self.undo_manager.undo()
        self.undo_manager.redo()

        self.assertEqual(self.stack_a._index, 4)
        self.assertEqual(self.stack_b._index, 2)

    def test_active_stack_clean(self):
        self.assertTrue(self.undo_manager.active_stack_clean)
        self.stack_a.push(self.command)
        self.assertFalse(self.undo_manager.active_stack_clean)
        self.undo_manager.active_stack = None
        self.assertTrue(self.undo_manager.active_stack_clean)
Пример #3
0
class TestRedoAction(unittest.TestCase):
    def setUp(self):
        self.stack = CommandStack()
        self.undo_manager = UndoManager()
        self.stack.undo_manager = self.undo_manager
        self.undo_manager.active_stack = self.stack

        self.command = SimpleCommand()

    def test_update(self):
        redo_action = RedoAction(command=self.command,
                                 undo_manager=self.undo_manager)
        self.stack.push(self.command)
        self.undo_manager.undo()
        self.assertTrue(redo_action.enabled)
        self.assertEqual(redo_action.name, "&Redo Increment by 1")
Пример #4
0
 def setUp(self):
     self.undo_manager = UndoManager()
     self.undo_manager.undo = MagicMock()
     self.undo_manager.redo = MagicMock()
     self.component = Component()
     self.tool = UndoTool(component=self.component,
                          undo_manager=self.undo_manager)
     self.component.tools.append(self.tool)
Пример #5
0
    def _undo_manager_default(self):
        """ Trait initializer. """

        # We make sure the undo package is entirely optional.
        try:
            from pyface.undo.api import UndoManager
        except ImportError:
            return None

        return UndoManager()
Пример #6
0
 def _manager_default(self):
     manager = UndoManager()
     return manager
Пример #7
0
    def setUp(self):
        self.stack = CommandStack()
        undo_manager = UndoManager()
        self.stack.undo_manager = undo_manager

        self.command = SimpleCommand()
Пример #8
0
 def _undo_manager_default(self):
     return UndoManager()