diff options
author | gm10 <[email protected]> | 2019-08-11 17:08:21 +0200 |
---|---|---|
committer | lukefromdc <[email protected]> | 2019-08-13 05:29:18 +0000 |
commit | 97f20dd25831da690d98c5a6ad05856a22edb411 (patch) | |
tree | 1bcc2faf24ac47f05fbe335e2ccc75e9516d9d32 | |
parent | 65283e661834a7282cac64b0c3442218bca1d618 (diff) | |
download | mozo-97f20dd25831da690d98c5a6ad05856a22edb411.tar.bz2 mozo-97f20dd25831da690d98c5a6ad05856a22edb411.tar.xz |
Add Undo and Redo buttons
-rw-r--r-- | Mozo/MainWindow.py | 9 | ||||
-rw-r--r-- | Mozo/MenuEditor.py | 14 | ||||
-rw-r--r-- | data/mozo.ui | 47 |
3 files changed, 63 insertions, 7 deletions
diff --git a/Mozo/MainWindow.py b/Mozo/MainWindow.py index 19635f5..23db1bd 100644 --- a/Mozo/MainWindow.py +++ b/Mozo/MainWindow.py @@ -53,11 +53,12 @@ class MainWindow: def __init__(self, datadir, version, argv): self.file_path = datadir self.version = version - self.editor = MenuEditor() Gtk.Window.set_default_icon_name('mozo') self.tree = Gtk.Builder() self.tree.set_translation_domain(GETTEXT_PACKAGE) self.tree.add_from_file(os.path.join(self.file_path, 'mozo.ui')) + self.editor = MenuEditor(undo_button=self.tree.get_object('undo_button'), + redo_button=self.tree.get_object('redo_button')) self.tree.connect_signals(self) self.setupMenuTree() self.setupItemTree() @@ -617,13 +618,13 @@ class MainWindow: elif isinstance(item, MateMenu.TreeSeparator): self.editor.moveSeparator(item, item.get_parent(), after=after) - def on_mainwindow_undo(self, accelgroup, window, keyval, modifier): + def on_mainwindow_undo(self, *_args): self.editor.undo() - def on_mainwindow_redo(self, accelgroup, window, keyval, modifier): + def on_mainwindow_redo(self, *_args): self.editor.redo() - def on_help_button_clicked(self, *args): + def on_help_button_clicked(self, *_args): Gtk.show_uri(Gdk.Screen.get_default(), "help:mate-user-guide/menu-editor", Gtk.get_current_event_time()) def on_revert_button_clicked(self, button): diff --git a/Mozo/MenuEditor.py b/Mozo/MenuEditor.py index 738456f..b218eb5 100644 --- a/Mozo/MenuEditor.py +++ b/Mozo/MenuEditor.py @@ -33,7 +33,10 @@ class Menu: dom = None class MenuEditor(object): - def __init__(self): + + def __init__(self, undo_button, redo_button): + self.undo_button = undo_button + self.redo_button = redo_button self.locale = locale.getdefaultlocale()[0] self.__undo = [] self.__redo = [] @@ -52,6 +55,7 @@ class MenuEditor(object): self.settings.tree.connect('changed', self.menuChanged) self.load() self.__loadMenus() + self.update_undo_redo_button_state() def __loadMenus(self): self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.props.menu_basename) @@ -121,6 +125,7 @@ class MenuEditor(object): util.removeWhitespaceNodes(menu.dom) #reset undo/redo, no way to recover from this self.__undo, self.__redo = [], [] + self.update_undo_redo_button_state() self.save() def revertTree(self, menu): @@ -161,6 +166,10 @@ class MenuEditor(object): pass self.save() + def update_undo_redo_button_state(self): + self.redo_button.set_sensitive(len(self.__redo) > 0) + self.undo_button.set_sensitive(len(self.__undo) > 0) + def undo(self): if len(self.__undo) == 0: return @@ -200,6 +209,7 @@ class MenuEditor(object): util.removeWhitespaceNodes(menu.dom) if redo: self.__redo.append(redo) + self.update_undo_redo_button_state() def redo(self): if len(self.__redo) == 0: @@ -240,6 +250,7 @@ class MenuEditor(object): util.removeWhitespaceNodes(menu.dom) if undo: self.__undo.append(undo) + self.update_undo_redo_button_state() def getMenus(self, parent=None): if parent is None: @@ -520,6 +531,7 @@ class MenuEditor(object): with codecs.open(undo_path, 'w', 'utf-8') as f: f.write(data) self.__undo[-1].append(undo_path) + self.update_undo_redo_button_state() def __getMenu(self, item): root = item.get_parent() diff --git a/data/mozo.ui b/data/mozo.ui index d441dbb..72dfea0 100644 --- a/data/mozo.ui +++ b/data/mozo.ui @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> <interface> <requires lib="gtk+" version="3.14"/> <object class="GtkUIManager" id="uimanager1"> @@ -53,6 +54,9 @@ <signal name="delete-event" handler="on_delete_event" swapped="no"/> <signal name="destroy" handler="on_close_button_clicked" swapped="no"/> <signal name="style-updated" handler="on_style_updated" swapped="no"/> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox5"> <property name="visible">True</property> @@ -80,6 +84,40 @@ </packing> </child> <child> + <object class="GtkButton" id="undo_button"> + <property name="label">gtk-undo</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="on_mainwindow_undo" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="redo_button"> + <property name="label">gtk-redo</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="on_mainwindow_redo" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> <object class="GtkButton" id="revert_button"> <property name="label">gtk-revert-to-saved</property> <property name="visible">True</property> @@ -93,7 +131,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">1</property> + <property name="position">3</property> </packing> </child> <child> @@ -110,7 +148,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">2</property> + <property name="position">4</property> </packing> </child> </object> @@ -584,6 +622,8 @@ </child> <action-widgets> <action-widget response="-11">help_button</action-widget> + <action-widget response="1">undo_button</action-widget> + <action-widget response="2">redo_button</action-widget> <action-widget response="0">revert_button</action-widget> <action-widget response="-7">close_button</action-widget> </action-widgets> @@ -595,6 +635,9 @@ <property name="title" translatable="yes">Revert Changes?</property> <property name="resizable">False</property> <property name="type_hint">dialog</property> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox6"> <property name="visible">True</property> |