Commit e65fd345 authored by Jasper St. Pierre's avatar Jasper St. Pierre
Browse files

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.
parent 075b8f0b
......@@ -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()
......
......@@ -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()
......
......@@ -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__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment