From 7298c609abbd4a0b574999ddfce103bbd2c742ff Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Thu, 7 Oct 2004 08:54:16 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: file:///Users/arjan/backup/gaphor/trunk/gaphor@418 a8418922-720d-0410-834f-a69b97ada669 --- ChangeLog | 10 ++++++++++ TODO | 3 +++ gaphor/UML/diagram.py | 2 +- gaphor/diagram/diagramitem.py | 9 ++++++--- gaphor/diagram/itemtool.py | 3 +++ gaphor/ui/diagramactions.py | 21 +++++++++++++-------- gaphor/ui/diagramtab.py | 12 +++++++----- gaphor/ui/diagramwindow.py | 7 +++++-- setup.py | 2 +- 9 files changed, 49 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63fdd3418..1140c50c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-10-07 Arjan Molenaar + + * gaphor/diagram/itemtool.py, gaphor/ui/*: updated to use new + UndoManager interface of DiaCanvas2 0.14.0. Requires CVS version + of diacanvas2 to work. + +2004-10-01 Arjan Molenaar + + Release 0.6.0 + 2004-09-28 Arjan Molenaar * gaphor/diagram/itemtool.py, itemactions.py, nameditem.py: diff --git a/TODO b/TODO index b62314657..8d299e5b9 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,9 @@ As always, there is much to do... Problem: the existing stuff works only on constrcution time. For this we need a menu that can change during the life of the application. +- confirmation window when creating a new model. + +- An option that shows the selected item (in the namespace view) in a diagram. - How to figure out if a module exists without loading it? diff --git a/gaphor/UML/diagram.py b/gaphor/UML/diagram.py index dd9cb0d01..2f0a5e8f1 100644 --- a/gaphor/UML/diagram.py +++ b/gaphor/UML/diagram.py @@ -74,7 +74,7 @@ class Diagram(Namespace, PackageableElement): def __init__(self, id=None, factory=None): super(Diagram, self).__init__(id, factory) self.canvas = DiagramCanvas(self) - self.canvas.set_undo_stack_depth(10) + #self.canvas.set_undo_stack_depth(10) self.canvas.set_property ("allow_undo", 1) def save(self, save_func): diff --git a/gaphor/diagram/diagramitem.py b/gaphor/diagram/diagramitem.py index a0f6db4d8..347523cda 100644 --- a/gaphor/diagram/diagramitem.py +++ b/gaphor/diagram/diagramitem.py @@ -21,6 +21,7 @@ class diagramassociation(association): # TODO: Maybe we should not break our side of the association... # Since signals are still connected as the diagram item is unlinked. + # TODO: Add undo/redo statements. def unlink(self, obj): #print 'diagramassociation.unlink', obj, value @@ -30,9 +31,10 @@ class diagramassociation(association): def _set2(self, obj, value): #print 'diagramassociation._set2', obj, value obj.preserve_property(self.name) - if obj.canvas and obj.canvas.in_undo and len(value.presentation) == 0: - print 'diagramassociation._set2(): relinking!' - value.relink() + #if obj.canvas and obj.canvas.in_undo and len(value.presentation) == 0: +# if obj.canvas and len(value.presentation) == 0: +# print 'diagramassociation._set2(): relinking!' +# value.relink() return association._set2(self, obj, value) def _del(self, obj, value): @@ -100,6 +102,7 @@ class DiagramItem(Presentation): def do_set_property(self, pspec, value): if pspec.name == 'subject': #print 'set subject:', value + # TODO: make property undo-able if value: self.subject = value elif self.subject: diff --git a/gaphor/diagram/itemtool.py b/gaphor/diagram/itemtool.py index db1e27fe9..582ed4701 100644 --- a/gaphor/diagram/itemtool.py +++ b/gaphor/diagram/itemtool.py @@ -54,6 +54,7 @@ class ItemTool(diacanvas.view.Tool): if event.type == BUTTON_PRESS: # If Button1 is pressed, we're going to move the item. if event.button == 1: + view.canvas.undo_manager.begin_transaction() self.grabbed_item = view_item self.old_pos = (event.x, event.y) item.request_update() @@ -71,6 +72,7 @@ class ItemTool(diacanvas.view.Tool): else: self.execute_action('AssociationEndRenameMult') else: + view.canvas.undo_manager.begin_transaction() if isinstance(item, NamedItem): self.execute_action('RenameItem') elif hasattr(item, 'is_editable') and item.is_editable(): @@ -78,6 +80,7 @@ class ItemTool(diacanvas.view.Tool): return True def do_button_release_event(self, view, event): + view.canvas.undo_manager.commit_transaction() if self.grabbed_item: self.grabbed_item = None return True diff --git a/gaphor/ui/diagramactions.py b/gaphor/ui/diagramactions.py index f7163dc78..53e1394d6 100644 --- a/gaphor/ui/diagramactions.py +++ b/gaphor/ui/diagramactions.py @@ -97,11 +97,12 @@ class UndoAction(Action): def update(self): diagram_tab = self._window.get_current_diagram_tab() - self.sensitive = diagram_tab and diagram_tab.get_canvas().get_undo_depth() > 0 + self.sensitive = diagram_tab and diagram_tab.get_canvas().undo_manager.can_undo() def execute(self): - self._window.get_current_diagram_view().canvas.pop_undo() + self._window.get_current_diagram_view().canvas.undo_manager.undo_transaction() self.update() + self._window.execute_action('EditUndoStack') register_action(UndoAction, 'EditUndoStack') @@ -117,11 +118,12 @@ class RedoAction(Action): def update(self): diagram_tab = self._window.get_current_diagram_tab() - self.sensitive = diagram_tab and diagram_tab.get_canvas().get_redo_depth() > 0 + self.sensitive = diagram_tab and diagram_tab.get_canvas().undo_manager.can_redo() def execute(self): - self._window.get_current_diagram_view().canvas.pop_redo() + self._window.get_current_diagram_view().canvas.undo_manager.redo_transaction() self.update() + self._window.execute_action('EditUndoStack') register_action(RedoAction, 'EditUndoStack') @@ -211,10 +213,13 @@ class DeleteAction(Action): def execute(self): view = self._window.get_current_diagram_view() - view.canvas.push_undo('delete') - items = view.selected_items - for i in items: - i.item.unlink() + view.canvas.undo_manager.begin_transaction() + try: + items = view.selected_items + for i in items: + i.item.unlink() + finally: + view.canvas.undo_manager.commit_transaction() register_action(DeleteAction, 'ItemSelect') diff --git a/gaphor/ui/diagramtab.py b/gaphor/ui/diagramtab.py index bd4de90cf..3d169cbb8 100644 --- a/gaphor/ui/diagramtab.py +++ b/gaphor/ui/diagramtab.py @@ -31,11 +31,12 @@ class DiagramTab(object): #self.diagram.canvas.disconnect(self.__snap_to_grid_id) self.diagram = diagram if diagram: + log.info('set diagram') diagram.canvas.set_property ('allow_undo', 1) diagram.connect(('name', '__unlink__'), self.__on_diagram_event) - self.__undo_id = diagram.canvas.connect('undo', self.__on_diagram_undo) + self.__undo_id = diagram.canvas.undo_manager.connect('begin_transaction', self.__on_diagram_undo) # Set capabilities: - self.__on_diagram_undo(diagram.canvas) + self.__on_diagram_undo(diagram.canvas.undo_manager) def construct(self): title = self.diagram and self.diagram.name or '' @@ -93,8 +94,8 @@ class DiagramTab(object): # handle mouse button 3 (popup menu): if event.type == gtk.gdk.BUTTON_PRESS: # First push the undo stack... - view.canvas.push_undo(None) - + #view.canvas.push_undo(None) + pass if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: vitem = view.focus_item if vitem: @@ -115,7 +116,8 @@ class DiagramTab(object): def __on_view_notify_tool(self, view, pspec): self.owning_window.execute_action('ToolChange') - def __on_diagram_undo(self, canvas): + def __on_diagram_undo(self, undo_manager): + log.info('set undo stack %s' % (undo_manager)) self.owning_window.execute_action('EditUndoStack') def __on_diagram_event(self, element, pspec): diff --git a/gaphor/ui/diagramwindow.py b/gaphor/ui/diagramwindow.py index 042ca7b98..eaa65c80b 100644 --- a/gaphor/ui/diagramwindow.py +++ b/gaphor/ui/diagramwindow.py @@ -81,9 +81,10 @@ class DiagramWindow(AbstractWindow): self.get_window().set_title(diagram.name or 'NoName') self.view.set_diagram(diagram) if diagram: + log.info('setting diagram') diagram.canvas.set_property ('allow_undo', 1) diagram.connect(('name', '__unlink__'), self.__on_diagram_event) - self.__undo_id = diagram.canvas.connect('undo', self.__on_diagram_undo) + self.__undo_id = diagram.canvas.undo_manager.connect('begin_transaction', self.__on_diagram_undo) #self.__snap_to_grid_id = diagram.canvas.connect('notify::snap-to-grid', self.__on_diagram_notify_snap_to_grid) # Set capabilities: self.__on_diagram_undo(diagram.canvas) @@ -151,7 +152,8 @@ class DiagramWindow(AbstractWindow): # handle mouse button 3 (popup menu): if event.type == gtk.gdk.BUTTON_PRESS: # First push the undo stack... - view.canvas.push_undo(None) + #view.canvas.push_undo(None) + pass if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: vitem = view.focus_item @@ -171,6 +173,7 @@ class DiagramWindow(AbstractWindow): #self.set_capability('select', len (view.selected_items) > 0) def __on_diagram_undo(self, canvas): + log.info ('diagram undo') self.execute_action('EditUndoStack') # self.set_capability('undo', canvas.get_undo_depth() > 0) # self.set_capability('redo', canvas.get_redo_depth() > 0) diff --git a/setup.py b/setup.py index 6703bd3e4..5e5346452 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ class config_Gaphor(Command): self.module_check('gnome') self.module_check('gnome.canvas') #self.module_check('gconf') - self.module_check('diacanvas', ('diacanvas_version', (0, 13, 0))) + self.module_check('diacanvas', ('diacanvas_version', (0, 14, 0))) print '' if self.config_failed: