commit d5a5fbb8ee87d4a8ae1c55f9ba72819251bb6fb7
Author: Guillaume Munch <[email protected]>
Date:   Sun Sep 27 07:05:00 2015 +0100

    Enhancements and bugfixes to the TOCs
    
    * New TOC "math-macro". This means that math macros can now be accessed in 
the
      outline pane in their order of appearance or in alphabetical order, and 
can be
      searched using the filter.
    
    * Lists of floats now show subfloats deeper in the navigation menu
    
    * The arbitrary 30 element cut-off after which nothing is shown except "Open
      Navigator..." is removed. Menus now have no limit in size, so Qt may 
display
      them scrollable. In exchange, we always show "Open outliner..." at the
      beginning. I tested for performance issues with a rather complex document 
and
      it is fine; but this does not exclude corner cases with lots of TOC 
entries of
      a certain kind. If necessary, populating the navigation sub-menu should be
      delayed like the main menu.
    
    * Elements that do not contribute to the output (e.g. in a note, a disabled
      branch) are now preceded with a symbol indicating this status. (The 
machinery
      was already there; I wonder why it was not implemented already.) I have 
chosen
      U+274E NEGATIVE SQUARED CROSS MARK.
    
    * Fix the contextual menus in the outliner (bug introduced at 94e992c5).
    
    * Toc item now move to the caption when present, but first center on the 
float,
      to prevent the situation where the caption is at the top of the screen 
and the
      contents of the float is off-screen above the caption.
      (Internally, the action of the toc items can now be customised)
    
    * Fix the LyXHTML output. Disabled captions no longer appear in the list of
      figures.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 0f37edd..6eea29a 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4462,7 +4462,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType 
utype) const
        d->bibinfo_cache_valid_ = true;
        d->cite_labels_valid_ = true;
        /// FIXME: Perf
-       cbuf.tocBackend().update(utype == OutputUpdate);
+       cbuf.tocBackend().update(true, utype);
        if (scope == UpdateMaster)
                cbuf.structureChanged();
 }
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index 1eb8f80..f0750c6 100644
--- a/src/TocBackend.cpp
+++ b/src/TocBackend.cpp
@@ -39,6 +39,7 @@ using namespace std;
 
 namespace lyx {
 
+
 ///////////////////////////////////////////////////////////////////////////
 //
 // TocItem implementation
@@ -46,8 +47,9 @@ namespace lyx {
 ///////////////////////////////////////////////////////////////////////////
 
 TocItem::TocItem(DocIterator const & dit, int d, docstring const & s,
-       bool output_active, docstring const & t) :
-  dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active)
+                       bool output_active, docstring const & t, FuncRequest 
action) :
+       dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active),
+       action_(action)
 {
 }
 
@@ -66,15 +68,32 @@ docstring const & TocItem::tooltip() const
 
 docstring const TocItem::asString() const
 {
-       return docstring(4 * depth_, ' ') + str_;
+       // U+2327 X IN A RECTANGLE BOX
+       // char_type const cross = 0x2327;
+       // U+274E NEGATIVE SQUARED CROSS MARK
+       char_type const cross = 0x274e;
+       docstring prefix;
+       if (!output_) {
+               prefix += cross;
+               prefix += " ";
+       }
+       return prefix + str_;
 }
 
+// convert a DocIterator into an argument to LFUN_PARAGRAPH_GOTO 
+docstring paragraph_goto_arg(DocIterator const & dit)
+{
+       CursorSlice const & s = dit.innerTextSlice();
+       return convert<docstring>(s.paragraph().id()) + ' ' +
+               convert<docstring>(s.pos());
+}
 
 FuncRequest TocItem::action() const
 {
-       string const arg = convert<string>(dit_.paragraph().id())
-               + ' ' + convert<string>(dit_.pos());
-       return FuncRequest(LFUN_PARAGRAPH_GOTO, arg);
+       if (action_.action() == LFUN_UNKNOWN_ACTION) {
+               return FuncRequest(LFUN_PARAGRAPH_GOTO, 
paragraph_goto_arg(dit_));
+       } else
+               return action_;
 }
 
 
@@ -156,15 +175,29 @@ void TocBuilder::pushItem(DocIterator const & dit, 
docstring const & s,
 void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
                                                         bool output_active)
 {
+       // first show the float before moving to the caption
+       docstring arg = "paragraph-goto " + paragraph_goto_arg(dit);
+       if (!stack_.empty())
+               arg = "paragraph-goto " +
+                       paragraph_goto_arg((*toc_)[stack_.top().pos].dit_) + 
";" + arg;
+       FuncRequest func(LFUN_COMMAND_SEQUENCE, arg);
+       
        if (!stack_.empty() && !stack_.top().is_captioned) {
                // The float we entered has not yet been assigned a caption.
                // Assign the caption string to it.
-               (*toc_)[stack_.top().pos].str(s);
+               TocItem & captionable = (*toc_)[stack_.top().pos];
+               captionable.str(s);
+               captionable.setAction(func);
                stack_.top().is_captioned = true;
        } else {
                // This is a new entry.
                pop();
-               pushItem(dit, s, output_active, true);
+               // the dit is at the float's level, e.g. for the contextual 
menu of
+               // outliner entries
+               DocIterator captionable_dit = dit;
+               captionable_dit.pop_back();
+               pushItem(captionable_dit, s, output_active, true);
+               (*toc_)[stack_.top().pos].setAction(func);
        }
 }
 
@@ -269,14 +302,14 @@ bool TocBackend::updateItem(DocIterator const & dit)
                && tocstring.empty())
                        tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);
 
-       const_cast<TocItem &>(*toc_item).str_ = tocstring;
+       const_cast<TocItem &>(*toc_item).str(tocstring);
 
        buffer_->updateTocItem("tableofcontents", dit);
        return true;
 }
 
 
-void TocBackend::update(bool output_active)
+void TocBackend::update(bool output_active, UpdateType utype)
 {
        for (TocList::iterator it = tocs_.begin(); it != tocs_.end(); ++it)
                it->second->clear();
@@ -284,7 +317,7 @@ void TocBackend::update(bool output_active)
        builders_.clear();
        if (!buffer_->isInternal()) {
                DocIterator dit;
-               buffer_->inset().addToToc(dit, output_active);
+               buffer_->inset().addToToc(dit, output_active, utype);
        }
 }
 
diff --git a/src/TocBackend.h b/src/TocBackend.h
index 176175d..2668eb0 100644
--- a/src/TocBackend.h
+++ b/src/TocBackend.h
@@ -16,6 +16,8 @@
 #define TOC_BACKEND_H
 
 #include "DocIterator.h"
+#include "FuncRequest.h"
+#include "OutputEnums.h"
 
 #include "support/shared_ptr.h"
 #include "support/strfwd.h"
@@ -29,7 +31,6 @@
 namespace lyx {
 
 class Buffer;
-class FuncRequest;
 
 
 /* FIXME: toc types are currently identified by strings. It cannot be converted
@@ -66,6 +67,7 @@ class TocItem
 {
        friend class Toc;
        friend class TocBackend;
+       friend class TocBuilder;
 
 public:
        /// Default constructor for STL containers.
@@ -75,7 +77,8 @@ public:
                int depth,
                docstring const & s,
                bool output_active,
-               docstring const & t = docstring()
+               docstring const & t = docstring(),
+               FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
                );
        ///
        ~TocItem() {}
@@ -89,19 +92,22 @@ public:
        void str(docstring const & s) { str_ = s; }
        ///
        docstring const & tooltip() const;
-       ///
+       /// String for display, e.g. it has a mark if output is inactive
        docstring const asString() const;
        ///
        DocIterator const & dit() const { return dit_; }
        ///
        bool isOutput() const { return output_; }
-
-       /// the action corresponding to the goTo above
+       ///
+       void setAction(FuncRequest a) { action_ = a; }
+       /// custom action, or the default one (paragraph-goto) if not customised
        FuncRequest action() const;
 
 protected:
        /// Current position of item.
        DocIterator dit_;
+
+private:
        /// nesting depth
        int depth_;
        /// Full item string
@@ -110,6 +116,8 @@ protected:
        docstring tooltip_;
        /// Is this item in a note, inactive branch, etc?
        bool output_;
+       /// Custom action
+       FuncRequest action_;
 };
 
 
@@ -192,7 +200,7 @@ public:
        ///
        void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
        ///
-       void update(bool output_active);
+       void update(bool output_active, UpdateType utype);
        /// \return true if the item was updated.
        bool updateItem(DocIterator const & pit);
        ///
diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp
index c336542..592a66a 100644
--- a/src/frontends/qt4/Menus.cpp
+++ b/src/frontends/qt4/Menus.cpp
@@ -1219,7 +1219,7 @@ void MenuDefinition::expandFlexInsert(
 }
 
 
-size_t const max_number_of_items = 25;
+size_t const max_number_of_items = 30;
 
 void MenuDefinition::expandToc2(Toc const & toc_list,
                size_t from, size_t to, int depth)
@@ -1236,7 +1236,7 @@ void MenuDefinition::expandToc2(Toc const & toc_list,
        if (to - from <= max_number_of_items) {
                for (size_t i = from; i < to; ++i) {
                        QString label(4 * max(0, toc_list[i].depth() - depth), 
' ');
-                       label += limitStringLength(toc_list[i].str());
+                       label += limitStringLength(toc_list[i].asString());
                        if (toc_list[i].depth() == depth) {
                                label += '|';
                            if (shortcut_count < 9) {
@@ -1246,6 +1246,9 @@ void MenuDefinition::expandToc2(Toc const & toc_list,
                        }
                        add(MenuItem(MenuItem::Command, label,
                                            FuncRequest(toc_list[i].action())));
+                       // separator after the menu heading
+                       if (toc_list[i].depth() < depth)
+                               add(MenuItem(MenuItem::Separator));
                }
        } else {
                size_t pos = from;
@@ -1255,7 +1258,7 @@ void MenuDefinition::expandToc2(Toc const & toc_list,
                                ++new_pos;
 
                        QString label(4 * max(0, toc_list[pos].depth() - 
depth), ' ');
-                       label += limitStringLength(toc_list[pos].str());
+                       label += limitStringLength(toc_list[pos].asString());
                        if (toc_list[pos].depth() == depth) {
                                label += '|';
                            if (shortcut_count < 9) {
@@ -1285,12 +1288,10 @@ void MenuDefinition::expandToc(Buffer const * buf)
        // all MenuItem constructors and to expandToc2. However, we
        // know that all the entries in a TOC will be have status_ ==
        // OK, so we avoid this unnecessary overhead (JMarc)
-
        if (!buf) {
-               add(MenuItem(MenuItem::Info, qt_("<No Document Open>")));
+               add(MenuItem(MenuItem::Info, qt_("(No Document Open)")));
                return;
        }
-
        // Add an entry for the master doc if this is a child doc
        Buffer const * const master = buf->masterBuffer();
        if (buf != master) {
@@ -1301,68 +1302,36 @@ void MenuDefinition::expandToc(Buffer const * buf)
        }
 
        MenuDefinition other_lists;
-
        FloatList const & floatlist = buf->params().documentClass().floats();
        TocList const & toc_list = buf->tocBackend().tocs();
        TocList::const_iterator cit = toc_list.begin();
        TocList::const_iterator end = toc_list.end();
        for (; cit != end; ++cit) {
-               // Handle this later
-               if (cit->first == "tableofcontents")
+               // Handle table of contents later
+               if (cit->first == "tableofcontents" || cit->second->empty())
                        continue;
-
                MenuDefinition submenu;
-               if (floatlist.typeExist(cit->first)) {
-                       TocIterator ccit = cit->second->begin();
-                       TocIterator eend = cit->second->end();
-                       for (; ccit != eend; ++ccit) {
-                               if (0 == ccit->depth()) {// omit subfloats
-                                       submenu.add(MenuItem(MenuItem::Command,
-                                                                               
 limitStringLength(ccit->str()) + '|',
-                                                                               
 FuncRequest(ccit->action())));
-                               }
-                       }
-
-                       FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
-                       submenu.add(MenuItem(MenuItem::Separator));
-                       submenu.add(MenuItem(MenuItem::Command, qt_("Open 
Navigator..."), f));
-                       MenuItem item(MenuItem::Submenu, guiName(cit->first, 
buf->params()));
-                       // deserves to be in the main menu.
-                       item.setSubmenu(submenu);
+               // "Open outliner..." entry
+               FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
+               submenu.add(MenuItem(MenuItem::Command, qt_("Open 
outliner..."), f));
+               submenu.add(MenuItem(MenuItem::Separator));
+               // add entries
+               submenu.expandToc2(* cit->second, 0, cit->second->size(), 0);
+               MenuItem item(MenuItem::Submenu, guiName(cit->first, 
buf->params()));
+               item.setSubmenu(submenu);
+               // deserves to be in the main menu?
+               if (floatlist.typeExist(cit->first) || cit->first == "child")
                        add(item);
-               } else {
-                       if (cit->second->size() >= 30) {
-                               // FIXME: the behaviour of the interface should 
not change
-                               // arbitrarily. Each type should be audited to 
see if the list
-                               // can be optimised like for floats above.
-                               FuncRequest f(LFUN_DIALOG_SHOW, "toc " + 
cit->first);
-                               submenu.add(MenuItem(MenuItem::Command, 
qt_("Open Navigator..."), f));
-                       } else {
-                               TocIterator ccit = cit->second->begin();
-                               TocIterator eend = cit->second->end();
-                               for (; ccit != eend; ++ccit) {
-                                       submenu.add(MenuItem(MenuItem::Command,
-                                                                               
 limitStringLength(ccit->str()) + '|',
-                                                                               
 FuncRequest(ccit->action())));
-                               }
-                       }
-
-                       MenuItem item(MenuItem::Submenu, guiName(cit->first, 
buf->params()));
-                       item.setSubmenu(submenu);
-                       if (cit->first == "child") {
-                               // deserves to be in the main menu.
-                               add(item);
-                       } else
-                               other_lists.add(item);
-               }
+               else
+                       other_lists.add(item);
        }
        if (!other_lists.empty()) {
                MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
                item.setSubmenu(other_lists);
                add(item);
        }
-
        // Handle normal TOC
+       add(MenuItem(MenuItem::Separator));
        cit = toc_list.find("tableofcontents");
        if (cit == end)
                LYXERR(Debug::GUI, "No table of contents.");
@@ -1370,7 +1339,7 @@ void MenuDefinition::expandToc(Buffer const * buf)
                if (!cit->second->empty())
                        expandToc2(* cit->second, 0, cit->second->size(), 0);
                else
-                       add(MenuItem(MenuItem::Info, qt_("<Empty Table of 
Contents>")));
+                       add(MenuItem(MenuItem::Info, qt_("(Empty Table of 
Contents)")));
        }
 }
 
diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp
index 8f0e317..53475e1 100644
--- a/src/frontends/qt4/TocModel.cpp
+++ b/src/frontends/qt4/TocModel.cpp
@@ -154,7 +154,7 @@ void TocModel::updateItem(DocIterator const & dit)
 {
        QModelIndex index = modelIndex(dit);
        TocItem const & toc_item = tocItem(index);
-       model_->setData(index, toqstr(toc_item.str()), Qt::DisplayRole);
+       model_->setData(index, toqstr(toc_item.asString()), Qt::DisplayRole);
        model_->setData(index, toqstr(toc_item.tooltip()), Qt::ToolTipRole);
 }
 
@@ -183,12 +183,12 @@ void TocModel::reset(shared_ptr<Toc const> toc)
                int current_row = model_->rowCount();
                model_->insertRows(current_row, 1);
                QModelIndex top_level_item = model_->index(current_row, 0);
-               model_->setData(top_level_item, toqstr(item.str()), 
Qt::DisplayRole);
+               model_->setData(top_level_item, toqstr(item.asString()), 
Qt::DisplayRole);
                model_->setData(top_level_item, index, Qt::UserRole);
                model_->setData(top_level_item, toqstr(item.tooltip()), 
Qt::ToolTipRole);
 
                LYXERR(Debug::GUI, "Toc: at depth " << item.depth()
-                       << ", added item " << item.str());
+                       << ", added item " << item.asString());
 
                populate(index, top_level_item);
                if (index >= end)
@@ -224,7 +224,7 @@ void TocModel::populate(unsigned int & index, QModelIndex 
const & parent)
                int current_row = model_->rowCount(parent);
                model_->insertRows(current_row, 1, parent);
                child_item = model_->index(current_row, 0, parent);
-               model_->setData(child_item, toqstr(item.str()), 
Qt::DisplayRole);
+               model_->setData(child_item, toqstr(item.asString()), 
Qt::DisplayRole);
                model_->setData(child_item, index, Qt::UserRole);
                model_->setData(child_item, toqstr(item.tooltip()), 
Qt::ToolTipRole);
                populate(index, child_item);
@@ -315,7 +315,7 @@ void TocModels::goTo(QString const & type, QModelIndex 
const & index) const
        }
        LASSERT(index.model() == it.value()->model(), return);
        TocItem const item = it.value()->tocItem(index);
-       LYXERR(Debug::GUI, "TocModels::goTo " << item.str());
+       LYXERR(Debug::GUI, "TocModels::goTo " << item.asString());
        dispatch(item.action());
 }
 
diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp
index 86fa16b..bb15f31 100644
--- a/src/frontends/qt4/TocWidget.cpp
+++ b/src/frontends/qt4/TocWidget.cpp
@@ -119,16 +119,12 @@ Inset * TocWidget::itemInset() const
 
        else if (current_type_ == "branch"
                         || current_type_ == "index"
-                        || current_type_ == "change")
+                        || current_type_ == "change"
+                        || current_type_ == "table" 
+                    || current_type_ == "listing"
+                    || current_type_ == "figure")
                inset = &dit.inset();
 
-       else if (current_type_ == "table" 
-                    || current_type_ == "listing"
-                    || current_type_ == "figure") {
-               DocIterator tmp_dit(dit);
-               tmp_dit.pop_back();
-               inset = &tmp_dit.inset();
-       }
        return inset;
 }
 
@@ -157,7 +153,7 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & 
cmd,
 
        case LFUN_LABEL_COPY_AS_REFERENCE: {
                // For labels in math, we need to supply the label as a string
-               FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, 
item.asString());
+               FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, 
item.str());
                if (inset)
                        return inset->getStatus(cur, label_copy, status);
                break;
@@ -202,7 +198,7 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const 
& cmd)
 
        case LFUN_LABEL_COPY_AS_REFERENCE: {
                // For labels in math, we need to supply the label as a string
-               FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, 
item.asString());
+               FuncRequest label_copy(LFUN_LABEL_COPY_AS_REFERENCE, 
item.str());
                if (inset)
                        inset->dispatch(cur, label_copy);
                break;
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 593aa3b..075a005 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -616,6 +616,8 @@ QString guiName(string const & type, BufferParams const & 
bp)
                return qt_("Index Entries");
        if (type == "marginalnote")
                return qt_("Marginal notes");
+       if (type == "math-macro")
+               return qt_("Math macros");
        if (type == "nomencl")
                return qt_("Nomenclature Entries");
        if (type == "note")
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index c582ea1..2cc7091 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -74,7 +74,7 @@ std::string insetName(InsetCode);
 /// Eg, insetDisplayName(BRANCH_CODE) == _("Branch")
 docstring insetDisplayName(InsetCode);
 ///
-static int const TOC_ENTRY_LENGTH = 40;
+static int const TOC_ENTRY_LENGTH = 80;
 
 /// Common base class to all insets
 
@@ -493,7 +493,15 @@ public:
        /// Add an entry to the TocList
        /// Pass a DocIterator that points at the paragraph containing
        /// the inset
-       virtual void addToToc(DocIterator const & /* di */, bool /* 
output_active */) const {}
+       ///
+       /// \param output_active : is the inset active or is it in an inactive
+       /// branch or a note?
+       ///
+       /// \param utype : is the toc being generated for use by the output
+       /// routines?
+       virtual void addToToc(DocIterator const & /* di */,
+                                                 bool /* output_active */,
+                                                 UpdateType /* utype*/) const 
{}
        /// Collect BibTeX information
        virtual void collectBibKeys(InsetIterator const &) const {}
        /// Update the counters of this inset and of its contents.
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index 98e5c4c..0ed3bc4 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -348,7 +348,8 @@ void InsetBranch::string2params(string const & in, 
InsetBranchParams & params)
 }
 
 
-void InsetBranch::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetBranch::addToToc(DocIterator const & cpit, bool output_active,
+                                                  UpdateType utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
@@ -359,7 +360,7 @@ void InsetBranch::addToToc(DocIterator const & cpit, bool 
output_active) const
        toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
        // Proceed with the rest of the inset.
        bool const doing_output = output_active && isBranchSelected();
-       InsetCollapsable::addToToc(cpit, doing_output);
+       InsetCollapsable::addToToc(cpit, doing_output, utype);
 }
 
 
diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h
index ecd2f7d..f4ba3f5 100644
--- a/src/insets/InsetBranch.h
+++ b/src/insets/InsetBranch.h
@@ -82,7 +82,8 @@ private:
        ///
        std::string contextMenuName() const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        InsetBranchParams const & params() const { return params_; }
        ///
diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp
index 415c3ad..93abfe4 100644
--- a/src/insets/InsetCaption.cpp
+++ b/src/insets/InsetCaption.cpp
@@ -90,17 +90,25 @@ void InsetCaption::setCustomLabel(docstring const & label)
 }
 
 
-void InsetCaption::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetCaption::addToToc(DocIterator const & cpit, bool output_active,
+                                                       UpdateType utype) const
 {
        string const & type = floattype_.empty() ? "senseless" : floattype_;
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetCaption &>(*this)));
-       docstring str = full_label_;
-       int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
-       text().forOutliner(str, length);
+       int length = (utype == OutputUpdate) ?
+               // For output (e.g. xhtml) all (bug #8603) or nothing
+               (output_active ? INT_MAX : 0) :
+               // TOC for LyX interface
+               TOC_ENTRY_LENGTH;
+       docstring str;
+       if (length > 0) {
+               str = full_label_;
+               text().forOutliner(str, length);
+       }
        buffer().tocBackend().builder(type)->captionItem(pit, str, 
output_active);
        // Proceed with the rest of the inset.
-       InsetText::addToToc(cpit, output_active);
+       InsetText::addToToc(cpit, output_active, utype);
 }
 
 
diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h
index 97f2691..1d8775e 100644
--- a/src/insets/InsetCaption.h
+++ b/src/insets/InsetCaption.h
@@ -79,9 +79,8 @@ private:
        docstring xhtml(XHTMLStream & os, OutputParams const & runparams) const;
        ///
        void setCustomLabel(docstring const & label);
-       /// \param output_active : is the toc being generated for use by the
-       /// output routines?
-       void addToToc(DocIterator const & di, bool output_active) const;
+       ///
+       void addToToc(DocIterator const & di, bool output_active, UpdateType 
utype) const;
        /// 
        virtual bool forcePlainLayout(idx_type = 0) const { return true; }
        /// Captions don't accept alignment, spacing, etc.
diff --git a/src/insets/InsetCaptionable.cpp b/src/insets/InsetCaptionable.cpp
index f90776a..cbdcc0a 100644
--- a/src/insets/InsetCaptionable.cpp
+++ b/src/insets/InsetCaptionable.cpp
@@ -45,17 +45,21 @@ docstring InsetCaptionable::floatName(string const & type) 
const
 }
 
 
-void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active) 
const
+void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
+                                                               UpdateType 
utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
        docstring str;
-       int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
-       text().forOutliner(str, length);
+       // Leave str empty if we generate for output (e.g. xhtml lists of 
figures).
+       // This ensures that there is a caption if and only if the string is
+       // non-empty.
+       if (utype != OutputUpdate)
+               text().forOutliner(str, TOC_ENTRY_LENGTH);
        shared_ptr<TocBuilder> b = buffer().tocBackend().builder(caption_type_);
        b->pushItem(pit, str, output_active);
        // Proceed with the rest of the inset.
-       InsetCollapsable::addToToc(cpit, output_active);
+       InsetCollapsable::addToToc(cpit, output_active, utype);
        b->pop();
 }
 
diff --git a/src/insets/InsetCaptionable.h b/src/insets/InsetCaptionable.h
index 9e85f67..94202e4 100644
--- a/src/insets/InsetCaptionable.h
+++ b/src/insets/InsetCaptionable.h
@@ -38,7 +38,8 @@ protected:
        /// are our captions subcaptions?
        virtual bool hasSubCaptions(ParIterator const &) const { return false; }
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        /// Update the counters of this inset and of its contents
        void updateBuffer(ParIterator const &, UpdateType);
        ///
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 293b0a1..b455c86 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -331,7 +331,8 @@ void InsetCitation::updateBuffer(ParIterator const &, 
UpdateType)
 }
 
 
-void InsetCitation::addToToc(DocIterator const & cpit, bool output_active) 
const
+void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
+                                                        UpdateType) const
 {
        // NOTE
        // BiblioInfo::collectCitedEntries() uses the TOC to collect the 
citations 
diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h
index 8d7bb79..4b4b5ed 100644
--- a/src/insets/InsetCitation.h
+++ b/src/insets/InsetCitation.h
@@ -65,7 +65,8 @@ public:
        ///
        void updateBuffer(ParIterator const & it, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        std::string contextMenuName() const;
        //@}
diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp
index 9c84314..6deb46c 100644
--- a/src/insets/InsetFloatList.cpp
+++ b/src/insets/InsetFloatList.cpp
@@ -209,8 +209,6 @@ docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams 
const & op) const {
                                               
op.local_font->language()->lang());
        }
 
-       // FIXME Do we need to check if it exists? If so, we need a new
-       // routine in TocBackend to do that.
        shared_ptr<Toc const> toc = buffer().tocBackend().toc(toctype);
        if (toc->empty())
                return docstring();
@@ -252,6 +250,8 @@ docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams 
const & op) const {
        Toc::const_iterator it = toc->begin();
        Toc::const_iterator const en = toc->end();
        for (; it != en; ++it) {
+               if (it->str().empty())
+                       continue;
                Paragraph const & par = it->dit().innerParagraph();
                string const attr = "class='lyxtoc-floats lyxtoc-" + toctype + 
"'";
                xs << html::StartTag("div", attr);
diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp
index e941f4a..d1b753d 100644
--- a/src/insets/InsetFoot.cpp
+++ b/src/insets/InsetFoot.cpp
@@ -74,7 +74,8 @@ void InsetFoot::updateBuffer(ParIterator const & it, 
UpdateType utype)
 }
 
 
-void InsetFoot::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetFoot::addToToc(DocIterator const & cpit, bool output_active,
+                                                UpdateType utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
@@ -84,7 +85,7 @@ void InsetFoot::addToToc(DocIterator const & cpit, bool 
output_active) const
        text().forOutliner(str, TOC_ENTRY_LENGTH);
        toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
        // Proceed with the rest of the inset.
-       InsetFootlike::addToToc(cpit, output_active);
+       InsetFootlike::addToToc(cpit, output_active, utype);
 }
 
 
diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h
index 165a7cf..f145d5c 100644
--- a/src/insets/InsetFoot.h
+++ b/src/insets/InsetFoot.h
@@ -39,7 +39,8 @@ private:
        /// Update the counters of this inset and of its contents
        void updateBuffer(ParIterator const &, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        docstring toolTip(BufferView const & bv, int x, int y) const;
        ///
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index 83cd84d..c20f031 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -1027,7 +1027,8 @@ void InsetGraphics::editGraphics(InsetGraphicsParams 
const & p) const
 }
 
 
-void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active) 
const
+void InsetGraphics::addToToc(DocIterator const & cpit, bool output_active,
+                                                        UpdateType) const
 {
        //FIXME UNICODE
        docstring const str = from_utf8(params_.filename.onlyFileName());
diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h
index d6ccfe2..3cf296f 100644
--- a/src/insets/InsetGraphics.h
+++ b/src/insets/InsetGraphics.h
@@ -99,7 +99,8 @@ private:
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        std::string contextMenuName() const;
        /// Force inset into LTR environment if surroundings are RTL
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 3883d22..20e0779 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -1125,13 +1125,14 @@ void InsetInclude::addPreview(DocIterator const & 
/*inset_pos*/,
 }
 
 
-void InsetInclude::addToToc(DocIterator const & cpit, bool output_active) const
+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);
+                       label_->addToToc(cpit, output_active, utype);
 
                InsetListingsParams p(to_utf8(params()["lstparams"]));
                string caption = p.getParamValue("caption");
@@ -1151,8 +1152,7 @@ void InsetInclude::addToToc(DocIterator const & cpit, 
bool output_active) const
                docstring str = childbuffer->fileName().displayName();
                toc->push_back(TocItem(cpit, 0, str, output_active));
 
-               //TocList & toclist = backend.tocs();
-               childbuffer->tocBackend().update(output_active);
+               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();
diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h
index bee2089..ce93c71 100644
--- a/src/insets/InsetInclude.h
+++ b/src/insets/InsetInclude.h
@@ -104,7 +104,8 @@ public:
        ///
        void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        void updateBuffer(ParIterator const &, UpdateType);
        ///
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index cb2704f..aff4080 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -348,7 +348,8 @@ void InsetIndex::string2params(string const & in, 
InsetIndexParams & params)
 }
 
 
-void InsetIndex::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
+                                                 UpdateType utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this)));
@@ -360,7 +361,7 @@ void InsetIndex::addToToc(DocIterator const & cpit, bool 
output_active) const
        text().forOutliner(str, INT_MAX);
        buffer().tocBackend().toc(type)->push_back(TocItem(pit, 0, str, 
output_active));
        // Proceed with the rest of the inset.
-       InsetCollapsable::addToToc(cpit, output_active);
+       InsetCollapsable::addToToc(cpit, output_active, utype);
 }
 
 
diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h
index a980a42..b1aa9b4 100644
--- a/src/insets/InsetIndex.h
+++ b/src/insets/InsetIndex.h
@@ -71,7 +71,8 @@ private:
        /// should paragraph indendation be omitted in any case?
        bool neverIndent() const { return true; }
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        docstring toolTip(BufferView const & bv, int x, int y) const;
        ///
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 82923ff..9171cd1 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -169,7 +169,8 @@ void InsetLabel::updateBuffer(ParIterator const & par, 
UpdateType utype)
 }
 
 
-void InsetLabel::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetLabel::addToToc(DocIterator const & cpit, bool output_active,
+                                                 UpdateType) const
 {
        docstring const & label = getParam("name");
        shared_ptr<Toc> toc = buffer().tocBackend().toc("label");
diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h
index 3c9bbd0..a5e5e3e 100644
--- a/src/insets/InsetLabel.h
+++ b/src/insets/InsetLabel.h
@@ -57,7 +57,8 @@ public:
        ///
        void updateBuffer(ParIterator const & it, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        //@}
 
        /// \name Static public methods obligated for InsetCommand derived 
classes
diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp
index 2970fcb..40ff30a 100644
--- a/src/insets/InsetMarginal.cpp
+++ b/src/insets/InsetMarginal.cpp
@@ -51,7 +51,8 @@ int InsetMarginal::docbook(odocstream & os,
 }
 
 
-void InsetMarginal::addToToc(DocIterator const & cpit, bool output_active) 
const
+void InsetMarginal::addToToc(DocIterator const & cpit, bool output_active,
+                                 UpdateType utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetMarginal &>(*this)));
@@ -61,7 +62,7 @@ void InsetMarginal::addToToc(DocIterator const & cpit, bool 
output_active) const
        text().forOutliner(str, TOC_ENTRY_LENGTH);
        toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
        // Proceed with the rest of the inset.
-       InsetFootlike::addToToc(cpit, output_active);
+       InsetFootlike::addToToc(cpit, output_active, utype);
 }
 
 } // namespace lyx
diff --git a/src/insets/InsetMarginal.h b/src/insets/InsetMarginal.h
index 38e1a9c..237beee 100644
--- a/src/insets/InsetMarginal.h
+++ b/src/insets/InsetMarginal.h
@@ -36,7 +36,8 @@ public:
        ///
        int docbook(odocstream &, OutputParams const & runparams) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
 private:
        ///
        Inset * clone() const { return new InsetMarginal(*this); }
diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp
index 953eeea..2279766 100644
--- a/src/insets/InsetNomencl.cpp
+++ b/src/insets/InsetNomencl.cpp
@@ -132,7 +132,8 @@ void InsetNomencl::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active) const
+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));
diff --git a/src/insets/InsetNomencl.h b/src/insets/InsetNomencl.h
index c58500f..14507b6 100644
--- a/src/insets/InsetNomencl.h
+++ b/src/insets/InsetNomencl.h
@@ -40,7 +40,8 @@ public:
        /// Updates needed features for this inset.
        void validate(LaTeXFeatures & features) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        InsetCode lyxCode() const { return NOMENCL_CODE; }
        ///
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index c1bb07a..6fcf279 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -207,7 +207,8 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & 
cmd,
 }
 
 
-void InsetNote::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetNote::addToToc(DocIterator const & cpit, bool output_active,
+                                                UpdateType utype) const
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
@@ -220,7 +221,7 @@ void InsetNote::addToToc(DocIterator const & cpit, bool 
output_active) const
 
        // Proceed with the rest of the inset.
        bool doing_output = output_active && producesOutput();
-       InsetCollapsable::addToToc(cpit, doing_output);
+       InsetCollapsable::addToToc(cpit, doing_output, utype);
 }
 
 
diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h
index dd580da..c80d61b 100644
--- a/src/insets/InsetNote.h
+++ b/src/insets/InsetNote.h
@@ -96,7 +96,8 @@ private:
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index c0de3ba..4489270 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -303,7 +303,8 @@ void InsetRef::updateBuffer(ParIterator const & it, 
UpdateType)
 }
 
 
-void InsetRef::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
+                                               UpdateType) const
 {
        docstring const & label = getParam("reference");
        if (buffer().insetLabel(label))
diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h
index 002fa64..5836d2e 100644
--- a/src/insets/InsetRef.h
+++ b/src/insets/InsetRef.h
@@ -70,7 +70,8 @@ public:
        ///
        void updateBuffer(ParIterator const & it, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        bool forceLTR() const { return true; }
        //@}
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 94d2f8e..6a138cc 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -3439,9 +3439,10 @@ docstring InsetTableCell::asString(bool intoInsets)
 }
 
 
-void InsetTableCell::addToToc(DocIterator const & di, bool output_active) const
+void InsetTableCell::addToToc(DocIterator const & di, bool output_active,
+                                                         UpdateType utype) 
const
 {
-       InsetText::iterateForToc(di, output_active);
+       InsetText::iterateForToc(di, output_active, utype);
 }
 
 
@@ -3927,13 +3928,14 @@ void InsetTabular::updateBuffer(ParIterator const & it, 
UpdateType utype)
 }
 
 
-void InsetTabular::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetTabular::addToToc(DocIterator const & cpit, bool output_active,
+                                                       UpdateType utype) const
 {
        DocIterator dit = cpit;
        dit.forwardPos();
        size_t const end = dit.nargs();
        for ( ; dit.idx() < end; dit.top().forwardIdx())
-               cell(dit.idx())->addToToc(dit, output_active);
+               cell(dit.idx())->addToToc(dit, output_active, utype);
 }
 
 
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index f27df2a..a3c2b86 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -71,7 +71,8 @@ public:
        ///
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
 private:
        /// unimplemented
        InsetTableCell();
@@ -942,7 +943,8 @@ public:
        /// Update the counters of this inset and of its contents
        void updateBuffer(ParIterator const &, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
 
        ///
        bool completionSupported(Cursor const &) const;
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index c4d4f24..204df96 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -797,18 +797,20 @@ void InsetText::forOutliner(docstring & os, size_t 
maxlen) const
 }
 
 
-void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
+void InsetText::addToToc(DocIterator const & cdit, bool output_active,
+                                                UpdateType utype) const
 {
        DocIterator dit = cdit;
        dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
-       iterateForToc(dit, output_active);
+       iterateForToc(dit, output_active, utype);
 }
 
 
-void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) 
const
+void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
+                                                         UpdateType utype) 
const
 {
        DocIterator dit = cdit;
-       // Ensure that any document has a table of contents
+       // This also ensures that any document has a table of contents
        shared_ptr<Toc> toc = buffer().tocBackend().toc("tableofcontents");
 
        BufferParams const & bufparams = buffer_->params();
@@ -832,7 +834,7 @@ void InsetText::iterateForToc(DocIterator const & cdit, 
bool output_active) cons
                        Inset & inset = *it->inset;
                        dit.pos() = it->pos;
                        //lyxerr << (void*)&inset << " code: " << 
inset.lyxCode() << std::endl;
-                       inset.addToToc(dit, doing_output);
+                       inset.addToToc(dit, doing_output, utype);
                        if (inset.lyxCode() == ARG_CODE)
                                arginset = inset.asInsetText();
                }
@@ -841,7 +843,8 @@ void InsetText::iterateForToc(DocIterator const & cdit, 
bool output_active) cons
                if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) 
{
                        // insert this into the table of contents
                        docstring tocstring;
-                       int const length = doing_output ? INT_MAX : 
TOC_ENTRY_LENGTH;
+                       int const length = (doing_output && utype == 
OutputUpdate) ?
+                               INT_MAX : TOC_ENTRY_LENGTH;
                        if (arginset) {
                                tocstring = par.labelString();
                                if (!tocstring.empty())
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index 64b6235..77dcfa9 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -171,7 +171,8 @@ public:
        ///
        void forOutliner(docstring &, size_t) const;
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        Inset * clone() const { return new InsetText(*this); }
        ///
@@ -217,7 +218,8 @@ protected:
        ///
        docstring getCaptionHTML(OutputParams const &) const;
        ///
-       void iterateForToc(DocIterator const & cdit, bool output_active) const;
+       void iterateForToc(DocIterator const & cdit, bool output_active,
+                                          UpdateType utype) const;
 private:
        ///
        bool drawFrame_;
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 485d62b..08bbe41 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -292,7 +292,8 @@ void InsetMathHull::updateBuffer(ParIterator const & it, 
UpdateType utype)
 }
 
 
-void InsetMathHull::addToToc(DocIterator const & pit, bool output_active) const
+void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
+                                                        UpdateType utype) const
 {
        if (!buffer_) {
                //FIXME: buffer_ should be set at creation for this inset! 
Problem is
@@ -307,7 +308,7 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool 
output_active) const
                if (!numbered(row))
                        continue;
                if (label_[row])
-                       label_[row]->addToToc(pit, output_active);
+                       label_[row]->addToToc(pit, output_active, utype);
                toc->push_back(TocItem(pit, 0, nicelabel(row), output_active));
        }
 }
diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index 5462acd..b4a5be0 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -51,7 +51,8 @@ public:
        ///
        void updateBuffer(ParIterator const &, UpdateType);
        ///
-       void addToToc(DocIterator const & di, bool output_active) const;
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
        ///
        InsetMathHull & operator=(InsetMathHull const &);
        ///
diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp
index d2d3cba..f3ba2b4 100644
--- a/src/mathed/MathMacroTemplate.cpp
+++ b/src/mathed/MathMacroTemplate.cpp
@@ -34,6 +34,7 @@
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "Lexer.h"
+#include "TocBackend.h"
 
 #include "frontends/Painter.h"
 
@@ -1383,4 +1384,17 @@ string MathMacroTemplate::contextMenuName() const
        return "context-math-macro-definition";
 }
 
+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));
+}
+
+
 } // namespace lyx
diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h
index 366c654..b0c3018 100644
--- a/src/mathed/MathMacroTemplate.h
+++ b/src/mathed/MathMacroTemplate.h
@@ -103,6 +103,9 @@ public:
        void infoize(odocstream & os) const;
        ///
        std::string contextMenuName() const;
+       ///
+       void addToToc(DocIterator const & di, bool output_active,
+                                 UpdateType utype) const;
 protected:
        ///
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);

Reply via email to