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.
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);
}
}