using std::sort;
using std::string;
using std::vector;
-
+using std::stack;
namespace {
md_documents,
md_bookmarks,
md_charstyles,
+ md_custom,
+ md_elements,
md_endmenu,
md_exportformats,
md_importformats,
{ "bookmarks", md_bookmarks },
{ "branches", md_branches },
{ "charstyles", md_charstyles },
+ { "custom", md_custom },
{ "documents", md_documents },
+ { "elements", md_elements },
{ "end", md_endmenu },
{ "exportformats", md_exportformats },
{ "floatinsert", md_floatinsert },
add(MenuItem(MenuItem::CharStyles));
break;
+ case md_custom:
+ add(MenuItem(MenuItem::Custom));
+ break;
+
+ case md_elements:
+ add(MenuItem(MenuItem::Elements));
+ break;
+
case md_documents:
add(MenuItem(MenuItem::Documents));
break;
}
+bool Menu::searchFunc(FuncRequest & func, stack<docstring> & names)
+{
+ const_iterator m = begin();
+ const_iterator m_end = end();
+ for (; m != m_end; ++m) {
+ if (m->kind() == MenuItem::Command && m->func() == func) {
+ names.push(m->label());
+ return true;
+ } else if (m->kind() == MenuItem::Submenu) {
+ names.push(m->label());
+ Menu submenu = menubackend.getMenu(m->submenuname());
+ if (submenu.searchFunc(func, names))
+ return true;
+ else
+ names.pop();
+ }
+ }
+ return false;
+}
+
+
void MenuBackend::specialMenu(Menu const & menu)
{
specialmenu_ = menu;
void expandDocuments(Menu & tomenu)
{
- typedef vector<string> Strings;
- Strings const names = theBufferList().getFileNames();
-
- if (names.empty()) {
- tomenu.add(MenuItem(MenuItem::Command, _("No Document Open!"),
- FuncRequest(LFUN_NOACTION)));
+ Buffer * first = theBufferList().first();
+ if (first) {
+ Buffer * b = first;
+ int ii = 1;
+
+ // We cannot use a for loop as the buffer list cycles.
+ do {
+ docstring label = makeDisplayPath(b->fileName(), 20);
+ if (!b->isClean()) label = label + "*";
+ if (ii < 10)
+ label = convert<docstring>(ii) + ". " + label + '|' + convert<docstring>(ii);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BUFFER_SWITCH, b->fileName())));
+
+ b = theBufferList().next(b);
+ ++ii;
+ } while (b != first);
+ } else {
+ tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
+ FuncRequest(LFUN_NOACTION)));
return;
}
-
- int ii = 1;
- Strings::const_iterator docit = names.begin();
- Strings::const_iterator end = names.end();
- for (; docit != end; ++docit, ++ii) {
- docstring label = makeDisplayPath(*docit, 20);
- if (ii < 10)
- label = convert<docstring>(ii) + ". " + label + char_type('|') + convert<docstring>(ii);
- tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BUFFER_SWITCH, *docit)));
- }
}
}
-void expandCharStyleInsert(Menu & tomenu, Buffer const * buf)
+void expandFlexInsert(Menu & tomenu, Buffer const * buf, std::string s)
{
if (!buf) {
tomenu.add(MenuItem(MenuItem::Command,
FuncRequest(LFUN_NOACTION)));
return;
}
- CharStyles & charstyles =
- buf->params().getTextClass().charstyles();
- CharStyles::iterator cit = charstyles.begin();
- CharStyles::iterator end = charstyles.end();
+ InsetLayouts const & insetlayouts =
+ buf->params().getTextClass().insetlayouts();
+ InsetLayouts::const_iterator cit = insetlayouts.begin();
+ InsetLayouts::const_iterator end = insetlayouts.end();
for (; cit != end; ++cit) {
- docstring const label = from_utf8(cit->name);
- tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label,
- FuncRequest(LFUN_CHARSTYLE_INSERT,
+ docstring const label = cit->first;
+ if (cit->second.lyxtype == s)
+ tomenu.addWithStatusCheck(MenuItem(MenuItem::Command,
+ label, FuncRequest(LFUN_FLEX_INSERT,
label)));
}
}
return;
}
- const_cast<Buffer*>(buf)->tocBackend().update();
+ Buffer* cbuf = const_cast<Buffer*>(buf);
+ cbuf->tocBackend().update();
+ cbuf->structureChanged();
// Add an entry for the master doc if this is a child doc
Buffer const * const master = buf->getMasterBuffer();
break;
case MenuItem::CharStyles:
- expandCharStyleInsert(tomenu, buf);
+ expandFlexInsert(tomenu, buf, "charstyle");
+ break;
+
+ case MenuItem::Custom:
+ expandFlexInsert(tomenu, buf, "custom");
+ break;
+
+ case MenuItem::Elements:
+ expandFlexInsert(tomenu, buf, "element");
break;
case MenuItem::FloatListInsert: