]> 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 91ab3f271e5a7b2a3c17daae75672fc82587d893..e06ce0fab265cf4c9fdb1979e7b68f1da0763b29 100644 (file)
@@ -1437,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);
        }
 }