]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Menus.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / Menus.cpp
index b9450a28575fa30952defe16497a69e25fc49ebe..e06ce0fab265cf4c9fdb1979e7b68f1da0763b29 100644 (file)
@@ -1131,7 +1131,7 @@ void MenuDefinition::expandFormats(MenuItem::Kind const kind, Buffer const * buf
                                docstring lbl = (kind == MenuItem::ViewFormats
                                        ? bformat(_("View [%1$s]|V"), label)
                                        : bformat(_("Update [%1$s]|U"), label));
-                               add(MenuItem(MenuItem::Command, toqstr(lbl), FuncRequest(action, f->name())));
+                               add(MenuItem(MenuItem::Command, toqstr(lbl), FuncRequest(action)));
                                continue;
                        }
                        break;
@@ -1230,13 +1230,16 @@ void MenuDefinition::expandFlexInsert(
                if (cit->second.lyxtype() == type) {
                        if (!cit->second.obsoleted_by().empty())
                                continue;
-                       docstring label = cit->first;
+                       docstring name = cit->first;
                        // we remove the "Flex:" prefix, if it is present
-                       if (prefixIs(label, from_ascii("Flex:")))
-                               label = label.substr(5);
+                       if (prefixIs(name, from_ascii("Flex:")))
+                               name = name.substr(5);
+                       docstring const label = (cit->second.menustring().empty()) ?
+                                               name
+                                             : cit->second.menustring();
                        addWithStatusCheck(MenuItem(MenuItem::Command,
                                toqstr(translateIfPossible(label)),
-                               FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label))));
+                               FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(name))));
                }
        }
        // FIXME This is a little clunky.
@@ -1434,51 +1437,59 @@ void MenuDefinition::expandBranches(Buffer const * buf)
        if (!buf || buf->hasReadonlyFlag())
                return;
 
-       BufferParams const & master_params = buf->masterBuffer()->params();
-       BufferParams const & params = buf->params();
-       if (params.branchlist().empty() && master_params.branchlist().empty() ) {
-               add(MenuItem(MenuItem::Help, qt_("No Branches Set for Document!")));
-               return;
-       }
-
-       BranchList::const_iterator cit = master_params.branchlist().begin();
-       BranchList::const_iterator end = master_params.branchlist().end();
+       BranchList const & child_list = buf->params().branchlist();
+       set<docstring> brset;
+       int ii = 1;
+       for (auto const & b : child_list) {
+               docstring const & bname = b.branch();
+               // NUM. Branch Name + "|", which triggers an empty shortcut in
+               // case that character should be in the branch name.
+               docstring label = convert<docstring>(ii) + ". " + bname + char_type('|');
+               // Add NUM as a keyboard shortcut if it's a single digit
+               if (ii < 10)
+                       label += convert<docstring>(ii);
 
-       for (int ii = 1; cit != end; ++cit, ++ii) {
-               docstring label = cit->branch();
-               if (ii < 10) {
-                       label = convert<docstring>(ii) + ". " + label
-                               + char_type('|') + convert<docstring>(ii);
-               }
                addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
-                                   FuncRequest(LFUN_BRANCH_INSERT,
-                                               cit->branch())));
+                       FuncRequest(LFUN_BRANCH_INSERT, bname)));
+
+               brset.insert(bname);
+               ++ii;
        }
 
-       if (buf == buf->masterBuffer())
-               return;
+       set<Buffer const *> bufset;
+       Buffer const * nextbuf = buf->parent();
+       MenuDefinition master_branches;
+       ii = 1;
+       while (nextbuf) {
+               // recursive includes are a bad idea, but let's not crash
+               // if we find one.
+               if (bufset.count(nextbuf))
+                       break;
+
+               for (auto const & b : nextbuf->params().branchlist()) {
+                       docstring const & bname = b.branch();
+                       // do not add it if we've already seen it
+                       if (brset.count(bname))
+                               continue;
+
+                       docstring label = convert<docstring>(ii) + ". " + bname + char_type('|');
+                       if (ii < 10)
+                               label += convert<docstring>(ii);
 
-       MenuDefinition child_branches;
+                       master_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
+                               toqstr(label), FuncRequest(LFUN_BRANCH_INSERT, bname)));
 
-       BranchList::const_iterator ccit = params.branchlist().begin();
-       BranchList::const_iterator cend = params.branchlist().end();
+                       bufset.insert(nextbuf);
+                       brset.insert(bname);
+                       ++ii;
+               }
 
-       for (int ii = 1; ccit != cend; ++ccit, ++ii) {
-               docstring label = ccit->branch();
-               if (ii < 10) {
-                       label = convert<docstring>(ii) + ". " + label
-                               + char_type('|') + convert<docstring>(ii);
-               } else
-                       label += char_type('|');
-               child_branches.addWithStatusCheck(MenuItem(MenuItem::Command,
-                                   toqstr(label),
-                                   FuncRequest(LFUN_BRANCH_INSERT,
-                                               ccit->branch())));
+               nextbuf = nextbuf->parent();
        }
 
-       if (!child_branches.empty()) {
-               MenuItem item(MenuItem::Submenu, qt_("Child Document"));
-               item.setSubmenu(child_branches);
+       if (!master_branches.empty()) {
+               MenuItem item(MenuItem::Submenu, qt_("Master Documents"));
+               item.setSubmenu(master_branches);
                add(item);
        }
 }