summaryrefslogtreecommitdiff
path: root/Mozo
diff options
context:
space:
mode:
Diffstat (limited to 'Mozo')
-rw-r--r--Mozo/MainWindow.py9
-rw-r--r--Mozo/MenuEditor.py14
2 files changed, 18 insertions, 5 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()