[jokosher-devel] [PATCH] Added button to revert to previously saved version (bug #85941)



Hello,

I added a button in the menu that reverts the project back to the previously saved version.
This is done by executing all the actions in the undo stack.

Regards,
Knut Erik Teigen
Index: Jokosher.glade
===================================================================
--- Jokosher.glade	(revision 1462)
+++ Jokosher.glade	(working copy)
@@ -129,6 +129,16 @@
 		  </child>
 
 		  <child>
+		    <widget class="GtkImageMenuItem" id="revert">
+  		      <property name="visible">True</property>
+  		      <property name="tooltip" translatable="yes">Revert to a saved version of the project</property>
+                      <property name="label">gtk-revert-to-saved</property>
+		      <property name="use_stock">True</property>
+		      <signal name="activate" handler="on_revert_activate"/>
+		    </widget>
+		  </child>
+
+		  <child>
 		    <widget class="GtkImageMenuItem" id="close">
 		      <property name="visible">True</property>
 		      <property name="tooltip" translatable="yes">Close the current project</property>
Index: Project.py
===================================================================
--- Project.py	(revision 1462)
+++ Project.py	(working copy)
@@ -814,7 +814,23 @@
 			len(self.__savedRedoStack) > 0
 	
 	#_____________________________________________________________________
-	
+
+        def Revert(self):
+                """
+                Empties the undo stack.
+                """
+
+	        self.__performingUndo = True
+		
+                while len(self.__undoStack):
+                        cmd = self.__undoStack.pop()
+                        self.ExecuteAction(cmd)
+
+                self.__performingUndo = False
+
+
+	#_____________________________________________________________________
+
 	def CanPerformUndo(self):
 		"""
 		Whether it's possible to perform an undo operation.
Index: JokosherApp.py
===================================================================
--- JokosherApp.py	(revision 1462)
+++ JokosherApp.py	(working copy)
@@ -88,6 +88,7 @@
 			"on_open_activate" : self.OnOpenProject,
 			"on_save_activate" : self.OnSaveProject,
 			"on_save_as_activate" : self.OnSaveAsProject,
+			"on_revert_activate" : self.OnRevertProject,
 			"on_new_activate" : self.OnNewProject,
 			"on_close_activate" : self.OnCloseProject,
 			"on_show_as_bars_beats_ticks_toggled" : self.OnShowBarsBeats,
@@ -122,6 +123,7 @@
 		self.record = self.wTree.get_widget("Record")
 		self.save = self.wTree.get_widget("save")
 		self.save_as = self.wTree.get_widget("save_as")
+		self.revert = self.wTree.get_widget("revert")
 		self.close = self.wTree.get_widget("close")
 		self.reverse = self.wTree.get_widget("Rewind")
 		self.forward = self.wTree.get_widget("Forward")
@@ -800,6 +802,52 @@
 		
 	#_____________________________________________________________________
 
+	def OnRevertProject(self, widget=None):
+		"""
+		Creates and shows a dialog which allows the user to revert
+		the current project to the previously saved version.
+		
+		Parameters:
+			widget -- reserved for GTK callbacks, don't use it explicitly.
+		"""
+
+                message = _("<span size='large' weight='bold'>Revert unsaved changes to project \"%s\"?</span>\n\nChanges made to the project will be permanently lost.") % self.project.name
+                
+                dlg = gtk.MessageDialog(self.window,
+                        gtk.DIALOG_MODAL |
+                        gtk.DIALOG_DESTROY_WITH_PARENT,
+                        gtk.MESSAGE_QUESTION,
+                        gtk.BUTTONS_NONE)
+                dlg.set_markup(message)
+                
+                dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+                defaultAction = dlg.add_button(gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_YES)
+                dlg.set_default(defaultAction)
+                
+                dlg.set_transient_for(self.window)
+                
+                response = dlg.run()
+                dlg.destroy()
+                if response == gtk.RESPONSE_YES:
+                        # Reverts by emptying the undoStack
+                        self.project.Revert()
+
+                        
+                        # Reverts by closing the project and reopening it
+# 
+#                         path = self.project.projectfile
+# 
+#                         self.Stop()
+#                         self.project.CloseProject()
+#                         self.project = None
+#                         self.mode = None
+# 
+#                         self.OpenProjectFromPath(path)
+                elif response == gtk.RESPONSE_CANCEL or response == gtk.RESPONSE_DELETE_EVENT:
+                        pass 
+
+	#_____________________________________________________________________
+
 	def OnNewProject(self, widget, destroyCallback=None):
 		"""
 		Creates and shows the "New Project" dialog.
@@ -1278,7 +1326,7 @@
 		if self.tvtoolitem in self.toolbar.get_children():
 			self.toolbar.remove(self.tvtoolitem)
 		
-		ctrls = (self.save, self.save_as, self.close, self.addInstrumentButton, self.addAudioFileButton,
+		ctrls = (self.save, self.save_as, self.revert, self.close, self.addInstrumentButton, self.addAudioFileButton,
 			self.reverse, self.forward, self.play, self.stop, self.record,
 			self.projectMenu, self.instrumentMenu, self.export, self.cut, self.copy, self.paste,
 			self.undo, self.redo, self.delete, self.compactMixButton)
@@ -1383,11 +1431,19 @@
 	def OnFileMenu(self, widget):
 		"""
 		When the file menu opens, check if there are any events and set the mixdown project menu item's
-		sensitivity accordingly and also the 'mixdown as' sensitivity.
-		
+		sensitivity accordingly and also the 'mixdown as' sensitivity. Also set the revert sensitivity
+                according to unsaved project changes
+
 		Parameters:
 			widget -- reserved for GTK callbacks, don't use it explicitly.
 		"""
+
+		revertable = False
+                if self.project:
+                        if self.project.CheckUnsavedChanges():
+                                revertable = True
+                self.revert.set_sensitive(revertable)
+
 		self.PopulateMixdownAsMenu()
 		if self.isRecording:
 			self.export.set_sensitive(False)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]