]> git.lyx.org Git - features.git/commitdiff
Improve the list of equations
authorGuillaume Munch <gm@lyx.org>
Mon, 9 Jan 2017 16:37:50 +0000 (17:37 +0100)
committerGuillaume Munch <gm@lyx.org>
Mon, 9 Jan 2017 17:27:26 +0000 (18:27 +0100)
Also convert other Tocs to TocBuilder when trivial, to make them customisable

src/insets/InsetCitation.cpp
src/insets/InsetExternal.cpp
src/insets/InsetGraphics.cpp
src/insets/InsetInclude.cpp
src/insets/InsetIndex.cpp
src/insets/InsetNomencl.cpp
src/mathed/InsetMathHull.cpp
src/mathed/MathMacroTemplate.cpp

index 13fddd7802217c2f6015ee5c87bf2625a5bdfeb9..29a0fbfc072c1b1a8190a16934a90ed7e5c0dbe9 100644 (file)
@@ -334,8 +334,9 @@ void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
        // by both XHTML and plaintext output. So, if we change what goes into the TOC,
        // then we will also need to change that routine.
        docstring const tocitem = getParam("key");
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("citation");
-       toc->push_back(TocItem(cpit, 0, tocitem, output_active));
+       TocBuilder & b = buffer().tocBackend().builder("citation");
+       b.pushItem(cpit, tocitem, output_active);
+       b.pop();
 }
 
 
index 00c304ac3075c49fd903fe0333dc1eb70aa6827b..6e0baff5d739556fb9437c5f78968c7606938389 100644 (file)
@@ -506,11 +506,10 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
 void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
                                                         UpdateType) const
 {
-       DocIterator pit = cpit;
-       pit.push_back(CursorSlice(const_cast<InsetExternal &>(*this)));
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("external");
        docstring str = screenLabel(params_, buffer());
-       toc->push_back(TocItem(pit, 0, str, output_active));
+       TocBuilder & b = buffer().tocBackend().builder("external");
+       b.pushItem(cpit, str, output_active);
+       b.pop();
 }
 
 
index 4d850b59db42c6c1e767210433cf0db920de3e21..d1458c05a3dc8df58e667226a05d7048a06e0ada 100644 (file)
@@ -1040,7 +1040,9 @@ void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active,
 {
        //FIXME UNICODE
        docstring const str = from_utf8(params_.filename.onlyFileName());
-       buffer().tocBackend().toc("graphics")->push_back(TocItem(cpit, 0, str, output_active));
+       TocBuilder & b = buffer().tocBackend().builder("graphics");
+       b.pushItem(cpit, str, output_active);
+       b.pop();
 }
 
 
index 7a35edd1737f08d002f15024e9d8228545bd4af8..4e44ec8c87800f1825b2d65da6991fb9b6a1d837 100644 (file)
@@ -1143,37 +1143,33 @@ void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
 void InsetInclude::addToToc(DocIterator const & cpit, bool output_active,
                                                        UpdateType utype) const
 {
-       TocBackend & backend = buffer().tocBackend();
-
        if (isListings(params())) {
                if (label_)
                        label_->addToToc(cpit, output_active, utype);
-
+               TocBuilder & b = buffer().tocBackend().builder("listing");
+               b.pushItem(cpit, screenLabel(), output_active);
                InsetListingsParams p(to_utf8(params()["lstparams"]));
-               string caption = p.getParamValue("caption");
-               if (caption.empty())
-                       return;
-               shared_ptr<Toc> toc = backend.toc("listing");
-               docstring str = convert<docstring>(toc->size() + 1)
-                       + ". " +  from_utf8(caption);
-               DocIterator pit = cpit;
-               toc->push_back(TocItem(pit, 0, str, output_active));
+               b.argumentItem(from_utf8(p.getParamValue("caption")));
+               b.pop();
        } else {
                Buffer const * const childbuffer = getChildBuffer();
+
+               TocBuilder & b = buffer().tocBackend().builder("child");
+               docstring str = childbuffer ? childbuffer->fileName().displayName()
+                       : from_ascii("?");
+               b.pushItem(cpit, str, output_active);
+               b.pop();
+
                if (!childbuffer)
                        return;
 
-               shared_ptr<Toc> toc = backend.toc("child");
-               docstring str = childbuffer->fileName().displayName();
-               toc->push_back(TocItem(cpit, 0, str, output_active));
-
+               // Include Tocs from children
                childbuffer->tocBackend().update(output_active, utype);
-               TocList const & childtoclist = childbuffer->tocBackend().tocs();
-               TocList::const_iterator it = childtoclist.begin();
-               TocList::const_iterator const end = childtoclist.end();
-               for(; it != end; ++it) {
-                       shared_ptr<Toc> toc = backend.toc(it->first);
-                       toc->insert(toc->end(), it->second->begin(), it->second->end());
+               for(auto const & pair : childbuffer->tocBackend().tocs()) {
+                       string const & type = pair.first;
+                       shared_ptr<Toc> child_toc = pair.second;
+                       shared_ptr<Toc> toc = buffer().tocBackend().toc(type);
+                       toc->insert(toc->end(), child_toc->begin(), child_toc->end());
                }
        }
 }
index 455b09fa87638d4ecd4c00d205b5cecd1c18b74d..a328d27de635c885b6d978e1fccf0ec81a763e16 100644 (file)
@@ -361,9 +361,11 @@ void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
                type += ":" + to_utf8(params_.index);
        // this is unlikely to be terribly long
        text().forOutliner(str, INT_MAX);
-       buffer().tocBackend().toc(type)->push_back(TocItem(pit, 0, str, output_active));
+       TocBuilder & b = buffer().tocBackend().builder(type);
+       b.pushItem(pit, str, output_active);
        // Proceed with the rest of the inset.
        InsetCollapsable::addToToc(cpit, output_active, utype);
+       b.pop();
 }
 
 
index 7395b6c19e71c2c9f619d9b3e5810fb757784450..fe4f7fb1419a6c833a83fc82dc5cc25c7a573909 100644 (file)
@@ -141,7 +141,9 @@ void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active,
                                                        UpdateType) const
 {
        docstring const str = getParam("symbol");
-       buffer().tocBackend().toc("nomencl")->push_back(TocItem(cpit, 0, str, output_active));
+       TocBuilder & b = buffer().tocBackend().builder("nomencl");
+       b.pushItem(cpit, str, output_active);
+       b.pop();
 }
 
 
index 807475e63aa771ed8381db02f0bc10d6424ed2f0..61e02104874241536902cf1441b1e98f0d25d2c7 100644 (file)
@@ -344,15 +344,42 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
                return;
        }
 
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("equation");
-
+       TocBuilder & b = buffer().tocBackend().builder("equation");
+       // compute first and last item
+       row_type first = nrows();
+       for (row_type row = 0; row != nrows(); ++row)
+               if (numbered(row)) {
+                       first = row;
+                       break;
+               }
+       if (first == nrows())
+               // no equation
+               return;
+       row_type last = nrows() - 1;
+       for (; last != 0; --last)
+               if (numbered(last))
+                       break;
+       // add equation numbers
+       b.pushItem(pit, docstring(), output_active);
+       if (first != last)
+               b.argumentItem(bformat(from_ascii("(%1$s-%2$s)"),
+                                      numbers_[first], numbers_[last]));
        for (row_type row = 0; row != nrows(); ++row) {
                if (!numbered(row))
                        continue;
                if (label_[row])
                        label_[row]->addToToc(pit, output_active, utype);
-               toc->push_back(TocItem(pit, 0, nicelabel(row), output_active));
+               docstring label = nicelabel(row);
+               if (first == last)
+                       // this is the only equation
+                       b.argumentItem(label);
+               else {
+                       // insert as sub-items
+                       b.pushItem(pit, label, output_active);
+                       b.pop();
+               }
        }
+       b.pop();
 }
 
 
index 2ac8703cb0cfa6fc4c8ebe470b7a61a266dcd165..2c6cbf7a82cdb34a4d2424135e92fcfcc1f52a99 100644 (file)
@@ -1389,13 +1389,14 @@ string MathMacroTemplate::contextMenuName() const
 void MathMacroTemplate::addToToc(DocIterator const & pit, bool output_active,
                                                                 UpdateType) const
 {
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("math-macro");
        docstring str;
        if (!validMacro())
                str = bformat(_("Invalid macro! \\%1$s"), name());
        else
                str = "\\" + name();
-       toc->push_back(TocItem(pit, 0, str, output_active));
+       TocBuilder & b = buffer().tocBackend().builder("math-macro");
+       b.pushItem(pit, str, output_active);
+       b.pop();
 }