commit 28dfc48fb2e24bb8c9d913535b955437b73ca9af Author: Guillaume Munch <g...@lyx.org> Date: Sun Nov 22 22:48:24 2015 +0000
Implement AddToToc layout command for Flex insets Enables TOC for FiXme, ToDo, Knitr, Sweave (#7790) --- src/TextClass.cpp | 4 ++-- src/frontends/qt4/qt_helpers.cpp | 3 ++- src/insets/Inset.cpp | 1 + src/insets/InsetCollapsable.cpp | 11 +++++++++-- src/insets/InsetCollapsable.h | 2 ++ src/insets/InsetFlex.cpp | 26 ++++++++++++++++++++++++++ src/insets/InsetFlex.h | 3 +++ 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 46a96e4..275678a 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -1336,9 +1336,9 @@ docstring TextClass::outlinerName(std::string const & type) const = outliner_names_.find(type); if (it == outliner_names_.end()) { LYXERR0("Missing OutlinerName for " << type << "!"); - return from_utf8(type); + return translateIfPossible(from_utf8(type)); } else - return it->second; + return translateIfPossible(it->second); } diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 88c4ab9..fc1ddb4 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -598,6 +598,7 @@ QStringList fileFilters(QString const & desc) QString guiName(string const & type, BufferParams const & bp) { + // FIXME: hardcoded if (type == "tableofcontents") return qt_("Table of Contents"); if (type == "child") @@ -646,7 +647,7 @@ QString guiName(string const & type, BufferParams const & bp) if (floats.typeExist(type)) return qt_(floats.getType(type).listName()); - return qt_(type); + return toqstr(bp.documentClass().outlinerName(type)); } diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 21d54e0..812aba5 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -31,6 +31,7 @@ #include "output_xhtml.h" #include "Text.h" #include "TextClass.h" +#include "TocBackend.h" #include "frontends/Application.h" #include "frontends/Painter.h" diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 7a4c999..bcf96cc 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -576,11 +576,18 @@ void InsetCollapsable::setLabel(docstring const & l) } -docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const +docstring InsetCollapsable::getLabel() const { InsetLayout const & il = getLayout(); - docstring const label = labelstring_.empty() ? + return labelstring_.empty() ? translateIfPossible(il.labelstring()) : labelstring_; +} + + +docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const +{ + InsetLayout const & il = getLayout(); + docstring const label = getLabel(); if (!il.contentaslabel() || geometry(bv) != ButtonOnly) return label; return getNewLabel(label); diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index c7b6d65..98df7ec 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -75,6 +75,8 @@ public: /// void setLabel(docstring const & l); /// + docstring getLabel() const; + /// virtual void setButtonLabel() {} /// virtual docstring const buttonLabel(BufferView const &) const; diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 0b14973..18f3417 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -23,6 +23,7 @@ #include "Lexer.h" #include "ParIterator.h" #include "TextClass.h" +#include "TocBackend.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -165,4 +166,29 @@ void InsetFlex::updateBuffer(ParIterator const & it, UpdateType utype) } +void InsetFlex::addToToc(DocIterator const & cpit, bool output_active, + UpdateType utype) const +{ + InsetLayout const & layout = getLayout(); + if (layout.addToToc()) { + TocBuilder & b = buffer().tocBackend().builder(layout.tocType()); + // Cursor inside the inset + DocIterator pit = cpit; + pit.push_back(CursorSlice(const_cast<InsetFlex &>(*this))); + docstring str; + str = getLabel(); + if (layout.isTocCaption()) { + if (!str.empty()) + str += ": "; + text().forOutliner(str, TOC_ENTRY_LENGTH); + } + b.pushItem(pit, str, output_active); + // Proceed with the rest of the inset. + InsetCollapsable::addToToc(cpit, output_active, utype); + b.pop(); + } else + InsetCollapsable::addToToc(cpit, output_active, utype); +} + + } // namespace lyx diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index 8277002..0f5a93a 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -45,6 +45,9 @@ public: void doDispatch(Cursor & cur, FuncRequest & cmd); /// void updateBuffer(ParIterator const & it, UpdateType utype); + /// + void addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const; //override protected: ///