commit e11a3cb8953d709760cf9e6250e549a956d9fb2c
Author: Guillaume Munch <[email protected]>
Date: Mon Jan 9 13:28:48 2017 +0100
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 63a8059..36e4fe6 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 af5bc16..ed5fe40 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 08754b9..e13773f 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"
- CHILD,//"child"
- GRAPHICS,//"graphics"
- NOTE,//"note"
- BRANCH,//"branch"
CHANGE,//"change"
- LABEL,//"label"
+ //The following is used for XHTML output
CITATION,//"citation"
+ LABEL,//"label"
+ SENSELESS,//"senseless"
+// Built-in but customizable
+ CHILD,//"child"
+ GRAPHICS,//"graphics"
EQUATION,//"equation"
- FOOTNOTE,//"footnote"
- MARGINAL_NOTE,//"marginalnote"
INDEX,//"index", "index:<user-str>" (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 fc1ddb4..2237d7d 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 e22555b..3cde061 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<InsetBranch &>(*this)));
-
- docstring str;
- text().forOutliner(str, TOC_ENTRY_LENGTH);
- str = params_.branch + (params_.inverted ? " (-):" : ": ") + str;
-
- shared_ptr<Toc> 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 83783e7..bcb2cd8 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 bcf96cc..fa9f010 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<InsetCollapsable
&>(*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 98df7ec..016d732 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 ee3b7c8..0b14973 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<InsetFlex &>(*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 0f5a93a..8277002 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 e87de41..cb7462d 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<InsetFoot &>(*this)));
-
- docstring str;
- text().forOutliner(str, TOC_ENTRY_LENGTH);
- str = custom_label_ + ": " + str;
-
- shared_ptr<Toc> 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 f145d5c..67110d2 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 1c1df32..3dfcf7d 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<InsetMarginal &>(*this)));
-
- docstring str;
- text().forOutliner(str, TOC_ENTRY_LENGTH);
- std::shared_ptr<Toc> 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 939c0d2..008a3dd 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 d5e7fb3..77323e6 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<InsetNote &>(*this)));
-
- InsetLayout const & il = getLayout();
- docstring str;
- text().forOutliner(str, TOC_ENTRY_LENGTH);
- str = translateIfPossible(il.labelstring()) + ": " + str;
-
- shared_ptr<Toc> 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 c80d61b..d6cc0a6 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); }