]> git.lyx.org Git - features.git/commitdiff
Extended tooltips for footnotes/marginpars:
authorJürgen Spitzmüller <spitz@lyx.org>
Thu, 10 Apr 2008 10:05:00 +0000 (10:05 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Thu, 10 Apr 2008 10:05:00 +0000 (10:05 +0000)
* src/insets/InsetFoot.{cpp,h}:
* src/insets/InsetMarginal.{cpp,h}:
- implement tooltip

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24202 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetFoot.cpp
src/insets/InsetFoot.h
src/insets/InsetMarginal.cpp
src/insets/InsetMarginal.h

index c40dc08d43fa196ec58c9325917344a4898f2c98..310ab27edceb770eb2bb72cf46dd7be949c153de 100644 (file)
@@ -26,6 +26,7 @@
 #include "TocBackend.h"
 
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/lstrings.h"
 
 #include <ostream>
@@ -55,9 +56,10 @@ void InsetFoot::updateLabels(ParIterator const & it)
        if (!outer.layout().intitle && cnts.hasCounter(foot)) {
                cnts.step(foot);
                // FIXME: the counter should format itself.
-               setLabel(support::bformat(from_ascii("%1$s %2$s"), 
-                                         getLayout(buffer().params()).labelstring(), 
-                                         cnts.theCounter(foot)));
+               custom_label_= support::bformat(from_ascii("%1$s %2$s"),
+                                         getLayout(buffer().params()).labelstring(),
+                                         cnts.theCounter(foot));
+               setLabel(custom_label_);
        
        }
        InsetCollapsable::updateLabels(it);
@@ -72,11 +74,27 @@ void InsetFoot::addToToc(ParConstIterator const & cpit) const
        Toc & toc = buffer().tocBackend().toc("footnote");
        // FIXME: we probably want the footnote number too.
        docstring str;
-       str = getNewLabel(str);
+       str = custom_label_ + ": " + getNewLabel(str);
        toc.push_back(TocItem(pit, 0, str));
 }
 
 
+docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const
+{
+       docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
+       OutputParams rp(&buffer().params().encoding());
+       odocstringstream ods;
+       InsetText::plaintext(ods, rp);
+       docstring foot_tip = custom_label_ + ": " + ods.str();
+       // shorten it if necessary
+       if (foot_tip.size() > 200)
+               foot_tip = foot_tip.substr(0, 200) + "...";
+       if (!isOpen() && !foot_tip.empty())
+               return foot_tip + '\n' + default_tip;
+       return default_tip;
+}
+
+
 int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const
 {
        OutputParams runparams = runparams_in;
index 0df579e0f4155fbc3acd09896bb5af49dea80c6b..8e2e3989fb4d4f72f2e7d9786e81707581b1a979 100644 (file)
@@ -44,7 +44,11 @@ private:
        ///
        void addToToc(ParConstIterator const &) const;
        ///
+       docstring toolTip(BufferView const & bv, int x, int y) const;
+       ///
        Inset * clone() const { return new InsetFoot(*this); }
+       ///
+       docstring custom_label_;
 };
 
 
index 654caca709859b87c5f8e9e8bd789c8f08f9af23..748ae3eca511b6e451a72f978971d997f502b6ca 100644 (file)
 #include "InsetMarginal.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "OutputParams.h"
 #include "TocBackend.h"
 
+#include "support/docstream.h"
 #include "support/gettext.h"
 
 #include <ostream>
@@ -36,6 +38,22 @@ docstring InsetMarginal::editMessage() const
 }
 
 
+docstring InsetMarginal::toolTip(BufferView const & bv, int x, int y) const
+{
+       docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
+       OutputParams rp(&buffer().params().encoding());
+       odocstringstream ods;
+       InsetText::plaintext(ods, rp);
+       docstring margin_tip = ods.str();
+       // shorten it if necessary
+       if (margin_tip.size() > 200)
+               margin_tip = margin_tip.substr(0, 200) + "...";
+       if (!isOpen() && !margin_tip.empty())
+               return margin_tip + '\n' + default_tip;
+       return default_tip;
+}
+
+
 int InsetMarginal::latex(odocstream & os, OutputParams const & runparams) const
 {
        os << "%\n\\marginpar{";
index 1899cf8d726683a4a2f7f4df39f85922ed2fec3e..2c395d601db4ea6053ba8b1e505b33da24869f6a 100644 (file)
@@ -40,6 +40,8 @@ public:
        docstring editMessage() const;
        ///
        void addToToc(ParConstIterator const &) const;
+       ///
+       docstring toolTip(BufferView const & bv, int x, int y) const;
 private:
        ///
        Inset * clone() const { return new InsetMarginal(*this); }