]> git.lyx.org Git - lyx.git/blobdiff - src/MenuBackend.cpp
* BufferView::updateMetrics(): split up the method in two for the SinglePar case.
[lyx.git] / src / MenuBackend.cpp
index dce50f52d11a7259bc08c0c5d71b5305401ae91a..fec705230dd64dddca6ce2f7518f36575a1abc3b 100644 (file)
@@ -218,6 +218,8 @@ Menu & Menu::read(Lexer & lex)
                md_documents,
                md_bookmarks,
                md_charstyles,
+               md_custom,
+               md_elements,
                md_endmenu,
                md_exportformats,
                md_importformats,
@@ -240,7 +242,9 @@ Menu & Menu::read(Lexer & lex)
                { "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 },
@@ -294,6 +298,14 @@ Menu & Menu::read(Lexer & lex)
                        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;
@@ -456,24 +468,27 @@ void expandLastfiles(Menu & tomenu)
 
 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)));
-       }
 }
 
 
@@ -610,7 +625,7 @@ void expandFloatInsert(Menu & tomenu, Buffer const * buf)
 }
 
 
-void expandCharStyleInsert(Menu & tomenu, Buffer const * buf)
+void expandFlexInsert(Menu & tomenu, Buffer const * buf, std::string s)
 {
        if (!buf) {
                tomenu.add(MenuItem(MenuItem::Command,
@@ -618,14 +633,15 @@ void expandCharStyleInsert(Menu & tomenu, Buffer const * buf)
                                    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)));
        }
 }
@@ -705,6 +721,10 @@ void expandToc(Menu & tomenu, Buffer const * buf)
                return;
        }
 
+       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();
        if (buf != master) {
@@ -870,7 +890,15 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
                        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: