From e11a3cb8953d709760cf9e6250e549a956d9fb2c Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Mon, 9 Jan 2017 13:28:48 +0100 Subject: [PATCH] Remove some hardcoded addToToc: note, footnote, marginalnote, branch Define their Toc from the layout instead. --- lib/layouts/stdfloats.inc | 4 ++++ lib/layouts/stdinsets.inc | 19 +++++++++++++++++ src/TocBackend.h | 25 +++++++++++++--------- src/frontends/qt4/qt_helpers.cpp | 36 ++++++++++---------------------- src/insets/InsetBranch.cpp | 18 +++------------- src/insets/InsetBranch.h | 3 +-- src/insets/InsetCollapsable.cpp | 27 ++++++++++++++++++++++++ src/insets/InsetCollapsable.h | 4 ++++ src/insets/InsetFlex.cpp | 25 ---------------------- src/insets/InsetFlex.h | 3 --- src/insets/InsetFoot.cpp | 18 ---------------- src/insets/InsetFoot.h | 3 --- src/insets/InsetMarginal.cpp | 15 ------------- src/insets/InsetMarginal.h | 3 --- src/insets/InsetNote.cpp | 20 ------------------ src/insets/InsetNote.h | 3 --- 16 files changed, 84 insertions(+), 142 deletions(-) diff --git a/lib/layouts/stdfloats.inc b/lib/layouts/stdfloats.inc index 63a8059ffa..36e4fe656d 100644 --- a/lib/layouts/stdfloats.inc +++ b/lib/layouts/stdfloats.inc @@ -6,6 +6,10 @@ Format 62 +OutlinerName table "Tables" #no AddToToc (built-in) +OutlinerName figure "Figures" #no AddToToc (built-in) +OutlinerName algorithm "Algorithms" #no AddToToc (built-in) + Float Type table GuiName Table diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index af5bc16f20..ed5fe40c0c 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -8,6 +8,13 @@ Format 62 Provides stdinsets 1 +OutlinerName marginalnote "Marginal notes" +OutlinerName footnote "Footnotes" +OutlinerName note "Notes" +OutlinerName branch "Branches" +OutlinerName index "Index Entries" #no AddToToc (built-in) +OutlinerName listing "Listings" #no AddToToc (built-in) + InsetLayout Marginal LabelString margin LatexType command @@ -35,6 +42,8 @@ InsetLayout Marginal font-style: normal; } EndHTMLStyle + AddToToc marginalnote + IsTocCaption true End InsetLayout Foot @@ -76,6 +85,8 @@ InsetLayout Foot padding: 1em; } EndHTMLStyle + AddToToc footnote + IsTocCaption true End InsetLayout Foot:InTitle @@ -130,6 +141,8 @@ InsetLayout Note:Comment display: none; } EndHTMLStyle + AddToToc note + IsTocCaption true End @@ -144,6 +157,8 @@ InsetLayout Note:Note EndFont MultiPar true # Not output for XHTML + AddToToc note + IsTocCaption true End @@ -172,6 +187,8 @@ InsetLayout Note:Greyedout } EndHTMLStyle HTMLIsBlock false + AddToToc note + IsTocCaption true End InsetLayout ERT @@ -338,6 +355,8 @@ InsetLayout Branch MultiPar true InToc true HTMLIsBlock false + AddToToc branch + IsTocCaption true End InsetLayout Index diff --git a/src/TocBackend.h b/src/TocBackend.h index 08754b90b0..e13773fa23 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -38,26 +38,31 @@ class Buffer; * I leave this for documentation purposes for the moment. * enum TocType { +// Non-customizable (does not use TocBuilder) + //The following is used for XHTML output TABLE_OF_CONTENTS,//"tableofcontents" + CHANGE,//"change" + //The following is used for XHTML output + CITATION,//"citation" + LABEL,//"label" + SENSELESS,//"senseless" +// Built-in but customizable CHILD,//"child" GRAPHICS,//"graphics" - NOTE,//"note" - BRANCH,//"branch" - CHANGE,//"change" - LABEL,//"label" - CITATION,//"citation" EQUATION,//"equation" - FOOTNOTE,//"footnote" - MARGINAL_NOTE,//"marginalnote" INDEX,//"index", "index:" (from interface) NOMENCL,//"nomencl" LISTING,//"listings" + //The following are used for XHTML output FLOAT,//"figure", "table", "algorithm", user-defined (from layout?) MATH_MACRO,//"math-macro" EXTERNAL,//"external" - SENSELESS,//"senseless" - USER_DEFINED,//any value defined in the layouts - TOC_TYPE_COUNT +// Defined in layouts + NOTE,//"note" + FOOTNOTE,//"footnote" + MARGINAL_NOTE,//"marginalnote" + BRANCH,//"branch" + USER_DEFINED //any value defined in the layouts } */ diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index fc1ddb4600..2237d7d507 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -598,9 +598,18 @@ QStringList fileFilters(QString const & desc) QString guiName(string const & type, BufferParams const & bp) { - // FIXME: hardcoded + // Hardcoded types if (type == "tableofcontents") return qt_("Table of Contents"); + if (type == "change") + return qt_("Changes"); + if (type == "senseless") + return qt_("Senseless"); + if (type == "citation") + return qt_("Citations"); + if (type == "label") + return qt_("Labels and References"); + // Customizable, but the corresponding insets have no layout definition if (type == "child") return qt_("Child Documents"); if (type == "graphics") @@ -609,30 +618,11 @@ QString guiName(string const & type, BufferParams const & bp) return qt_("Equations"); if (type == "external") return qt_("External material"); - if (type == "footnote") - return qt_("Footnotes"); - if (type == "listing") - return qt_("Listings"); - if (type == "index") - 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") - return qt_("Notes"); - if (type == "citation") - return qt_("Citations"); - if (type == "label") - return qt_("Labels and References"); - if (type == "branch") - return qt_("Branches"); - if (type == "change") - return qt_("Changes"); - if (type == "senseless") - return qt_("Senseless"); + if (prefixIs(type, "index:")) { string const itype = split(type, ':'); IndicesList const & indiceslist = bp.indiceslist(); @@ -643,10 +633,6 @@ QString guiName(string const & type, BufferParams const & bp) return toqstr(bformat(_("Index Entries (%1$s)"), indextype)); } - FloatList const & floats = bp.documentClass().floats(); - if (floats.typeExist(type)) - return qt_(floats.getType(type).listName()); - return toqstr(bp.documentClass().outlinerName(type)); } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index e22555ba79..3cde0615a1 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -385,22 +385,10 @@ void InsetBranch::string2params(string const & in, InsetBranchParams & params) } -void InsetBranch::addToToc(DocIterator const & cpit, bool output_active, - UpdateType utype) const +void InsetBranch::updateBuffer(ParIterator const & it, UpdateType utype) { - DocIterator pit = cpit; - pit.push_back(CursorSlice(const_cast(*this))); - - docstring str; - text().forOutliner(str, TOC_ENTRY_LENGTH); - str = params_.branch + (params_.inverted ? " (-):" : ": ") + str; - - shared_ptr toc = buffer().tocBackend().toc("branch"); - toc->push_back(TocItem(pit, 0, str, output_active)); - - // Proceed with the rest of the inset. - bool const doing_output = output_active && producesOutput(); - InsetCollapsable::addToToc(cpit, doing_output, utype); + setLabel(params_.branch + (params_.inverted ? " (-)" : "")); + InsetCollapsable::updateBuffer(it, utype); } diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 83783e71eb..bcb2cd8fd9 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -88,8 +88,7 @@ private: /// std::string contextMenuName() const; /// - void addToToc(DocIterator const & di, bool output_active, - UpdateType utype) const; + void updateBuffer(ParIterator const & it, UpdateType utype); /// void setParams(InsetBranchParams const & params) { params_ = params; } diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index bcf96cc069..fa9f01056a 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -24,6 +24,7 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "TocBackend.h" #include "frontends/FontMetrics.h" #include "frontends/Painter.h" @@ -660,4 +661,30 @@ bool InsetCollapsable::canPaintChange(BufferView const & bv) const } +void InsetCollapsable::addToToc(DocIterator const & cpit, bool output_active, + UpdateType utype) const +{ + bool doing_output = output_active && producesOutput(); + 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(*this))); + docstring const label = getLabel(); + b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active); + // Proceed with the rest of the inset. + InsetText::addToToc(cpit, doing_output, utype); + if (layout.isTocCaption()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH); + b.argumentItem(str); + } + b.pop(); + } else + InsetText::addToToc(cpit, doing_output, utype); +} + + + } // namespace lyx diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 98df7eced2..016d73207f 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -150,6 +150,10 @@ public: std::string contextMenu(BufferView const & bv, int x, int y) const; /// std::string contextMenuName() const; + /// + void addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const; //override + protected: /// void doDispatch(Cursor & cur, FuncRequest & cmd); diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index ee3b7c89c4..0b14973faa 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -23,7 +23,6 @@ #include "Lexer.h" #include "ParIterator.h" #include "TextClass.h" -#include "TocBackend.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -166,28 +165,4 @@ 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(*this))); - docstring const label = getLabel(); - b.pushItem(pit, label + (label.empty() ? "" : ": "), output_active); - // Proceed with the rest of the inset. - InsetCollapsable::addToToc(cpit, output_active, utype); - if (layout.isTocCaption()) { - docstring str; - text().forOutliner(str, TOC_ENTRY_LENGTH); - b.argumentItem(str); - } - b.pop(); - } else - InsetCollapsable::addToToc(cpit, output_active, utype); -} - - } // namespace lyx diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index 0f5a93ad15..82770026c3 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -45,9 +45,6 @@ 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: /// diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index e87de41b99..cb7462d503 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -75,24 +75,6 @@ void InsetFoot::updateBuffer(ParIterator const & it, UpdateType utype) } -void InsetFoot::addToToc(DocIterator const & cpit, bool output_active, - UpdateType utype) const -{ - DocIterator pit = cpit; - pit.push_back(CursorSlice(const_cast(*this))); - - docstring str; - text().forOutliner(str, TOC_ENTRY_LENGTH); - str = custom_label_ + ": " + str; - - shared_ptr toc = buffer().tocBackend().toc("footnote"); - toc->push_back(TocItem(pit, 0, str, output_active)); - - // Proceed with the rest of the inset. - InsetFootlike::addToToc(cpit, output_active, utype); -} - - docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const { if (isOpen(bv)) diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h index f145d5ce16..67110d2574 100644 --- a/src/insets/InsetFoot.h +++ b/src/insets/InsetFoot.h @@ -39,9 +39,6 @@ private: /// Update the counters of this inset and of its contents void updateBuffer(ParIterator const &, UpdateType); /// - void addToToc(DocIterator const & di, bool output_active, - UpdateType utype) const; - /// docstring toolTip(BufferView const & bv, int x, int y) const; /// Inset * clone() const { return new InsetFoot(*this); } diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index 1c1df328e9..3dfcf7d048 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -52,19 +52,4 @@ int InsetMarginal::docbook(odocstream & os, } -void InsetMarginal::addToToc(DocIterator const & cpit, bool output_active, - UpdateType utype) const -{ - DocIterator pit = cpit; - pit.push_back(CursorSlice(const_cast(*this))); - - docstring str; - text().forOutliner(str, TOC_ENTRY_LENGTH); - std::shared_ptr toc = buffer().tocBackend().toc("marginalnote"); - toc->push_back(TocItem(pit, 0, str, output_active)); - - // Proceed with the rest of the inset. - InsetFootlike::addToToc(cpit, output_active, utype); -} - } // namespace lyx diff --git a/src/insets/InsetMarginal.h b/src/insets/InsetMarginal.h index 939c0d23c4..008a3dd039 100644 --- a/src/insets/InsetMarginal.h +++ b/src/insets/InsetMarginal.h @@ -35,9 +35,6 @@ public: size_t max_length = INT_MAX) const; /// int docbook(odocstream &, OutputParams const & runparams) const; - /// - void addToToc(DocIterator const & di, bool output_active, - UpdateType utype) const; /// Is the content of this inset part of the immediate (visible) text sequence? bool isPartOfTextSequence() const { return false; } private: diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index d5e7fb324c..77323e6efe 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -208,26 +208,6 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd, } -void InsetNote::addToToc(DocIterator const & cpit, bool output_active, - UpdateType utype) const -{ - DocIterator pit = cpit; - pit.push_back(CursorSlice(const_cast(*this))); - - InsetLayout const & il = getLayout(); - docstring str; - text().forOutliner(str, TOC_ENTRY_LENGTH); - str = translateIfPossible(il.labelstring()) + ": " + str; - - shared_ptr toc = buffer().tocBackend().toc("note"); - toc->push_back(TocItem(pit, 0, str, output_active)); - - // Proceed with the rest of the inset. - bool doing_output = output_active && producesOutput(); - InsetCollapsable::addToToc(cpit, doing_output, utype); -} - - bool InsetNote::isMacroScope() const { // LyX note has no latex output diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index c80d61b27d..d6cc0a6510 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -96,9 +96,6 @@ private: /// bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; /// - void addToToc(DocIterator const & di, bool output_active, - UpdateType utype) const; - /// void doDispatch(Cursor & cur, FuncRequest & cmd); /// Inset * clone() const { return new InsetNote(*this); }