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 @@
+
+ True
+ Revert to a saved version of the project
+ gtk-revert-to-saved
+ True
+
+
+
+
+
True
Close the current project
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 = _("Revert unsaved changes to project \"%s\"?\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):
"