X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FMenuBackend.C;h=5419f6d8b718fb8ffa923724cd6e2073d18e3481;hb=8765ab59cdddad67284007813ef25934ea0042ce;hp=7397fcee3498a54ecd0cb49966ec03e568491b4d;hpb=479e9054dbba9753a1a5e03e12ffab970caf4557;p=lyx.git diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 7397fcee34..5419f6d8b7 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -35,6 +35,7 @@ #include "lyx_main.h" // for lastfiles #include "lyxfunc.h" #include "lyxlex.h" +#include "paragraph.h" #include "TocBackend.h" #include "ToolbarBackend.h" @@ -133,7 +134,7 @@ docstring const MenuItem::shortcut() const } -docstring const MenuItem::binding() const +docstring const MenuItem::binding(bool forgui) const { if (kind_ != Command) return docstring(); @@ -143,7 +144,7 @@ docstring const MenuItem::binding() const kb_keymap::Bindings bindings = theTopLevelKeymap().findbindings(func_); if (bindings.size()) { - return from_utf8(bindings.begin()->print()); + return bindings.begin()->print(forgui); } else { lyxerr[Debug::KBMAP] << "No binding for " @@ -274,7 +275,7 @@ Menu & Menu::read(LyXLex & lex) // fallback to md_item case md_item: { lex.next(true); - docstring const name = _(lex.getString()); + docstring const name = translateIfPossible(lex.getDocString()); lex.next(true); string const command = lex.getString(); FuncRequest func = lyxaction.lookupFunc(command); @@ -348,9 +349,9 @@ Menu & Menu::read(LyXLex & lex) // fallback to md_submenu case md_submenu: { lex.next(true); - docstring const mlabel = _(lex.getString()); + docstring const mlabel = translateIfPossible(lex.getDocString()); lex.next(true); - docstring const mname = from_utf8(lex.getString()); + docstring const mname = lex.getDocString(); add(MenuItem(MenuItem::Submenu, mlabel, mname, optional)); optional = false; @@ -412,10 +413,9 @@ void Menu::checkShortcuts() const } -void MenuBackend::specialMenu(docstring const &name) +void MenuBackend::specialMenu(Menu const & menu) { - if (hasMenu(name)) - specialmenu_ = &getMenu(name); + specialmenu_ = menu; } @@ -447,10 +447,11 @@ void expandLastfiles(Menu & tomenu) int ii = 1; for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) { + string const file = lfit->absFilename(); docstring const label = convert(ii) + ". " - + makeDisplayPath((*lfit), 30) + + makeDisplayPath(file, 30) + char_type('|') + convert(ii); - tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit)))); + tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file))); } } @@ -485,7 +486,7 @@ void expandBookmarks(Menu & tomenu) for (size_t i = 1; i <= bm.size(); ++i) { if (bm.isValid(i)) { docstring const label = convert(i) + ". " - + makeDisplayPath(bm.bookmark(i).filename, 20) + + makeDisplayPath(bm.bookmark(i).filename.absFilename(), 20) + char_type('|') + convert(i); tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BOOKMARK_GOTO, convert(i)))); @@ -535,10 +536,12 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) switch (kind) { case MenuItem::ImportFormats: + // FIXME: This is a hack, we should rather solve + // FIXME: bug 2488 instead. if ((*fit)->name() == "text") - label = _("Plain Text as Lines"); + label = _("Plain Text"); else if ((*fit)->name() == "textparagraph") - label = _("Plain Text as Paragraphs"); + label = _("Plain Text, Join Lines"); label += "..."; break; case MenuItem::ViewFormats: @@ -625,7 +628,7 @@ void expandCharStyleInsert(Menu & tomenu, Buffer const * buf) docstring const label = from_utf8(cit->name); tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_CHARSTYLE_INSERT, - cit->name))); + label))); } } @@ -633,22 +636,22 @@ void expandCharStyleInsert(Menu & tomenu, Buffer const * buf) Menu::size_type const max_number_of_items = 25; void expandToc2(Menu & tomenu, - TocBackend::Toc const & toc_list, - TocBackend::Toc::size_type from, - TocBackend::Toc::size_type to, int depth) + Toc const & toc_list, + Toc::size_type from, + Toc::size_type to, int depth) { int shortcut_count = 0; // check whether depth is smaller than the smallest depth in toc. int min_depth = 1000; - for (TocBackend::Toc::size_type i = from; i < to; ++i) + for (Toc::size_type i = from; i < to; ++i) min_depth = std::min(min_depth, toc_list[i].depth()); if (min_depth > depth) depth = min_depth; if (to - from <= max_number_of_items) { - for (TocBackend::Toc::size_type i = from; i < to; ++i) { + for (Toc::size_type i = from; i < to; ++i) { docstring label(4 * max(0, toc_list[i].depth() - depth), char_type(' ')); label += limit_string_length(toc_list[i].str()); if (toc_list[i].depth() == depth @@ -660,9 +663,9 @@ void expandToc2(Menu & tomenu, FuncRequest(toc_list[i].action()))); } } else { - TocBackend::Toc::size_type pos = from; + Toc::size_type pos = from; while (pos < to) { - TocBackend::Toc::size_type new_pos = pos + 1; + Toc::size_type new_pos = pos + 1; while (new_pos < to && toc_list[new_pos].depth() > depth) ++new_pos; @@ -704,10 +707,19 @@ void expandToc(Menu & tomenu, Buffer const * buf) return; } + // Add an entry for the master doc if this is a child doc + Buffer const * const master = buf->getMasterBuffer(); + if (buf != master) { + ParIterator const pit = par_iterator_begin(master->inset()); + string const arg = convert(pit->id()); + FuncRequest f(LFUN_PARAGRAPH_GOTO, arg); + tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f)); + } + FloatList const & floatlist = buf->params().getLyXTextClass().floats(); - TocBackend::TocList const & toc_list = buf->tocBackend().tocs(); - TocBackend::TocList::const_iterator cit = toc_list.begin(); - TocBackend::TocList::const_iterator end = toc_list.end(); + TocList const & toc_list = buf->tocBackend().tocs(); + TocList::const_iterator cit = toc_list.begin(); + TocList::const_iterator end = toc_list.end(); for (; cit != end; ++cit) { // Handle this later if (cit->first == "tableofcontents") @@ -715,8 +727,8 @@ void expandToc(Menu & tomenu, Buffer const * buf) // All the rest is for floats auto_ptr menu(new Menu); - TocBackend::Toc::const_iterator ccit = cit->second.begin(); - TocBackend::Toc::const_iterator eend = cit->second.end(); + TocIterator ccit = cit->second.begin(); + TocIterator eend = cit->second.end(); for (; ccit != eend; ++ccit) { docstring const label = limit_string_length(ccit->str()); menu->add(MenuItem(MenuItem::Command, @@ -768,7 +780,7 @@ void expandToolbars(Menu & tomenu) for (; cit != end; ++cit) { docstring label = _(cit->gui_name); - // frontends are not supposed to turn on/off toolbars, if they can not + // frontends are not supposed to turn on/off toolbars, if they cannot // update ToolbarBackend::flags. That is to say, ToolbarsBackend::flags // should reflect the true state of toolbars. // @@ -879,8 +891,7 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu, break; case MenuItem::Command: - if (!specialmenu_ - || !specialmenu_->hasFunc(cit->func())) + if (!specialmenu_.hasFunc(cit->func())) tomenu.addWithStatusCheck(*cit); } } @@ -929,7 +940,7 @@ void MenuBackend::read(LyXLex & lex) break; case md_menu: { lex.next(true); - docstring const name = from_utf8(lex.getString()); + docstring const name = lex.getDocString(); if (hasMenu(name)) { getMenu(name).read(lex); } else {