X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FMenuBackend.cpp;h=05aa0b461de1e5833d62a5567ca3ff43d18f251b;hb=0362c6aae73c293d1c20277c12d362acfe0b2ef6;hp=a36691271e2e88565fe8d322ede07721a0b3cc47;hpb=ee005614a356f5b7906bfe8e0e3839c6ef8db698;p=lyx.git diff --git a/src/MenuBackend.cpp b/src/MenuBackend.cpp index a36691271e..05aa0b461d 100644 --- a/src/MenuBackend.cpp +++ b/src/MenuBackend.cpp @@ -21,13 +21,11 @@ #include "Buffer.h" #include "BufferList.h" #include "BufferParams.h" +#include "Converter.h" #include "CutAndPaste.h" -#include "debug.h" #include "Floating.h" #include "FloatList.h" #include "Format.h" -#include "gettext.h" -#include "Importer.h" #include "KeyMap.h" #include "Session.h" #include "LyXAction.h" @@ -35,45 +33,36 @@ #include "LyXFunc.h" #include "Lexer.h" #include "Paragraph.h" +#include "TextClass.h" #include "TocBackend.h" #include "ToolbarBackend.h" +#include "frontends/Application.h" + +#include "support/convert.h" +#include "support/debug.h" #include "support/filetools.h" +#include "support/gettext.h" #include "support/lstrings.h" -#include "support/convert.h" #include #include +#include - -namespace lyx { - -using support::compare_ascii_no_case; -using support::contains; -using support::makeDisplayPath; -using support::token; - +using namespace std; using boost::bind; +using namespace lyx::support; -using std::auto_ptr; -using std::endl; -using std::equal_to; -using std::find_if; -using std::max; -using std::sort; -using std::string; -using std::vector; -using std::stack; +namespace lyx { namespace { -class MenuNamesEqual : public std::unary_function { +class MenuNamesEqual : public unary_function { public: MenuNamesEqual(docstring const & name) : name_(name) {} - bool operator()(Menu const & menu) const - { + bool operator()(Menu const & menu) const { return menu.name() == name_; } private: @@ -83,10 +72,6 @@ private: } // namespace anon -// This is the global menu definition -MenuBackend menubackend; - - MenuItem::MenuItem(Kind kind) : kind_(kind), optional_(false) {} @@ -131,25 +116,22 @@ docstring const MenuItem::shortcut() const } -docstring const MenuItem::binding(bool forgui) const +docstring const MenuItem::binding() const { if (kind_ != Command) return docstring(); // Get the keys bound to this action, but keep only the // first one later - KeyMap::Bindings bindings = theTopLevelKeymap().findbindings(func_); + KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_); - if (bindings.size()) { - return bindings.begin()->print(forgui); - } else { - LYXERR(Debug::KBMAP) - << "No binding for " - << lyxaction.getActionName(func_.action) - << '(' << to_utf8(func_.argument()) << ')' << endl; - return docstring(); - } + if (bindings.size()) + return bindings.begin()->print(KeySequence::ForGui); + LYXERR(Debug::KBMAP, "No binding for " + << lyxaction.getActionName(func_.action) + << '(' << to_utf8(func_.argument()) << ')'); + return docstring(); } @@ -391,7 +373,7 @@ MenuItem const & Menu::operator[](size_type i) const bool Menu::hasFunc(FuncRequest const & func) const { return find_if(begin(), end(), - bind(std::equal_to(), + bind(equal_to(), bind(&MenuItem::func, _1), func)) != end(); } @@ -422,7 +404,7 @@ void Menu::checkShortcuts() const } -bool Menu::searchFunc(FuncRequest & func, stack & names) +bool Menu::searchFunc(FuncRequest & func, stack & names) const { const_iterator m = begin(); const_iterator m_end = end(); @@ -432,7 +414,7 @@ bool Menu::searchFunc(FuncRequest & func, stack & names) return true; } else if (m->kind() == MenuItem::Submenu) { names.push(m->label()); - Menu submenu = menubackend.getMenu(m->submenuname()); + Menu submenu = theApp()->menuBackend().getMenu(m->submenuname()); if (submenu.searchFunc(func, names)) return true; else @@ -495,8 +477,9 @@ void expandDocuments(Menu & tomenu) // We cannot use a for loop as the buffer list cycles. do { - docstring label = makeDisplayPath(b->absFileName(), 20); - if (!b->isClean()) label = label + "*"; + docstring label = b->fileName().displayName(20); + if (!b->isClean()) + label = label + "*"; if (ii < 10) label = convert(ii) + ". " + label + '|' + convert(ii); tomenu.add(MenuItem(MenuItem::Command, label, @@ -508,7 +491,6 @@ void expandDocuments(Menu & tomenu) } else { tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"), FuncRequest(LFUN_NOACTION))); - return; } } @@ -544,7 +526,7 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) switch (kind) { case MenuItem::ImportFormats: - formats = Importer::GetImportableFormats(); + formats = theConverters().importableFormats(); action = LFUN_BUFFER_IMPORT; break; case MenuItem::ViewFormats: @@ -567,6 +549,7 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) if ((*fit)->dummy()) continue; docstring label = from_utf8((*fit)->prettyname()); + docstring const shortcut = from_utf8((*fit)->shortcut()); switch (kind) { case MenuItem::ImportFormats: @@ -588,8 +571,13 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) BOOST_ASSERT(false); break; } - if (!(*fit)->shortcut().empty()) - label += char_type('|') + from_utf8((*fit)->shortcut()); + // FIXME: if we had proper support for translating the + // format names defined in configure.py, there would + // not be a need to check whether the shortcut is + // correct. If we add it uncondiitonally, it would + // create useless warnings on bad shortcuts + if (!shortcut.empty() && contains(label, shortcut)) + label += char_type('|') + shortcut; if (buf) tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label, @@ -611,7 +599,7 @@ void expandFloatListInsert(Menu & tomenu, Buffer const * buf) } FloatList const & floats = - buf->params().getTextClass().floats(); + buf->params().textClass().floats(); FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { @@ -633,7 +621,7 @@ void expandFloatInsert(Menu & tomenu, Buffer const * buf) } FloatList const & floats = - buf->params().getTextClass().floats(); + buf->params().textClass().floats(); FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator end = floats.end(); for (; cit != end; ++cit) { @@ -646,7 +634,7 @@ void expandFloatInsert(Menu & tomenu, Buffer const * buf) } -void expandFlexInsert(Menu & tomenu, Buffer const * buf, std::string s) +void expandFlexInsert(Menu & tomenu, Buffer const * buf, string s) { if (!buf) { tomenu.add(MenuItem(MenuItem::Command, @@ -654,13 +642,13 @@ void expandFlexInsert(Menu & tomenu, Buffer const * buf, std::string s) FuncRequest(LFUN_NOACTION))); return; } - InsetLayouts const & insetlayouts = - buf->params().getTextClass().insetlayouts(); - InsetLayouts::const_iterator cit = insetlayouts.begin(); - InsetLayouts::const_iterator end = insetlayouts.end(); + InsetLayouts const & insetLayouts = + buf->params().textClass().insetLayouts(); + InsetLayouts::const_iterator cit = insetLayouts.begin(); + InsetLayouts::const_iterator end = insetLayouts.end(); for (; cit != end; ++cit) { docstring const label = cit->first; - if (cit->second.lyxtype == s) + if (cit->second.lyxtype() == s) tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FLEX_INSERT, label))); @@ -680,7 +668,7 @@ void expandToc2(Menu & tomenu, // check whether depth is smaller than the smallest depth in toc. int min_depth = 1000; for (Toc::size_type i = from; i < to; ++i) - min_depth = std::min(min_depth, toc_list[i].depth()); + min_depth = min(min_depth, toc_list[i].depth()); if (min_depth > depth) depth = min_depth; @@ -755,7 +743,7 @@ void expandToc(Menu & tomenu, Buffer const * buf) tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f)); } - FloatList const & floatlist = buf->params().getTextClass().floats(); + FloatList const & floatlist = buf->params().textClass().floats(); TocList const & toc_list = buf->tocBackend().tocs(); TocList::const_iterator cit = toc_list.begin(); TocList::const_iterator end = toc_list.end(); @@ -780,8 +768,18 @@ void expandToc(Menu & tomenu, Buffer const * buf) label = _(floatName); // BUG3633: listings is not a proper float so its name // is not shown in floatlist. + else if (cit->first == "equation") + label = _("List of Equations"); + else if (cit->first == "index") + label = _("List of Indexes"); else if (cit->first == "listing") - label = _("List of listings"); + label = _("List of Listings"); + else if (cit->first == "marginalnote") + label = _("List of Marginal notes"); + else if (cit->first == "note") + label = _("List of Notes"); + else if (cit->first == "footnote") + label = _("List of Foot notes"); // this should not happen now, but if something else like // listings is added later, this can avoid an empty menu name. else