[alacarte] Allow specifying a menu basename other than applications.menu



commit e65fd3456817e9f7735a52941c5d6b787a1d030d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 10 16:43:23 2013 -0500

    Allow specifying a menu basename other than applications.menu
    
    Users may want to edit menus other than 'applications.menu'. Allow
    them to pass an argument on the command line that specifies the menu
    basename.

 Alacarte/MainWindow.py |    4 ++--
 Alacarte/MenuEditor.py |   10 +++++++---
 alacarte.in            |    8 +++++++-
 3 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py
index df602cf..638ef06 100644
--- a/Alacarte/MainWindow.py
+++ b/Alacarte/MainWindow.py
@@ -37,10 +37,10 @@ class MainWindow(object):
     #hack to make editing menu properties work
     edit_pool = []
 
-    def __init__(self, datadir, version):
+    def __init__(self, menu_basename, datadir, version):
         self.file_path = datadir
         self.version = version
-        self.editor = MenuEditor()
+        self.editor = MenuEditor(menu_basename)
         self.editor.tree.connect("changed", self.menuChanged)
         Gtk.Window.set_default_icon_name('alacarte')
         self.tree = Gtk.Builder()
diff --git a/Alacarte/MenuEditor.py b/Alacarte/MenuEditor.py
index 1d39f95..181866f 100644
--- a/Alacarte/MenuEditor.py
+++ b/Alacarte/MenuEditor.py
@@ -23,11 +23,15 @@ import xml.parsers.expat
 from gi.repository import GMenu, GLib
 from Alacarte import util
 
+def get_default_menu():
+    prefix = os.environ.get('XDG_MENU_PREFIX', '')
+    return prefix + 'applications.menu'
+
 class MenuEditor(object):
-    def __init__(self, name=os.environ.get('XDG_MENU_PREFIX', '') + 'applications.menu'):
-        self.name = name
+    def __init__(self, basename=None):
+        basename = basename or get_default_menu()
 
-        self.tree = GMenu.Tree.new(name, GMenu.TreeFlags.SHOW_EMPTY|GMenu.TreeFlags.INCLUDE_EXCLUDED|GMenu.TreeFlags.INCLUDE_NODISPLAY|GMenu.TreeFlags.SHOW_ALL_SEPARATORS|GMenu.TreeFlags.SORT_DISPLAY_NAME)
+        self.tree = GMenu.Tree.new(basename, GMenu.TreeFlags.SHOW_EMPTY|GMenu.TreeFlags.INCLUDE_EXCLUDED|GMenu.TreeFlags.INCLUDE_NODISPLAY|GMenu.TreeFlags.SHOW_ALL_SEPARATORS|GMenu.TreeFlags.SORT_DISPLAY_NAME)
         self.tree.connect('changed', self.menuChanged)
         self.load()
 
diff --git a/alacarte.in b/alacarte.in
index d8443b4..5aa1dd0 100644
--- a/alacarte.in
+++ b/alacarte.in
@@ -21,6 +21,12 @@
 import sys
 from Alacarte.MainWindow import MainWindow
 
+def get_menu_basename():
+    if len(sys.argv) > 1:
+        return sys.argv[1]
+    else:
+        return None
+
 def main():
     try:
         from Alacarte import config
@@ -29,7 +35,7 @@ def main():
     except ImportError:
         datadir = '.'
         version = '0.9'
-    app = MainWindow(datadir, version)
+    app = MainWindow(get_menu_basename(), datadir, version)
     app.run()
 
 if __name__ == '__main__':



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