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
This commit is contained in:
Bo Peng 2007-10-11 15:14:11 +00:00
parent c37b495ca0
commit 4ed5939d2e
4 changed files with 58 additions and 1 deletions

View 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;

View 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;

View 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);

View 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
};
///