]> git.lyx.org Git - features.git/commitdiff
InsetInfo: add MENU_INFO (menu paste ==> Edit > Paste)
authorBo Peng <bpeng@lyx.org>
Thu, 11 Oct 2007 15:14:11 +0000 (15:14 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 11 Oct 2007 15:14:11 +0000 (15:14 +0000)
* 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

src/MenuBackend.cpp
src/MenuBackend.h
src/insets/InsetInfo.cpp
src/insets/InsetInfo.h

index fec705230dd64dddca6ce2f7518f36575a1abc3b..d4e0e2b7df9b55ce53c5cfefeae56cab4ce170fd 100644 (file)
@@ -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<docstring> & 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;
index bfb3833bf6eb06bbd9eeb759641afdf97170235c..c9f3e8de01e769dfb2f7e4b5414bd061eec980a1 100644 (file)
@@ -19,6 +19,7 @@
 #include <boost/shared_ptr.hpp>
 
 #include <vector>
+#include <stack>
 
 
 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<docstring> & names);
 
 private:
        friend class MenuBackend;
index 831a7a4b1a73efebd7d24872835c27446624b318..e82abc6747a3ece66adbf32f4848d081e4f23f47 100644 (file)
@@ -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<InsetInfo::info_type, string> 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<docstring> 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);
index 19821658aebad04b2628c6fee2e2dc1ecc2268b6..c7909e47394f9a429237c714fc7269ff8c08f262 100644 (file)
@@ -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
        };
 
        ///