From: Bo Peng Date: Thu, 11 Oct 2007 15:14:11 +0000 (+0000) Subject: InsetInfo: add MENU_INFO (menu paste ==> Edit > Paste) X-Git-Tag: 1.6.10~7885 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4ed5939d2e397629117eb7ab8e34024ca107b4ba;p=features.git InsetInfo: add MENU_INFO (menu paste ==> Edit > Paste) * src/insets/InsetInfo.h|cpp: handle MENU_INFO * src/MenuBackend.h|cpp: add searchFunc function git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20907 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/MenuBackend.cpp b/src/MenuBackend.cpp index fec705230d..d4e0e2b7df 100644 --- a/src/MenuBackend.cpp +++ b/src/MenuBackend.cpp @@ -65,7 +65,7 @@ using std::max; using std::sort; using std::string; using std::vector; - +using std::stack; namespace { @@ -423,6 +423,27 @@ void Menu::checkShortcuts() const } +bool Menu::searchFunc(FuncRequest & func, stack & names) +{ + const_iterator m = begin(); + const_iterator m_end = end(); + for (; m != m_end; ++m) { + if (m->kind() == MenuItem::Command && m->func() == func) { + names.push(m->label()); + return true; + } else if (m->kind() == MenuItem::Submenu) { + names.push(m->label()); + Menu submenu = menubackend.getMenu(m->submenuname()); + if (submenu.searchFunc(func, names)) + return true; + else + names.pop(); + } + } + return false; +} + + void MenuBackend::specialMenu(Menu const & menu) { specialmenu_ = menu; diff --git a/src/MenuBackend.h b/src/MenuBackend.h index bfb3833bf6..c9f3e8de01 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -19,6 +19,7 @@ #include #include +#include namespace lyx { @@ -191,6 +192,10 @@ public: // Check whether the menu shortcuts are unique void checkShortcuts() const; + + // search for func in this menu iteratively, and put menu + // names in a stack. + bool searchFunc(FuncRequest & func, std::stack & names); private: friend class MenuBackend; diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 831a7a4b1a..e82abc6747 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -24,6 +24,7 @@ #include "LaTeXFeatures.h" #include "LyXAction.h" #include "Lexer.h" +#include "MenuBackend.h" #include "MetricsInfo.h" #include "ParagraphParameters.h" #include "TextClassList.h" @@ -83,6 +84,7 @@ Translator const initTranslator() translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut"); translator.addPair(InsetInfo::PACKAGE_INFO, "package"); translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass"); + translator.addPair(InsetInfo::MENU_INFO, "menu"); return translator; } @@ -193,6 +195,34 @@ void InsetInfo::updateInfo() bp_.getFont(), false); break; } + case MENU_INFO: { + stack names; + FuncRequest func = lyxaction.lookupFunc(name_); + if (func.action == LFUN_UNKNOWN_ACTION) { + setText(_("No menu entry for "), bp_.getFont(), false); + break; + } + // iterate through the menubackend to find it + Menu menu = menubackend.getMenubar(); + if (!menu.searchFunc(func, names)) { + setText(_("No menu entry for "), bp_.getFont(), false); + break; + } + // if find, return its path. + InsetText::clear(); + Paragraph & info = paragraphs().front(); + unsigned int i = 0; + while (!names.empty()) { + // do not insert > for the top level menu item + if (i != 0) + info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR), + Change(Change::UNCHANGED)); + for (i = 0; i < names.top().length(); ++i) + info.insertChar(i, names.top()[i], bp_.getFont(), false); + names.pop(); + } + break; + } } // remove indent paragraphs().begin()->params().noindent(true); diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 19821658ae..c7909e4739 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -29,6 +29,7 @@ public: SHORTCUT_INFO, // Keyboard shortcut PACKAGE_INFO, // Availability of package TEXTCLASS_INFO, // Availability of textclass + MENU_INFO, // Which menu item is used for certain function }; ///