[alacarte] MainWindow: Refactor loadMenu
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [alacarte] MainWindow: Refactor loadMenu
- Date: Fri, 1 Jun 2012 06:10:08 +0000 (UTC)
commit ec28d8678ac091a6099ef94f6d8382f273bee9a0
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Jun 1 02:07:25 2012 -0400
MainWindow: Refactor loadMenu
This is a lot cleaner than the hardcoded depth mess we had before
Alacarte/MainWindow.py | 16 +++++-----------
Alacarte/MenuEditor.py | 26 ++++++++++++--------------
2 files changed, 17 insertions(+), 25 deletions(-)
---
diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py
index c091764..8fd4bd6 100644
--- a/Alacarte/MainWindow.py
+++ b/Alacarte/MainWindow.py
@@ -202,9 +202,8 @@ class MainWindow(object):
def loadMenus(self):
self.menu_store.clear()
- for menu in self.editor.getMenus():
- iters = [None]*20
- self.loadMenu(iters, menu)
+ self.loadMenu({ None: None })
+
menu_tree = self.tree.get_object('menu_tree')
menu_tree.set_model(self.menu_store)
for menu in self.menu_store:
@@ -212,20 +211,15 @@ class MainWindow(object):
menu_tree.get_selection().select_path((0,))
self.on_menu_tree_cursor_changed(menu_tree)
- def loadMenu(self, iters, parent, depth=0):
- if depth == 0:
- icon = util.getIcon(parent)
- iters[depth] = self.menu_store.append(None, (icon, cgi.escape(parent.get_name()), parent))
- depth += 1
+ def loadMenu(self, iters, parent=None):
for menu, show in self.editor.getMenus(parent):
name = cgi.escape(menu.get_name())
if not show:
name = "<small><i>%s</i></small>" % (name,)
icon = util.getIcon(menu)
- iters[depth] = self.menu_store.append(iters[depth-1], (icon, name, menu))
- self.loadMenu(iters, menu, depth)
- depth -= 1
+ iters[menu] = self.menu_store.append(iters[parent], (icon, name, menu))
+ self.loadMenu(iters, menu)
def loadItems(self, menu, menu_path):
self.item_store.clear()
diff --git a/Alacarte/MenuEditor.py b/Alacarte/MenuEditor.py
index 0f79a45..a20e615 100644
--- a/Alacarte/MenuEditor.py
+++ b/Alacarte/MenuEditor.py
@@ -108,15 +108,15 @@ class MenuEditor(object):
def getMenus(self, parent=None):
if parent is None:
- yield self.applications.tree.get_root_directory()
- else:
- item_iter = parent.iter()
+ parent = self.applications.tree.get_root_directory()
+
+ item_iter = parent.iter()
+ item_type = item_iter.next()
+ while item_type != GMenu.TreeItemType.INVALID:
+ if item_type == GMenu.TreeItemType.DIRECTORY:
+ item = item_iter.get_directory()
+ yield (item, self.isVisible(item))
item_type = item_iter.next()
- while item_type != GMenu.TreeItemType.INVALID:
- if item_type == GMenu.TreeItemType.DIRECTORY:
- item = item_iter.get_directory()
- yield (item, self.isVisible(item))
- item_type = item_iter.next()
def getContents(self, item):
contents = []
@@ -332,12 +332,10 @@ class MenuEditor(object):
self.addXmlLayout(menu_xml, layout, dom)
self.save()
- def findMenu(self, menu_id, parent=None):
- root_directory = self.applications.tree.get_root_directory()
- if parent is None and root_directory is not None:
- return self.findMenu(menu_id, root_directory)
- if menu_id == root_directory.get_menu_id():
- return root_directory
+ def findMenu(self, menu_id, parent):
+ if menu_id == parent.get_menu_id():
+ return parent
+
item_iter = parent.iter()
item_type = item_iter.next()
while item_type != GMenu.TreeItemType.INVALID:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]