changeset 1338:d0e6f350b3fd

Clear change log to prevent from undo/redo. - commit the transaction after changing DOM-tree. - prevent SPObject document from adding changes into the log of undo/redo. - If a changes is not in the log of undo/redo, it would not be redo.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 05 Feb 2011 18:08:57 +0800
parents 05ced4a389bf
children 20cf3e2a0a9d
files pyink/MBScene.py pyink/comp_dock.py
diffstat 2 files changed, 31 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sat Feb 05 13:46:07 2011 +0800
+++ b/pyink/MBScene.py	Sat Feb 05 18:08:57 2011 +0800
@@ -176,11 +176,9 @@
 	self._director.show_scene(frame_idx)
 	pass
 
-    def markUndo(self, msg):
-	#self._domviewui.mark_undo(msg)
-	# FIXME: move into domview latter when the inkscpae-pybind is modified
-	#        to support the sp_document_done.
-	self.desktop.doc().done("None",msg)
+    def _drop_undo(self):
+	self.document.commit()	# commit the transation and drop change log.
+	self.document.beginTransaction()
     
     def addNameEditor(self,hbox):
 	self.nameEditor = gtk.Entry(max=40)
@@ -240,23 +238,23 @@
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
 	self.insertKeyScene(layer_idx, frame_idx)
 	self.selectSceneObject(layer_idx, frame_idx)
-	self.markUndo("insert key")
+	self._drop_undo()
 	return
     
     def doDuplicateKeyScene(self,w):
         self.duplicateKeyScene()
-	self.markUndo("dup key")
+	self._drop_undo()
 	pass
 
     def doRemoveScene(self,w):
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
 	self.removeKeyScene(layer_idx, frame_idx)
-	self.markUndo("remove key")
+	self._drop_undo()
 	return
 
     def doExtendScene(self,w):
 	self.extendScene()
-	self.markUndo("extend key")
+	self._drop_undo()
 	pass
 
     def doRun(self,arg):
@@ -302,12 +300,12 @@
     def doInsertFrame(self, w):
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
 	self._domviewui.insert_frames(layer_idx, frame_idx, 1)
-	self.markUndo("insert frame")
+	self._drop_undo()
 
     def doRemoveFrame(self, w):
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
 	self._domviewui.rm_frames(layer_idx, frame_idx, 1)
-	self.markUndo("remove frame")
+	self._drop_undo()
 
     def do_TweenTypeChange(self, w):
 	if self._disable_tween_type_selector:
@@ -322,7 +320,7 @@
 	    # Length of tween > 1 and cover this frame
 	    self._domviewui.chg_tween(layer_idx, start, tween_type=tween_type)
 	    pass
-	self.markUndo("change type")
+	self._drop_undo()
 	pass
     
     def onQuit(self, event):
@@ -402,7 +400,8 @@
 	self.top.show_all()
 	self.last_update = None
 	
-	self.markUndo("Initialize")
+	self._drop_undo()
+	
 	return False
 
     ## \brief To handle context menu event.
--- a/pyink/comp_dock.py	Sat Feb 05 13:46:07 2011 +0800
+++ b/pyink/comp_dock.py	Sat Feb 05 18:08:57 2011 +0800
@@ -1,6 +1,7 @@
 import gtk
 import os
 import data_monitor
+import pybInkscape
 
 
 ## \brief User interface for management components and their timelines.
@@ -145,6 +146,7 @@
         raise ValueError, 'unknown component name - %s' % (name)
     pass
 
+
 ## \brief UI interactive handlers
 #
 # A mix-in to handle UI events.
@@ -159,6 +161,11 @@
         self._locker = domview_ui
         pass
 
+    def _drop_undo(self):
+        self._doc.commit()
+        self._doc.beginTransaction()
+        pass
+
     ## \brief Start handle UI events.
     #
     def start_handle_ui_events(self):
@@ -166,8 +173,7 @@
         pass
 
     def install_dock(self, desktop):
-        doc = desktop.doc()
-        doc.connectCommit(self.on_commit)
+        self._doc = desktop.doc().rdoc
         pass
     
     def _current_component(self):
@@ -271,14 +277,12 @@
     
     def on_add_comp_clicked(self, *args):
         self._add_component()
-        self._desktop.doc().done("None",
-                                 "Add a new component")
+        self._drop_undo()
         pass
 
     def on_remove_comp_clicked(self, *args):
         self._rm_component()
-        self._desktop.doc().done("None",
-                                 "Remove a component")
+        self._drop_undo()
         pass
 
     def on_treeview_components_button_press_event(self, widget, event, *args):
@@ -293,8 +297,7 @@
 
     def on_treeview_components_row_activated(self, *args):
         self._switch_component()
-        self._desktop.doc().done("None",
-                                 "Switch to another component")
+        self._drop_undo()
         pass
     
     ## \brief Handle of changing component name.
@@ -311,8 +314,7 @@
 
         self._domview_ui.rename_component(old_name, new_text)
         
-        self._desktop.doc().done("None",
-                                 "Change name of a component")
+        self._drop_undo()
         pass
 
     def on_rename_component_activate(self, *args):
@@ -335,26 +337,22 @@
         
         self._domview_ui.link_to_component(comp_name, cur_layer_group)
         
-        self._desktop.doc().done("None",
-                                 "Make a xlink of a component")
+        self._drop_undo()
         pass
     
     def on_switch_component_activate(self, *args):
         self._switch_component()
-        self._desktop.doc().done("None",
-                                 "Switch to another component")
+        self._drop_undo()
         pass
     
     def on_add_timeline_clicked(self, *args):
         self._add_timeline()
-        self._desktop.doc().done("None",
-                                 "Add a timeline")
+        self._drop_undo()
         pass
 
     def on_remove_timeline_clicked(self, *args):
         self._rm_timeline()
-        self._desktop.doc().done("None",
-                                 "Remove a timeline")
+        self._drop_undo()
         pass
 
     def on_treeview_timelines_button_press_event(self, widget, event, *args):
@@ -369,8 +367,7 @@
 
     def on_treeview_timelines_row_activated(self, *args):
         self._switch_timeline()
-        self._desktop.doc().done("None",
-                                 "Switch to another timeline")
+        self._drop_undo()
         pass
 
     def on_cellrenderer_timelines_edited(self, renderer, path,
@@ -385,8 +382,7 @@
         
         self._domview_ui.rename_timeline(old_name, new_text)
         
-        self._desktop.doc().done("None",
-                                 "Change name of a timeline")
+        self._drop_undo()
         pass
     
     def on_rename_timeline_activate(self, *args):
@@ -402,12 +398,7 @@
     
     def on_switch_timeline_activate(self, *args):
         self._switch_timeline()
-        self._desktop.doc().done("None",
-                                 "Switch to another timeline")
-        pass
-
-    def on_commit(self):
-        print 'commit'
+        self._drop_undo()
         pass
     pass