]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetIndex.cpp
InsetIndex: hide printTree behind a LYX_INSET_INDEX_DEBUG flag
[features.git] / src / insets / InsetIndex.cpp
index 25dfb4649ba57dc410b86a5e4d1ec19a0a946b0e..13a7b4d1dff1eb677f4a694df4eebfccfb699b8b 100644 (file)
@@ -55,6 +55,9 @@
 using namespace std;
 using namespace lyx::support;
 
+// Uncomment to enable InsetIndex-specific debugging mode: the tree for the index will be printed to std::cout.
+// #define LYX_INSET_INDEX_DEBUG
+
 namespace lyx {
 
 namespace {
@@ -582,8 +585,8 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PARAGRAPH_BREAK: {
                // Since this inset in single-par anyway, let's use
-               // return to enter subindexes
-               FuncRequest fr(LFUN_INDEXMACRO_INSERT, "subindex");
+               // return to enter subentries
+               FuncRequest fr(LFUN_INDEXMACRO_INSERT, "subentry");
                lyx::dispatch(fr);
                break;
        }
@@ -620,7 +623,7 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
        }
        
        case LFUN_PARAGRAPH_BREAK:
-               return macrosPossible("subindex");
+               return macrosPossible("subentry");
        
        case LFUN_INDEXMACRO_INSERT:
                return macrosPossible(cmd.getArg(0));
@@ -675,7 +678,7 @@ void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams)
                if (inset.lyxCode() == INDEXMACRO_CODE) {
                        InsetIndexMacro const & iim =
                                static_cast<InsetIndexMacro const &>(inset);
-                       if (iim.params().type == InsetIndexMacroParams::Subindex) {
+                       if (iim.params().type == InsetIndexMacroParams::Subentry) {
                                ++i;
                                if (i > 2)
                                        return;
@@ -687,7 +690,8 @@ void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams)
 }
 
 
-std::vector<docstring> InsetIndex::getSubentriesAsText(OutputParams const & runparams) const
+std::vector<docstring> InsetIndex::getSubentriesAsText(OutputParams const & runparams,
+                                                      bool const asLabel) const
 {
        std::vector<docstring> subentries;
 
@@ -699,14 +703,19 @@ std::vector<docstring> InsetIndex::getSubentriesAsText(OutputParams const & runp
                if (inset.lyxCode() == INDEXMACRO_CODE) {
                        InsetIndexMacro const & iim =
                                static_cast<InsetIndexMacro const &>(inset);
-                       if (iim.params().type == InsetIndexMacroParams::Subindex) {
+                       if (iim.params().type == InsetIndexMacroParams::Subentry) {
                                ++i;
                                if (i > 2)
                                        break;
-
-                               otexstringstream os;
-                               iim.getLatex(os, runparams);
-                               subentries.emplace_back(os.str());
+                               if (asLabel) {
+                                       docstring const l;
+                                       docstring const sl = iim.getNewLabel(l);
+                                       subentries.emplace_back(sl);
+                               } else {
+                                       otexstringstream os;
+                                       iim.getLatex(os, runparams);
+                                       subentries.emplace_back(os.str());
+                               }
                        }
                }
        }
@@ -813,7 +822,7 @@ bool hasInsetWithCode(const InsetIndex * const inset_index, const InsetCode code
 
 bool InsetIndex::hasSubentries() const
 {
-       return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::Subindex});
+       return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::Subentry});
 }
 
 
@@ -832,7 +841,7 @@ bool InsetIndex::hasSortKey() const
 bool InsetIndex::macrosPossible(string const type) const
 {
        if (type != "see" && type != "seealso"
-           && type != "sortkey" && type != "subindex")
+           && type != "sortkey" && type != "subentry")
                return false;
 
        Paragraph const & par = paragraphs().front();
@@ -848,8 +857,8 @@ bool InsetIndex::macrosPossible(string const type) const
                             && (iim.params().type == InsetIndexMacroParams::See
                                 || iim.params().type == InsetIndexMacroParams::Seealso))
                                return false;
-                       if (type == "subindex"
-                            && iim.params().type == InsetIndexMacroParams::Subindex) {
+                       if (type == "subentry"
+                            && iim.params().type == InsetIndexMacroParams::Subentry) {
                                ++subidxs;
                                if (subidxs > 1)
                                        return false;
@@ -926,8 +935,15 @@ docstring const InsetIndex::buttonLabel(BufferView const & bv) const
        docstring res;
        if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
                res = label;
-       else
+       else {
                res = getNewLabel(label);
+               OutputParams const rp(0);
+               vector<docstring> sublbls = getSubentriesAsText(rp, true);
+               for (auto const & sublbl : sublbls) {
+                       res += " " + docstring(1, char_type(0x2023));// TRIANGULAR BULLET
+                       res += " " + sublbl;
+               }
+       }
        if (!insetindexpagerangetranslator_latex().find(params_.range).empty())
                res += " " + from_ascii(insetindexpagerangetranslator_latex().find(params_.range));
        return res;
@@ -979,11 +995,22 @@ void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this)));
        docstring str;
+       InsetLayout const & il = getLayout();
+       docstring label = translateIfPossible(il.labelstring());
+       if (!il.contentaslabel())
+               str = label;
+       else {
+               str = getNewLabel(label);
+               OutputParams const rp(0);
+               vector<docstring> sublbls = getSubentriesAsText(rp, true);
+               for (auto const & sublbl : sublbls) {
+                       str += " " + docstring(1, char_type(0x2023));// TRIANGULAR BULLET
+                       str += " " + sublbl;
+               }
+       }
        string type = "index";
        if (buffer().masterBuffer()->params().use_indices)
                type += ":" + to_utf8(params_.index);
-       // this is unlikely to be terribly long
-       text().forOutliner(str, INT_MAX);
        TocBuilder & b = backend.builder(type);
        b.pushItem(pit, str, output_active);
        // Proceed with the rest of the inset.
@@ -1663,7 +1690,7 @@ void outputIndexPage(XMLStream & xs, const IndexNode* root_node, unsigned depth
        xs << xml::CR();
 }
 
-// Only useful for debugging.
+#ifdef LYX_INSET_INDEX_DEBUG
 void printTree(const IndexNode* root_node, unsigned depth = 0)
 {
        static const std::string pattern = "    ";
@@ -1698,6 +1725,7 @@ void printTree(const IndexNode* root_node, unsigned depth = 0)
                printTree(node, depth + 1);
        }
 }
+#endif // LYX_INSET_INDEX_DEBUG
 }
 
 
@@ -1723,7 +1751,7 @@ docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const
                return docstring();
 
        const IndexNode* index_root = buildIndexTree(entries);
-#if 0
+#ifdef LYX_INSET_INDEX_DEBUG
        printTree(index_root);
 #endif