def test_element_factory_undo(self): from gaphor.core.modeling import Element event_manager = EventManager() undo_manager = UndoManager(event_manager) element_factory = ElementFactory(event_manager) undo_manager.begin_transaction() p = element_factory.create(Element) assert undo_manager._current_transaction assert undo_manager._current_transaction._actions assert undo_manager.can_undo() undo_manager.commit_transaction() assert undo_manager.can_undo() assert element_factory.size() == 1 undo_manager.undo_transaction() assert not undo_manager.can_undo() assert undo_manager.can_redo() assert element_factory.size() == 0 undo_manager.redo_transaction() assert undo_manager.can_undo() assert not undo_manager.can_redo() assert element_factory.size() == 1 assert element_factory.lselect()[0] is p undo_manager.shutdown()
def test_redo_stack(self): from gaphor.core.modeling import Element event_manager = EventManager() undo_manager = UndoManager(event_manager) element_factory = ElementFactory(event_manager) undo_manager.begin_transaction() p = element_factory.create(Element) assert undo_manager._current_transaction assert undo_manager._current_transaction._actions assert undo_manager.can_undo() undo_manager.commit_transaction() assert undo_manager.can_undo() assert element_factory.size() == 1, element_factory.size() with Transaction(event_manager): element_factory.create(Element) assert undo_manager.can_undo() assert not undo_manager.can_redo() assert element_factory.size() == 2 undo_manager.undo_transaction() assert undo_manager.can_undo() assert 1 == len(undo_manager._undo_stack) assert 1 == len(undo_manager._redo_stack) assert undo_manager.can_redo() assert element_factory.size() == 1 undo_manager.undo_transaction() assert not undo_manager.can_undo() assert undo_manager.can_redo() assert 0 == len(undo_manager._undo_stack) assert 2 == len(undo_manager._redo_stack) # assert element_factory.size() == 0 undo_manager.redo_transaction() assert 1 == len(undo_manager._undo_stack) assert 1 == len(undo_manager._redo_stack) assert undo_manager.can_undo() assert undo_manager.can_redo() assert element_factory.size() == 1 undo_manager.redo_transaction() assert undo_manager.can_undo() assert not undo_manager.can_redo() assert element_factory.size() == 2 assert p in element_factory.lselect() undo_manager.shutdown()
def test_element_factory_rollback(self): from gaphor.core.modeling import Element event_manager = EventManager() undo_manager = UndoManager(event_manager) element_factory = ElementFactory(event_manager) undo_manager.begin_transaction() element_factory.create(Element) assert undo_manager._current_transaction assert undo_manager._current_transaction._actions assert undo_manager.can_undo() undo_manager.rollback_transaction() assert not undo_manager.can_undo() assert element_factory.size() == 0 undo_manager.shutdown()