The branch, biblatex2, has been updated. - Log -----------------------------------------------------------------
commit 425c190d623daeb6d05bce1aa2244b548225305a Merge: a751c5b 578f964 Author: Juergen Spitzmueller <[email protected]> Date: Mon Jan 9 20:04:32 2017 +0100 merge recent changes from master commit 578f964d9f472e804a4b80884850d0cd6c1dd5dd Author: Scott Kostyshak <[email protected]> Date: Mon Jan 9 13:48:32 2017 -0500 Fix typo in Development.lyx diff --git a/lib/doc/Development.lyx b/lib/doc/Development.lyx index 58d0f8f..9232eea 100644 --- a/lib/doc/Development.lyx +++ b/lib/doc/Development.lyx @@ -1,5 +1,5 @@ #LyX 2.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 515 +\lyxformat 527 \begin_document \begin_header \save_transient_properties true @@ -78,7 +78,8 @@ logicalmkup \tocdepth 4 \paragraph_separation indent \paragraph_indentation default -\quotes_language english +\quotes_style english +\dynamic_quotes 0 \papercolumns 1 \papersides 2 \paperpagestyle headings @@ -766,7 +767,7 @@ updatedocs.py \end_layout \begin_layout Standard -Note that we do not automatically any local layout used in the +Note that we do not automatically update any local layout used in the \begin_inset Flex Code status collapsed commit ffb195b5e9fa8f533348c9d157a0846cd62add73 Author: Juergen Spitzmueller <[email protected]> Date: Mon Jan 9 18:54:49 2017 +0100 Clarify layout and add some tooltips Addresses: #9795 diff --git a/src/frontends/qt4/ui/BibtexAddUi.ui b/src/frontends/qt4/ui/BibtexAddUi.ui index 4b7353e..e8ee451 100644 --- a/src/frontends/qt4/ui/BibtexAddUi.ui +++ b/src/frontends/qt4/ui/BibtexAddUi.ui @@ -1,106 +1,154 @@ -<ui version="4.0" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> <class>BibtexAddUi</class> - <widget class="QDialog" name="BibtexAddUi" > - <property name="geometry" > + <widget class="QDialog" name="BibtexAddUi"> + <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>221</width> - <height>321</height> + <width>328</width> + <height>377</height> </rect> </property> - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>1</vsizetype> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="windowTitle" > + <property name="windowTitle"> <string>LyX: Add BibTeX Database</string> </property> - <property name="sizeGripEnabled" > + <property name="sizeGripEnabled"> <bool>true</bool> </property> - <layout class="QGridLayout" > - <property name="margin" > - <number>9</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item row="2" column="2" > - <widget class="QPushButton" name="rescanPB" > - <property name="toolTip" > - <string>Scan for new databases and styles</string> - </property> - <property name="text" > - <string>&Rescan</string> - </property> - </widget> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="0" column="0"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="bibLA"> + <property name="text"> + <string>&Databases found by LaTeX:</string> + </property> + <property name="buddy"> + <cstring>bibLW</cstring> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QListWidget" name="bibLW"> + <property name="toolTip"> + <string>This list consists of all databases that are indexed by LaTeX and thus are found without a file path. This is usually everything in the bib/ subdirectory of LaTeX's texmf tree. If you want to reuse your own database, this is the place you should store it.</string> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + </widget> + </item> + <item row="2" column="0"> + <spacer> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>162</width> + <height>29</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="1"> + <widget class="QPushButton" name="rescanPB"> + <property name="toolTip"> + <string>Rescan LaTeX's index for new databases and styles</string> + </property> + <property name="text"> + <string>&Rescan</string> + </property> + </widget> + </item> + </layout> </item> - <item row="2" column="0" > - <widget class="QPushButton" name="browsePB" > - <property name="text" > - <string>&Browse...</string> - </property> - <property name="autoDefault" > - <bool>false</bool> - </property> - <property name="default" > - <bool>true</bool> - </property> - </widget> + <item row="1" column="0"> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QLabel" name="localLA"> + <property name="toolTip"> + <string>Here you can enter a local BibTeX database name or browse your directory.</string> + </property> + <property name="text"> + <string>&Local databases:</string> + </property> + <property name="buddy"> + <cstring>bibED</cstring> + </property> + </widget> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="bibED"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>Here you can enter a local BibTeX database name</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="browsePB"> + <property name="toolTip"> + <string>Browse your local directory</string> + </property> + <property name="text"> + <string>&Browse...</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> </item> - <item row="2" column="1" > - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>21</width> - <height>29</height> - </size> + <item row="2" column="0"> + <layout class="QHBoxLayout"> + <property name="spacing"> + <number>6</number> </property> - </spacer> - </item> - <item row="1" column="0" colspan="3" > - <widget class="QLineEdit" name="bibED" > - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>7</hsizetype> - <vsizetype>0</vsizetype> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <property name="leftMargin"> + <number>0</number> </property> - <property name="toolTip" > - <string>Enter BibTeX database name</string> + <property name="topMargin"> + <number>0</number> </property> - </widget> - </item> - <item row="3" column="0" colspan="3" > - <layout class="QHBoxLayout" > - <property name="margin" > + <property name="rightMargin"> <number>0</number> </property> - <property name="spacing" > - <number>6</number> + <property name="bottomMargin"> + <number>0</number> </property> <item> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeType" > + <property name="sizeType"> <enum>QSizePolicy::Expanding</enum> </property> - <property name="sizeHint" > + <property name="sizeHint" stdset="0"> <size> <width>20</width> <height>20</height> @@ -109,37 +157,30 @@ </spacer> </item> <item> - <widget class="QPushButton" name="addPB" > - <property name="text" > + <widget class="QPushButton" name="addPB"> + <property name="text"> <string>&Add</string> </property> - <property name="autoDefault" > + <property name="autoDefault"> <bool>false</bool> </property> - <property name="default" > + <property name="default"> <bool>true</bool> </property> </widget> </item> <item> - <widget class="QPushButton" name="closePB" > - <property name="text" > + <widget class="QPushButton" name="closePB"> + <property name="text"> <string>Cancel</string> </property> - <property name="autoDefault" > + <property name="autoDefault"> <bool>false</bool> </property> </widget> </item> </layout> </item> - <item row="0" column="0" colspan="3" > - <widget class="QListWidget" name="bibLW" > - <property name="selectionMode" > - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - </widget> - </item> </layout> </widget> <tabstops> @@ -150,7 +191,7 @@ <tabstop>closePB</tabstop> </tabstops> <includes> - <include location="local" >qt_i18n.h</include> + <include location="local">qt_i18n.h</include> </includes> <resources/> <connections/> commit 5fdc577badb1cb133d6a0dc7d831bb1f82576adb Author: Guillaume Munch <[email protected]> Date: Mon Jan 9 17:37:50 2017 +0100 Improve the list of equations Also convert other Tocs to TocBuilder when trivial, to make them customisable diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 13fddd7..29a0fbf 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -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(); } diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 00c304a..6e0baff 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -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(); } diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 4d850b5..d1458c0 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -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(); } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 7a35edd..4e44ec8 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -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()); } } } diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 455b09f..a328d27 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -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(); } diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 7395b6c..fe4f7fb 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -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(); } diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 807475e..61e0210 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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(); } diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index 2ac8703..2c6cbf7 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -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(); } 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. 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); } commit f0663e3ce4216bd8ef1a43b1e70a921ce2fec988 Author: Guillaume Munch <[email protected]> Date: Sun Jan 8 21:55:56 2017 +0100 Document AddToToc diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index abc8dbc..3572367 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -1,4 +1,4 @@ -#LyX 2.2 created this file. For more info see http://www.lyx.org/ +#LyX 2.3 created this file. For more info see http://www.lyx.org/ \lyxformat 508 \begin_document \begin_header @@ -123,6 +123,7 @@ logicalmkup \html_css_as_file 0 \html_be_strict true \author -712698321 "Jürgen Spitzmüller" +\author 2047637253 "Guillaume Munch" \author 2089657418 "Usti" \end_header @@ -9378,6 +9379,76 @@ status collapsed \end_inset ] Deletes an existing style. +\change_inserted 2047637253 1483900342 + +\end_layout + +\begin_layout Description + +\change_inserted 2047637253 1483900479 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900346 +OutlinerName +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900369 +<type> +\end_layout + +\end_inset + +] [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900418 +<string> +\end_layout + +\end_inset + +] Define a new table of contents with type +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900414 +<type> +\end_layout + +\end_inset + + and name +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900419 +<string> +\end_layout + +\end_inset + +. + See also the AddToToc commands. +\change_unchanged + \end_layout \begin_layout Description @@ -10643,6 +10714,38 @@ where the following commands are allowed: \end_layout \begin_layout Description + +\change_inserted 2047637253 1483963019 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483901753 +AddToToc +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483963007 +string +\end_layout + +\end_inset + +=""] This paragraph will appear in the table of contents of the given type. + An empty string disables. + See also the OutlinerName and the IsTocCaption commands. + Default: disabled. +\end_layout + +\begin_layout Description \begin_inset Flex Code status collapsed @@ -11472,6 +11575,59 @@ Defines individual characters that should be output in raw form, meaning arguments. That is, arguments do not inherit PassThruChars from their parent inset or layout. +\change_inserted 2047637253 1483899840 + +\end_layout + +\begin_layout Itemize + +\change_inserted 2047637253 1483900841 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900841 +IsTocCaption +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900841 + +\emph on +0 +\end_layout + +\end_inset + +, +\begin_inset space \thinspace{} +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900841 +1 +\end_layout + +\end_inset + +] If this is set to 1, the argument will output its content in the corresponding + item in the table of contents. + See AddToToc. +\change_unchanged + \end_layout \begin_layout Standard @@ -12333,6 +12489,55 @@ TitleLatexName \end_layout \begin_layout Description + +\change_inserted 2047637253 1483902824 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483902211 +IsTocCaption +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483902211 + +\emph on +0 +\end_layout + +\end_inset + +, +\begin_inset space \thinspace{} +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483902211 +1 +\end_layout + +\end_inset + +] If this is set to 1 and AddToToc is enabled, the paragraph adds a summary + of its contents in its item in the table of contents. + Otherwise, only the label, if it exists, appears. +\end_layout + +\begin_layout Description \begin_inset Flex Code status collapsed @@ -17283,6 +17488,39 @@ InsetLayout \end_layout \begin_layout Description + +\change_inserted 2047637253 1483963036 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900123 +AddToToc +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483962897 +string +\end_layout + +\end_inset + +=""] This inset will appear in the table of contents of the given type. + An empty string disables. + See also the OutlinerName and the IsTocCaption commands. + This is only implemented for Flex insets. + Default: disabled. +\end_layout + +\begin_layout Description \begin_inset Flex Code status collapsed @@ -18142,11 +18380,68 @@ status collapsed \end_inset ] Whether to include the contents of this inset in the strings generated - for the `Outline' pane. + for the `Outline' pane +\change_inserted 2047637253 1483900773 + for all table of contents, regardless of the AddToToc setting +\change_unchanged +. One would not, for example, want the content of a footnote in a section header to be included in the TOC displayed in the outline, but one would normally want the content of a character style displayed. Default is false: not to include. +\change_inserted 2047637253 1483900609 + +\end_layout + +\begin_layout Description + +\change_inserted 2047637253 1483901257 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900725 +IsTocCaption +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900620 + +\emph on +0 +\end_layout + +\end_inset + +, +\begin_inset space \thinspace{} +\end_inset + + +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483900620 +1 +\end_layout + +\end_inset + +] If this is set to 1 and AddToToc is enabled, the inset adds a summary + of its contents in its item in the table of contents. + Otherwise, only the label appears. +\change_unchanged + \end_layout \begin_layout Description commit 68109443f3738b89574cfc82bc30b14e0c31a8be Author: Guillaume Munch <[email protected]> Date: Sun Jan 8 21:57:02 2017 +0100 Implement AddToToc for paragraph layouts Enables table of Theorems & Definitions diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index ba101e4..6d50f27 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3333,11 +3333,11 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out void Paragraph::forOutliner(docstring & os, size_t const maxlen, - bool const shorten) const + bool const shorten, bool const label) const { size_t tmplen = shorten ? maxlen + 1 : maxlen; - if (!d->params_.labelString().empty()) - os += d->params_.labelString() + ' '; + if (label && !labelString().empty()) + os += labelString() + ' '; for (pos_type i = 0; i < size() && os.length() < tmplen; ++i) { if (isDeleted(i)) continue; diff --git a/src/Paragraph.h b/src/Paragraph.h index 2133d8c..813640e 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -181,8 +181,8 @@ public: int options = AS_STR_NONE, const OutputParams *runparams = 0) const; /// - void forOutliner(docstring &, size_t const maxlen, - bool const shorten = true) const; + void forOutliner(docstring &, size_t maxlen, bool shorten = true, + bool label = true) const; /// void write(std::ostream &, BufferParams const &, diff --git a/src/Text.cpp b/src/Text.cpp index 8e0d1be..8d08baa 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -240,6 +240,21 @@ bool Text::isFirstInSequence(pit_type par_offset) const } +pit_type Text::lastInSequence(pit_type pit) const +{ + depth_type const depth = pars_[pit].getDepth(); + pit_type newpit = pit; + + while (size_t(newpit + 1) < pars_.size() && + (pars_[newpit + 1].getDepth() > depth || + (pars_[newpit + 1].getDepth() == depth && + pars_[newpit + 1].layout() == pars_[pit].layout()))) + ++newpit; + + return newpit; +} + + int Text::getTocLevel(pit_type par_offset) const { Paragraph const & par = pars_[par_offset]; @@ -2042,20 +2057,36 @@ docstring Text::asString(pit_type beg, pit_type end, int options) const void Text::shortenForOutliner(docstring & str, size_t const maxlen) { support::truncateWithEllipsis(str, maxlen); - docstring::iterator it = str.begin(); - docstring::iterator end = str.end(); - for (; it != end; ++it) - if ((*it) == L'\n' || (*it) == L'\t') - (*it) = L' '; + for (char_type & c : str) + if (c == L'\n' || c == L'\t') + c = L' '; } void Text::forOutliner(docstring & os, size_t const maxlen, - bool const shorten) const + bool const shorten) const +{ + pit_type end = pars_.size() - 1; + if (0 <= end && !pars_[0].labelString().empty()) + os += pars_[0].labelString() + ' '; + forOutliner(os, maxlen, 0, end, shorten); +} + + +void Text::forOutliner(docstring & os, size_t const maxlen, + pit_type pit_start, pit_type pit_end, + bool const shorten) const { size_t tmplen = shorten ? maxlen + 1 : maxlen; - for (size_t i = 0; i != pars_.size() && os.length() < tmplen; ++i) - pars_[i].forOutliner(os, tmplen, false); + pit_type end = min(size_t(pit_end), pars_.size() - 1); + bool first = true; + for (pit_type i = pit_start; i <= end && os.length() < tmplen; ++i) { + if (!first) + os += ' '; + // This function lets the first label be treated separately + pars_[i].forOutliner(os, tmplen, false, !first); + first = false; + } if (shorten) shortenForOutliner(os, maxlen); } diff --git a/src/Text.h b/src/Text.h index bdf2169..f49c8e2 100644 --- a/src/Text.h +++ b/src/Text.h @@ -130,9 +130,13 @@ public: /// Appends a possibly abbreviated representation of our text to \param os, /// where \param maxlen defines the maximum size of \param os. If \param - /// shorten is true, then os is shortened as above - void forOutliner(docstring & os, size_t const maxlen, - bool const shorten = true) const; + /// shorten is true, then os is shortened as above. + void forOutliner(docstring & os, size_t maxlen, bool shorten = true) const; + /// Appends a possibly abbreviated representation of our text, from + /// start to end, to \param os, where \param maxlen defines the + /// maximum size of \param os. Omits the label of the first paragraph. + void forOutliner(docstring & os, size_t maxlen, pit_type start, pit_type end, + bool shorten = true) const; /// insert a character at cursor position /// FIXME: replace Cursor with DocIterator. @@ -329,6 +333,9 @@ public: pit_type outerHook(pit_type pit) const; /// Is it the first par with same depth and layout? bool isFirstInSequence(pit_type pit) const; + /// Return the last paragraph with same depth and layout, or a strictly + /// greater depth + pit_type lastInSequence(pit_type pit) const; /// Is this paragraph in the table of contents? int getTocLevel(pit_type pit) const; /// Get the font of the "environment" of paragraph \p par_offset in \p pars. diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index f490c35..6c7c1f9 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -200,7 +200,7 @@ void TocBuilder::argumentItem(docstring const & arg_str) TocItem & item = (*toc_)[stack_.top().pos]; docstring const & str = item.str(); string const & delim = - str.empty() ? "" : stack_.top().is_captioned ? ", " : ": "; + (str.empty() || !stack_.top().is_captioned) ? "" : ", "; item.str(str + from_ascii(delim) + arg_str); stack_.top().is_captioned = true; } diff --git a/src/TocBackend.h b/src/TocBackend.h index b851d68..08754b9 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -56,6 +56,7 @@ enum TocType { MATH_MACRO,//"math-macro" EXTERNAL,//"external" SENSELESS,//"senseless" + USER_DEFINED,//any value defined in the layouts TOC_TYPE_COUNT } */ @@ -119,16 +120,16 @@ private: class TocBuilder { public: - TocBuilder(std::shared_ptr<Toc> const toc); - /// When entering a float or flex (AddToToc) + TocBuilder(std::shared_ptr<Toc> toc); + /// When entering a float or flex or paragraph (with AddToToc) void pushItem(DocIterator const & dit, docstring const & s, bool output_active, bool is_captioned = false); /// When encountering a float caption void captionItem(DocIterator const & dit, docstring const & s, bool output_active); - /// When encountering an argument (isTocCaption) + /// When encountering an argument (with isTocCaption) for flex or paragraph void argumentItem(docstring const & arg_str); - /// When exiting a float or flex + /// When exiting a float or flex or paragraph void pop(); private: TocBuilder(){} diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 05cbb29..ee3b7c8 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -175,7 +175,8 @@ void InsetFlex::addToToc(DocIterator const & cpit, bool output_active, // Cursor inside the inset DocIterator pit = cpit; pit.push_back(CursorSlice(const_cast<InsetFlex &>(*this))); - b.pushItem(pit, getLabel(), output_active); + 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()) { diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 607f7f5..db6b744 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -851,13 +851,29 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, // can't hurt too much to do it again bool const doing_output = output_active && producesOutput(); - // For each paragraph, traverse its insets and let them add - // their toc items + // For each paragraph, + // * Add a toc item for the paragraph if it is AddToToc--merging adjacent + // paragraphs as needed. + // * Traverse its insets and let them add their toc items + // * Compute the main table of contents (this is hardcoded) + // * Add the list of changes ParagraphList const & pars = paragraphs(); pit_type pend = paragraphs().size(); + // Record pairs {start,end} of where a toc item was opened for a paragraph + // and where it must be closed + stack<pair<pit_type, pit_type>> addtotoc_stack; + for (pit_type pit = 0; pit != pend; ++pit) { Paragraph const & par = pars[pit]; dit.pit() = pit; + dit.pos() = 0; + + // Custom AddToToc in paragraph layouts (i.e. theorems) + if (par.layout().addToToc() && text().isFirstInSequence(pit)) { + pit_type end = openAddToTocForParagraph(pit, dit, output_active); + addtotoc_stack.push({pit, end}); + } + // if we find an optarg, we'll save it for use later. InsetText const * arginset = 0; InsetList::const_iterator it = par.insetList().begin(); @@ -870,7 +886,16 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, if (inset.lyxCode() == ARG_CODE) arginset = inset.asInsetText(); } - // now the toc entry for the paragraph + + // End custom AddToToc in paragraph layouts + while (!addtotoc_stack.empty() && addtotoc_stack.top().second == pit) { + // execute the closing function + closeAddToTocForParagraph(addtotoc_stack.top().first, + addtotoc_stack.top().second); + addtotoc_stack.pop(); + } + + // now the toc entry for the paragraph in the main table of contents int const toclevel = text().getTocLevel(pit); if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { // insert this into the table of contents @@ -895,6 +920,31 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, } +pit_type InsetText::openAddToTocForParagraph(pit_type pit, + DocIterator const & dit, + bool output_active) const +{ + Paragraph const & par = paragraphs()[pit]; + TocBuilder & b = buffer().tocBackend().builder(par.layout().tocType()); + docstring const label = par.labelString(); + b.pushItem(dit, label + (label.empty() ? "" : " "), output_active); + return text().lastInSequence(pit); +} + + +void InsetText::closeAddToTocForParagraph(pit_type start, pit_type end) const +{ + Paragraph const & par = paragraphs()[start]; + TocBuilder & b = buffer().tocBackend().builder(par.layout().tocType()); + if (par.layout().isTocCaption()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH, start, end); + b.argumentItem(str); + } + b.pop(); +} + + bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur) { if (buffer().isClean()) diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 5bc7c52..8c647fb 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -223,6 +223,13 @@ protected: void iterateForToc(DocIterator const & cdit, bool output_active, UpdateType utype) const; private: + /// Open the toc item for paragraph pit. Returns the paragraph index where + /// it should end. + pit_type openAddToTocForParagraph(pit_type pit, + DocIterator const & dit, + bool output_active) const; + /// Close a toc item opened in start and closed in end + void closeAddToTocForParagraph(pit_type start, pit_type end) const; /// bool drawFrame_; /// commit d6b1dc4724ddf5f1d203da8224073236400b6623 Author: Guillaume Munch <[email protected]> Date: Sun Jan 8 19:19:55 2017 +0100 Update Sweave, Knitr manual and showcase the new Navigate menu Also mention needauth option diff --git a/lib/examples/knitr.lyx b/lib/examples/knitr.lyx index cf6ee09..6e96b2e 100644 --- a/lib/examples/knitr.lyx +++ b/lib/examples/knitr.lyx @@ -1,4 +1,4 @@ -#LyX 2.2 created this file. For more info see http://www.lyx.org/ +#LyX 2.3 created this file. For more info see http://www.lyx.org/ \lyxformat 508 \begin_document \begin_header @@ -69,11 +69,12 @@ knitr \papercolumns 1 \papersides 1 \paperpagestyle default -\tracking_changes false +\tracking_changes true \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false +\author 2047637253 "Guillaume Munch" \end_header \begin_body @@ -203,6 +204,31 @@ knitr \series default ; many of the examples have links to the \SpecialChar LyX source documents. +\change_inserted 2047637253 1483899260 + +\end_layout + +\begin_layout Standard + +\change_inserted 2047637253 1483899275 +Since \SpecialChar LyX + 2.3, it is necessary to enable the use of +\emph on +needauth +\emph default + converters in +\family sans + Preferences\SpecialChar menuseparator +File Handling\SpecialChar menuseparator +Converters +\family default + in order to compile with +\series bold +knitr +\series default +. +\change_unchanged + \end_layout \begin_layout Standard @@ -216,6 +242,64 @@ knitr \end_layout \begin_layout Standard + +\change_inserted 2047637253 1483899195 +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483899204 + +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483899200 +show-off +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483899204 + +rnorm(5) +\end_layout + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483899204 + +df=data.frame(y=rnorm(100), x=1:100) +\end_layout + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483899204 + +summary(lm(y~x, data=df)) +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\begin_layout Standard + +\change_deleted 2047637253 1483899208 \begin_inset ERT status open @@ -247,6 +331,8 @@ summary(lm(y~x, data=df)) \end_inset +\change_unchanged + \end_layout \begin_layout Standard diff --git a/lib/examples/sweave.lyx b/lib/examples/sweave.lyx index bf770be..59d64df 100644 --- a/lib/examples/sweave.lyx +++ b/lib/examples/sweave.lyx @@ -1,4 +1,4 @@ -#LyX 2.2 created this file. For more info see http://www.lyx.org/ +#LyX 2.3 created this file. For more info see http://www.lyx.org/ \lyxformat 508 \begin_document \begin_header @@ -81,24 +81,33 @@ sweave \papercolumns 1 \papersides 1 \paperpagestyle default -\tracking_changes false +\tracking_changes true \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false +\author 2047637253 "Guillaume Munch" \end_header \begin_body \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897614 +\begin_inset Note Note status open \begin_layout Plain Layout -% -\backslash -SweaveOpts{prefix=TRUE,prefix.string=sweave-prefix,keep.source=FALSE} +\change_inserted 2047637253 1483897614 +\begin_inset Flex Sweave Options +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483897614 + +prefix=TRUE,prefix.string=sweave-prefix,keep.source=FALSE \end_layout \end_inset @@ -106,6 +115,13 @@ SweaveOpts{prefix=TRUE,prefix.string=sweave-prefix,keep.source=FALSE} \end_layout +\end_inset + + +\change_unchanged + +\end_layout + \begin_layout Standard \begin_inset ERT status open @@ -239,6 +255,27 @@ https://github.com/downloads/yihui/lyx/sweave.pdf \end_inset . +\change_inserted 2047637253 1483898587 + +\end_layout + +\begin_layout Standard + +\change_inserted 2047637253 1483899123 +Since \SpecialChar LyX + 2.3, it is necessary to enable the use of +\emph on +needauth +\emph default + converters in +\family sans + Preferences\SpecialChar menuseparator +File Handling\SpecialChar menuseparator +Converters +\family default + in order to compile with Sweave. +\change_unchanged + \end_layout \begin_layout Section @@ -306,27 +343,41 @@ bin \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897627 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<where-is-R-bin,eval=FALSE>>= -\end_layout +\change_inserted 2047637253 1483897627 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -R.home('bin') +\change_inserted 2047637253 1483897627 +where-is-R-bin,eval=FALSE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897627 + +R.home('bin') \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -361,27 +412,41 @@ Sweave.sty \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897639 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<sweave-sty,eval=FALSE>>= -\end_layout +\change_inserted 2047637253 1483897639 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -file.path(R.home('share'), 'texmf', 'tex', 'latex') +\change_inserted 2047637253 1483897639 +sweave-sty,eval=FALSE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897639 + +file.path(R.home('share'), 'texmf', 'tex', 'latex') \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -455,15 +520,54 @@ echo=FALSE \begin_layout Standard To write R code in \SpecialChar LyX -, you can first switch to the +, you can first +\change_inserted 2047637253 1483898412 +insert +\change_deleted 2047637253 1483898419 +switch to the +\change_unchanged + \family typewriter Chunk \family default - environment in the layout styles list (droplist in the top-left corner - in the toolbar), or you can simply open a \SpecialChar TeX - code environment and write Sweave - code chunks in it. - The latter approach is recommended since it is more stable. + +\change_inserted 2047637253 1483898437 +insets from +\family sans +Insert\SpecialChar menuseparator +Custom Insets\SpecialChar menuseparator +Chunk +\change_deleted 2047637253 1483898459 + +\family default +environment in the layout styles list (droplist in the top-left corner in + the toolbar) +\change_unchanged +, or you can simply open a \SpecialChar TeX + code environment and write Sweave code chunks + in it. + +\change_deleted 2047637253 1483898024 +The latter approach is recommended since it is more stable. +\change_inserted 2047637253 1483961753 +However, \SpecialChar LyX + provides a summary of all the +\family typewriter +Chunk +\family default + insets in the document in the +\family sans +Navigate\SpecialChar menuseparator +Literate Programming +\family default + and +\family sans +View\SpecialChar menuseparator +Outline Pane +\family default + menus. +\change_unchanged + \end_layout \begin_layout Standard @@ -483,52 +587,91 @@ useFancyQuotes \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897653 +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483897653 + +\begin_inset Argument 1 status open \begin_layout Plain Layout -<<setup, keep.source=TRUE>>= +\change_inserted 2047637253 1483897653 +setup, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897653 + ## the option 'digits' can set the (approximate) number of digits \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897653 + options(width = 70, useFancyQuotes = FALSE, digits = 4) \end_layout -\begin_layout Plain Layout +\end_inset + -@ \end_layout +\begin_layout Standard + +\change_inserted 2047637253 1483897653 +\begin_inset Flex Chunk +status open + \begin_layout Plain Layout -<<sweave-manual, eval=FALSE, keep.source=TRUE>>= -\end_layout +\change_inserted 2047637253 1483897653 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -## view the Sweave vignette (requires R >= 2.13.0) +\change_inserted 2047637253 1483897653 +sweave-manual, eval=FALSE, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -vignette("Sweave", package = "utils") +\change_inserted 2047637253 1483897653 + +## view the Sweave vignette (requires R >= 2.13.0) \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897653 + +vignette("Sweave", package = "utils") \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -536,52 +679,91 @@ A simple example that will run in any S engine: \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897659 +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483897659 + +\begin_inset Argument 1 status open \begin_layout Plain Layout -<<print-integers, keep.source=TRUE>>= +\change_inserted 2047637253 1483897659 +print-integers, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897659 + ## the integers from 1 to 10 are \end_layout \begin_layout Plain Layout -1:10 +\change_inserted 2047637253 1483897659 + +1:10 \end_layout -\begin_layout Plain Layout +\end_inset + -@ \end_layout +\begin_layout Standard + +\change_inserted 2047637253 1483897659 +\begin_inset Flex Chunk +status open + \begin_layout Plain Layout -<<hide-results, results=hide>>= -\end_layout +\change_inserted 2047637253 1483897659 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -## intentionally hide the output by setting results=hide +\change_inserted 2047637253 1483897659 +hide-results, results=hide +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -print(1:20) +\change_inserted 2047637253 1483897659 + +## intentionally hide the output by setting results=hide \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897659 + +print(1:20) \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -589,32 +771,48 @@ We can also emulate a simple calculator: \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897665 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<calculator>>= -\end_layout +\change_inserted 2047637253 1483897665 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -1 + pi +\change_inserted 2047637253 1483897665 +calculator +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -sin(pi/6) +\change_inserted 2047637253 1483897665 + +1 + pi \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897665 + +sin(pi/6) \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -622,42 +820,62 @@ Now we look at some Gaussian data: \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897670 +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\change_inserted 2047637253 1483897670 + +\begin_inset Argument 1 status open \begin_layout Plain Layout -<<rnorm>>= +\change_inserted 2047637253 1483897670 +rnorm +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897670 + set.seed(123) # for reproducibility \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897670 + x <- rnorm(20) \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897670 + print(x) \end_layout \begin_layout Plain Layout -t1 <- t.test(x) -\end_layout - -\begin_layout Plain Layout +\change_inserted 2047637253 1483897670 -@ +t1 <- t.test(x) \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -753,27 +971,41 @@ iris \end_layout \begin_layout Standard -\begin_inset ERT + +\change_inserted 2047637253 1483897677 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<iris-summary>>= -\end_layout +\change_inserted 2047637253 1483897677 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -summary(iris[,-5]) +\change_inserted 2047637253 1483897677 +iris-summary +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897677 + +summary(iris[,-5]) \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -803,46 +1035,60 @@ name "tab:xtable-demo" \end_inset -\end_layout +\change_inserted 2047637253 1483897685 + +\begin_inset Flex Chunk +status open \begin_layout Plain Layout -\align center -\begin_inset ERT + +\change_inserted 2047637253 1483897698 + +\begin_inset Argument 1 status open \begin_layout Plain Layout +\change_inserted 2047637253 1483897692 +xtable-demo,results=tex,echo=FALSE +\change_unchanged + \end_layout -\begin_layout Plain Layout +\end_inset + -<<xtable-demo,results=tex,echo=FALSE>>= \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897699 + if (require('xtable')) { \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897699 + print(xtable(sapply(iris[,-5], quantile)), floating=FALSE) \end_layout \begin_layout Plain Layout +\change_inserted 2047637253 1483897699 + } else cat('the xtable package is not available! please install.packages("xtable" )') -\end_layout - -\begin_layout Plain Layout +\change_unchanged -@ \end_layout \end_inset +\change_unchanged + \end_layout \end_inset @@ -925,27 +1171,49 @@ Both eps and pdf are set to true so that both latex and pdflatex work. \end_inset -\begin_inset ERT +\end_layout + +\begin_layout Plain Layout +\align center + +\change_inserted 2047637253 1483897765 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<iris-pairs,fig=TRUE,width=4.5,height=4.5,eps=TRUE,pdf=TRUE>>= -\end_layout +\change_inserted 2047637253 1483897772 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -pairs(iris, col = iris$Species) +\change_inserted 2047637253 1483897770 +iris-pairs,fig=TRUE,width=4.5,height=4.5,eps=TRUE,pdf=TRUE +\change_unchanged + +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897776 + +pairs(iris, col = iris$Species) +\change_unchanged + \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Plain Layout @@ -984,32 +1252,48 @@ status open \begin_layout Plain Layout \align center -\begin_inset ERT + +\change_inserted 2047637253 1483897883 +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<<iris-boxplots,fig=TRUE,width=7,height=2,keep.source=F,eps=T,pdf=T>>= -\end_layout +\change_inserted 2047637253 1483897883 + +\begin_inset Argument 1 +status open \begin_layout Plain Layout -par(mar=c(4,5,.1,.3), las=1) +\change_inserted 2047637253 1483897883 +iris-boxplots,fig=TRUE,width=7,height=2,keep.source=F,eps=T,pdf=T +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -boxplot(Sepal.Length~Species,data=iris,horizontal=TRUE,xlab='Sepal.Length') +\change_inserted 2047637253 1483897883 + +par(mar=c(4,5,.1,.3), las=1) \end_layout \begin_layout Plain Layout -@ +\change_inserted 2047637253 1483897883 + +boxplot(Sepal.Length~Species,data=iris,horizontal=TRUE,xlab='Sepal.Length') \end_layout \end_inset +\change_unchanged + \end_layout \begin_layout Plain Layout @@ -1049,6 +1333,8 @@ R/S code R CMD Stangle \family default . +\change_inserted 2047637253 1483898877 + \end_layout \begin_layout Section @@ -1408,8 +1694,17 @@ label= \end_layout \begin_layout Standard -Another known issue is the Sweave code chunk may fail when we change the - alignment of the chunk paragraph in \SpecialChar LyX +Another +\change_deleted 2047637253 1483899012 +known +\change_unchanged + issue +\change_inserted 2047637253 1483898966 +with the \SpecialChar TeX + code environment +\change_unchanged +is the Sweave code chunk may fail when we change the alignment of the chunk + paragraph in \SpecialChar LyX (using \family sans Paragraph settings @@ -1461,7 +1756,16 @@ This is not a legitimate Sweave code chunk, since <<>>= \family default must start in a new line with nothing before it. - Therefore we recommend you to double check the real source code via + +\change_inserted 2047637253 1483899083 + This does not happen when using the Chunk inset instead of the \SpecialChar TeX + code environmen +t. + +\change_unchanged + +\change_deleted 2047637253 1483898988 +Therefore we recommend you to double check the real source code via \family sans View\SpecialChar menuseparator View Source @@ -1480,6 +1784,8 @@ reference "tab:xtable-demo" \end_inset . +\change_unchanged + \end_layout \begin_layout Section commit d1c1a4520c0c3d85b064475ac4b172b97cd09848 Author: Guillaume Munch <[email protected]> Date: Sun Jan 8 19:19:25 2017 +0100 Fine tune AddToToc options for Sweave, Knitr diff --git a/lib/layouts/knitr.module b/lib/layouts/knitr.module index 246c90a..17c2dd2 100644 --- a/lib/layouts/knitr.module +++ b/lib/layouts/knitr.module @@ -37,6 +37,8 @@ InsetLayout "Flex:Sweave Options" Spellcheck 0 FreeSpacing true ForceLTR true + AddToToc literate + IsTocCaption 1 End InsetLayout "Flex:S/R expression" diff --git a/lib/layouts/litinsets.inc b/lib/layouts/litinsets.inc index 7f72ba3..886496f 100644 --- a/lib/layouts/litinsets.inc +++ b/lib/layouts/litinsets.inc @@ -47,6 +47,7 @@ InsetLayout "Flex:Chunk" LeftDelim << RightDelim >>=<br/> IsTocCaption 1 + AutoInsert 1 EndArgument ResetsFont false ForceOwnlines true diff --git a/lib/layouts/sweave.module b/lib/layouts/sweave.module index 5b7799b..6ddac9f 100644 --- a/lib/layouts/sweave.module +++ b/lib/layouts/sweave.module @@ -47,6 +47,8 @@ InsetLayout "Flex:Sweave Options" Spellcheck 0 FreeSpacing true ForceLTR true + AddToToc literate + IsTocCaption 0 End InsetLayout "Flex:S/R expression" @@ -91,4 +93,6 @@ InsetLayout "Flex:Sweave Input File" Spellcheck 0 FreeSpacing true ForceLTR true + AddToToc literate + IsTocCaption 1 End commit 5e2071376972a3c16d0874f18cf31e329e4f773c Author: Guillaume Munch <[email protected]> Date: Sun Jan 8 19:17:57 2017 +0100 Implement IsTocCaption for InsetArgument Shows the title of Sweave, Knitr chunks in the Navigate menu. diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 3992784..f490c35 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -27,7 +27,7 @@ #include "ParIterator.h" #include "TextClass.h" -#include "insets/InsetArgument.h" +#include "insets/InsetText.h" #include "support/convert.h" #include "support/debug.h" @@ -193,6 +193,18 @@ void TocBuilder::captionItem(DocIterator const & dit, docstring const & s, } } +void TocBuilder::argumentItem(docstring const & arg_str) +{ + if (stack_.empty() || arg_str.empty()) + return; + TocItem & item = (*toc_)[stack_.top().pos]; + docstring const & str = item.str(); + string const & delim = + str.empty() ? "" : stack_.top().is_captioned ? ", " : ": "; + item.str(str + from_ascii(delim) + arg_str); + stack_.top().is_captioned = true; +} + void TocBuilder::pop() { if (!stack_.empty()) diff --git a/src/TocBackend.h b/src/TocBackend.h index eaa1ce9..b851d68 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -120,13 +120,15 @@ class TocBuilder { public: TocBuilder(std::shared_ptr<Toc> const toc); - /// When entering a float + /// When entering a float or flex (AddToToc) void pushItem(DocIterator const & dit, docstring const & s, bool output_active, bool is_captioned = false); - /// When encountering a caption + /// When encountering a float caption void captionItem(DocIterator const & dit, docstring const & s, bool output_active); - /// When exiting a float + /// When encountering an argument (isTocCaption) + void argumentItem(docstring const & arg_str); + /// When exiting a float or flex void pop(); private: TocBuilder(){} diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 6ba49c7..605286c 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -26,6 +26,7 @@ #include "ParIterator.h" #include "TexRow.h" #include "texstream.h" +#include "TocBackend.h" #include "support/convert.h" #include "support/debug.h" @@ -106,6 +107,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) } } Layout::LaTeXArgMap::const_iterator const lait = args.find(name_); + caption_of_toc_ = string(); if (lait != args.end()) { docstring label = translateIfPossible((*lait).second.labelstring); docstring striplabel; @@ -117,6 +119,12 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) decoration_ = (*lait).second.decoration; pass_thru_chars_ = (*lait).second.pass_thru_chars; pass_thru_local_ = false; + if (lait->second.is_toc_caption) + // empty if AddToToc is not set + caption_of_toc_ = insetlayout + ? it.inset().getLayout().tocType() + : it.paragraph().layout().tocType(); + switch ((*lait).second.passthru) { case PT_INHERITED: pass_thru_ = pass_thru_context_; @@ -309,4 +317,18 @@ void InsetArgument::latexArgument(otexstream & os, } + +void InsetArgument::addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const +{ + if (!caption_of_toc_.empty()) { + docstring str; + text().forOutliner(str, TOC_ENTRY_LENGTH); + buffer().tocBackend().builder(caption_of_toc_).argumentItem(str); + } + // Proceed with the rest of the inset. + InsetText::addToToc(dit, output_active, utype); +} + + } // namespace lyx diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index fb7e290..0ccdc41 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -81,6 +81,9 @@ public: /// void setButtonLabel(); //@} + /// + void addToToc(DocIterator const & dit, bool output_active, + UpdateType utype) const; //override private: /// @@ -105,6 +108,8 @@ private: bool pass_thru_; /// docstring pass_thru_chars_; + /// The type of Toc this is the caption of, empty otherwise. + std::string caption_of_toc_; protected: /// \name Protected functions inherited from Inset class diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 18f3417..05cbb29 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -175,16 +175,14 @@ void InsetFlex::addToToc(DocIterator const & cpit, bool output_active, // Cursor inside the inset DocIterator pit = cpit; pit.push_back(CursorSlice(const_cast<InsetFlex &>(*this))); - docstring str; - str = getLabel(); + b.pushItem(pit, getLabel(), output_active); + // Proceed with the rest of the inset. + InsetCollapsable::addToToc(cpit, output_active, utype); if (layout.isTocCaption()) { - if (!str.empty()) - str += ": "; + docstring str; text().forOutliner(str, TOC_ENTRY_LENGTH); + b.argumentItem(str); } - 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); commit 28dfc48fb2e24bb8c9d913535b955437b73ca9af Author: Guillaume Munch <[email protected]> Date: Sun Nov 22 22:48:24 2015 +0000 Implement AddToToc layout command for Flex insets Enables TOC for FiXme, ToDo, Knitr, Sweave (#7790) 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: /// commit 089b80fc7d039f1ddc7a9e38aace77d1b3351f43 Author: Guillaume Munch <[email protected]> Date: Mon Nov 30 15:27:43 2015 +0000 Menus: Factor Toc code diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index c442b9b..22ef06b 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -351,6 +351,7 @@ public: void expandFloatListInsert(Buffer const * buf); void expandFloatInsert(Buffer const * buf); void expandFlexInsert(Buffer const * buf, InsetLayout::InsetLyXType type); + void expandTocSubmenu(std::string const & type, Toc const & toc_list); void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth, string toc_type); void expandToc(Buffer const * buf); void expandPasteRecent(Buffer const * buf); @@ -1318,12 +1319,7 @@ void MenuDefinition::expandToc(Buffer const * buf) if (cit->first == "tableofcontents" || cit->second->empty()) continue; MenuDefinition 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, cit->first); + submenu.expandTocSubmenu(cit->first, *cit->second); MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params())); item.setSubmenu(submenu); // deserves to be in the main menu? @@ -1352,6 +1348,17 @@ void MenuDefinition::expandToc(Buffer const * buf) } +void MenuDefinition::expandTocSubmenu(std::string const & type, Toc const & toc) +{ + // "Open outliner..." entry + FuncRequest f(LFUN_DIALOG_SHOW, "toc " + type); + add(MenuItem(MenuItem::Command, qt_("Open Outliner..."), f)); + add(MenuItem(MenuItem::Separator)); + // add entries + expandToc2(toc, 0, toc.size(), 0, type); +} + + void MenuDefinition::expandPasteRecent(Buffer const * buf) { docstring_list const sel = cap::availableSelections(buf); commit ab98adf9250bc4711baa6172b180bafe741e2fc0 Author: Guillaume Munch <[email protected]> Date: Mon Nov 30 15:27:43 2015 +0000 Move Tocs to the "Other lists" submenu based on a blacklist This causes user-defined Tocs to appear in the main list diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 2b13d1f..3992784 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -339,4 +339,26 @@ docstring TocBackend::outlinerName(string const & type) const } +bool TocBackend::isOther(std::string const & type) +{ + // This is where having an Enum of types would have been more elegant... + return type == "graphics" + || type == "note" + || type == "branch" + || type == "change" + || type == "label" + || type == "citation" + || type == "equation" + || type == "footnote" + || type == "marginalnote" + || type == "nomencl" + || type == "listings" + || type == "math-macro" + || type == "external" + || type == "senseless" + || type == "index" + || type.substr(0,6) == "index:"; +} + + } // namespace lyx diff --git a/src/TocBackend.h b/src/TocBackend.h index 10bfff1..eaa1ce9 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -180,6 +180,9 @@ public: odocstringstream & os, size_t max_length) const; /// docstring outlinerName(std::string const & type) const; + /// Whether a toc type is less important and appears in the "Other lists" + /// submenu + static bool isOther(std::string const & type); private: /// diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index de0c887..c442b9b 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1310,7 +1310,6 @@ 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(); @@ -1328,7 +1327,7 @@ void MenuDefinition::expandToc(Buffer const * buf) 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") + if (!TocBackend::isOther(cit->first)) add(item); else other_lists.add(item); ----------------------------------------------------------------------- Summary of changes: lib/doc/Customization.lyx | 297 ++++++++++++++++++++++- lib/doc/Development.lyx | 7 +- lib/examples/knitr.lyx | 90 +++++++- lib/examples/sweave.lyx | 470 +++++++++++++++++++++++++++++------ lib/layouts/knitr.module | 2 + lib/layouts/litinsets.inc | 1 + lib/layouts/stdfloats.inc | 4 + lib/layouts/stdinsets.inc | 19 ++ lib/layouts/sweave.module | 4 + src/Paragraph.cpp | 6 +- src/Paragraph.h | 4 +- src/Text.cpp | 47 +++- src/Text.h | 13 +- src/TextClass.cpp | 4 +- src/TocBackend.cpp | 36 +++- src/TocBackend.h | 37 ++- src/frontends/qt4/Menus.cpp | 22 +- src/frontends/qt4/qt_helpers.cpp | 37 +-- src/frontends/qt4/ui/BibtexAddUi.ui | 221 ++++++++++------- src/insets/Inset.cpp | 1 + src/insets/InsetArgument.cpp | 22 ++ src/insets/InsetArgument.h | 5 + src/insets/InsetBranch.cpp | 18 +-- src/insets/InsetBranch.h | 3 +- src/insets/InsetCitation.cpp | 5 +- src/insets/InsetCollapsable.cpp | 38 +++- src/insets/InsetCollapsable.h | 6 + src/insets/InsetExternal.cpp | 7 +- src/insets/InsetFoot.cpp | 18 -- src/insets/InsetFoot.h | 3 - src/insets/InsetGraphics.cpp | 4 +- src/insets/InsetInclude.cpp | 38 ++-- src/insets/InsetIndex.cpp | 4 +- src/insets/InsetMarginal.cpp | 15 -- src/insets/InsetMarginal.h | 3 - src/insets/InsetNomencl.cpp | 4 +- src/insets/InsetNote.cpp | 20 -- src/insets/InsetNote.h | 3 - src/insets/InsetText.cpp | 56 ++++- src/insets/InsetText.h | 7 + src/mathed/InsetMathHull.cpp | 33 +++- src/mathed/MathMacroTemplate.cpp | 5 +- 42 files changed, 1277 insertions(+), 362 deletions(-) hooks/post-receive -- Repository for new features
