mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
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:
parent
c37b495ca0
commit
4ed5939d2e
@ -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;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -192,6 +193,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;
|
||||
///
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user