commit cf64064db71ddedb4deb888e63325cea8619a9cd
Author: Richard Heck <[email protected]>
Date:   Thu Nov 26 15:21:21 2015 -0500

    Use the much faster forOutliner also to get the tooltip text.

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index ae2e6de..0c5feb0 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3269,8 +3269,6 @@ void Paragraph::forOutliner(docstring & os, size_t const 
maxlen,
                char_type const c = d->text_[i];
                if (isPrintable(c))
                        os += c;
-               else if (c == '\t' || c == '\n')
-                       os += ' ';
                else if (c == META_INSET)
                        getInset(i)->forOutliner(os, tmplen, false);
        }
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index f928830..96071fa 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -74,7 +74,7 @@ std::string insetName(InsetCode);
 /// Eg, insetDisplayName(BRANCH_CODE) == _("Branch")
 docstring insetDisplayName(InsetCode);
 ///
-static int const TOC_ENTRY_LENGTH = 128;
+static int const TOC_ENTRY_LENGTH = 120;
 
 /// Common base class to all insets
 
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index 6c78d44..7d2d4d5 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -356,11 +356,15 @@ void InsetBranch::addToToc(DocIterator const & cpit, bool 
output_active,
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
-
+       
+       docstring tooltip;
+       text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
+       docstring str = params_.branch + ": " + tooltip;
+       tooltip = support::wrapParas(tooltip, 0, 60, 2);
+       
        shared_ptr<Toc> toc = buffer().tocBackend().toc("branch");
-       docstring str = params_.branch + ": ";
-       text().forOutliner(str, TOC_ENTRY_LENGTH);
-       toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
+       toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+       
        // Proceed with the rest of the inset.
        bool const doing_output = output_active && isBranchSelected();
        InsetCollapsable::addToToc(cpit, doing_output, utype);
diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp
index d1b753d..7008fda 100644
--- a/src/insets/InsetFoot.cpp
+++ b/src/insets/InsetFoot.cpp
@@ -26,6 +26,7 @@
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 
 using namespace std;
 
@@ -79,11 +80,15 @@ void InsetFoot::addToToc(DocIterator const & cpit, bool 
output_active,
 {
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
-
+       
+       docstring tooltip;
+       text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
+       docstring str = custom_label_ + ": " + tooltip;
+       tooltip = support::wrapParas(tooltip, 0, 60, 2);
+       
        shared_ptr<Toc> toc = buffer().tocBackend().toc("footnote");
-       docstring str = custom_label_ + ": ";
-       text().forOutliner(str, TOC_ENTRY_LENGTH);
-       toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
+       toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+       
        // Proceed with the rest of the inset.
        InsetFootlike::addToToc(cpit, output_active, utype);
 }
diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp
index 40ff30a..cb85ab3 100644
--- a/src/insets/InsetMarginal.cpp
+++ b/src/insets/InsetMarginal.cpp
@@ -20,6 +20,7 @@
 
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 
 namespace lyx {
 
@@ -57,10 +58,14 @@ void InsetMarginal::addToToc(DocIterator const & cpit, bool 
output_active,
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetMarginal &>(*this)));
 
+       docstring tooltip;
+       text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
+       docstring const str = tooltip;
+       tooltip = support::wrapParas(tooltip, 0, 60, 2);
+       
        shared_ptr<Toc> toc = buffer().tocBackend().toc("marginalnote");
-       docstring str;
-       text().forOutliner(str, TOC_ENTRY_LENGTH);
-       toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
+       toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+
        // Proceed with the rest of the inset.
        InsetFootlike::addToToc(cpit, output_active, utype);
 }
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index 6fcf279..e483cf2 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -37,6 +37,7 @@
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
@@ -213,11 +214,14 @@ void InsetNote::addToToc(DocIterator const & cpit, bool 
output_active,
        DocIterator pit = cpit;
        pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
        
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("note");
        InsetLayout const & il = getLayout();
-       docstring str = translateIfPossible(il.labelstring()) + from_ascii(": 
");
-       text().forOutliner(str, TOC_ENTRY_LENGTH);
-       toc->push_back(TocItem(pit, 0, str, output_active, 
toolTipText(docstring(), 3, 60)));
+       docstring tooltip;
+       text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
+       docstring str = translateIfPossible(il.labelstring()) + ": " + tooltip;
+       tooltip = support::wrapParas(tooltip, 0, 60, 2);
+       
+       shared_ptr<Toc> toc = buffer().tocBackend().toc("note");
+       toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
 
        // Proceed with the rest of the inset.
        bool doing_output = output_active && producesOutput();
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index c0640a1..52ea7af 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -201,6 +201,9 @@ public:
        /// e.g., "Index: ".
        /// \param numlines: the number of lines in the tooltip
        /// \param len: length of those lines
+       /// NOTE This routine is kind of slow. It's fine to use it within the 
+       /// GUI, but definitely do not try to use it in updateBuffer or anything
+       /// of that sort.
        docstring toolTipText(docstring prefix = empty_docstring(),
                        size_t numlines = 5, size_t len = 80) const;
 

Reply via email to