diff --git a/frontends/src/quick_frontend/quick_menus.py b/frontends/src/quick_frontend/quick_menus.py index 80c1f61f..e8fa89a1 100644 --- a/frontends/src/quick_frontend/quick_menus.py +++ b/frontends/src/quick_frontend/quick_menus.py @@ -219,7 +219,16 @@ class MenuContainer(MenuBase): yield child def append(self, item): + """add an item at the end of current ones + + @param item: instance of MenuBase (must be unique in container) + """ assert isinstance(item, MenuItem) or isinstance(item, MenuContainer) + assert item.canonical not in self._items + self._items[item.canonical] = item + + def replace(self, item): + """add an item at the end of current ones or replace an existing one""" self._items[item.canonical] = item @@ -391,6 +400,23 @@ class QuickMenusManager(object): else: self.addMenu(type_, path, path_i18n, id_=id_, extra=extra, top_extra=top_extra) + def addMenuHook(self, type_, path, path_i18n=None, extra=None, top_extra=None, callback=None): + """Helper method to add a menu hook + + Menu hooks are local menus which override menu given by backend + @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] + @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] + @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation + @param extra(dict[unicode, unicode], None): same as in [addMenus] + @param top_extra: same as in [_createCategories] + @param callback(callable): local callback (mutually exclusive with id_) + """ + if path_i18n is None: + path_i18n = self._getPathI18n(path) + menu_item = MenuHook(type_, path[-1], path_i18n[-1], callback=callback, extra=extra) + self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra) + log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_)) + def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None): """Create a category with all parents, and set extra on the last one