From c9da62fb08e682204018dcd7d679ec0bc563489a Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Mon, 29 Nov 2010 23:15:31 +0000 Subject: [PATCH] Implement the possibility of concatenating (context) menus. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36605 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Menus.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 9894efe510..309f2156da 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -298,6 +298,8 @@ public: const_iterator begin() const { return items_.begin(); } /// const_iterator end() const { return items_.end(); } + /// + void cat(MenuDefinition const & other); // search for func in this menu iteratively, and put menu // names in a stack. @@ -641,6 +643,14 @@ bool MenuDefinition::hasFunc(FuncRequest const & func) const } +void MenuDefinition::cat(MenuDefinition const & other) +{ + const_iterator et = other.end(); + for (const_iterator it = other.begin(); it != et; ++it) + add(*it); +} + + void MenuDefinition::checkShortcuts() const { // This is a quadratic algorithm, but we do not care because @@ -1976,14 +1986,27 @@ void Menus::updateMenu(Menu * qmenu) if (qmenu->d->name.isEmpty()) return; - if (!d->hasMenu(qmenu->d->name)) { + docstring identifier = qstring_to_ucs4(qmenu->d->name); + MenuDefinition fromLyxMenu(qmenu->d->name); + while (!identifier.empty()) { + docstring menu_name; + identifier = split(identifier, menu_name, ';'); + + if (!d->hasMenu(toqstr(menu_name))) { + LYXERR(Debug::GUI, "\tWARNING: non existing menu: " + << menu_name); + continue; + } + + fromLyxMenu.cat(d->getMenu(toqstr(menu_name))); + fromLyxMenu.add(MenuItem(MenuItem::Separator)); + } + + if (fromLyxMenu.empty()) { qmenu->addAction(qt_("No Action Defined!")); - LYXERR(Debug::GUI, "\tWARNING: non existing menu: " - << qmenu->d->name); return; } - MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name); BufferView * bv = 0; if (qmenu->d->view) bv = qmenu->d->view->currentBufferView();