From: Jürgen Spitzmüller Date: Thu, 10 Apr 2008 10:05:00 +0000 (+0000) Subject: Extended tooltips for footnotes/marginpars: X-Git-Tag: 1.6.10~5219 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9ad1a3af4fa52bec8b361fbdc2f1db97720a8cc9;p=features.git Extended tooltips for footnotes/marginpars: * 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 --- diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index c40dc08d43..310ab27edc 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -26,6 +26,7 @@ #include "TocBackend.h" #include "support/debug.h" +#include "support/docstream.h" #include "support/lstrings.h" #include @@ -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; diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h index 0df579e0f4..8e2e3989fb 100644 --- a/src/insets/InsetFoot.h +++ b/src/insets/InsetFoot.h @@ -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_; }; diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index 654caca709..748ae3eca5 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -14,9 +14,11 @@ #include "InsetMarginal.h" #include "Buffer.h" +#include "BufferParams.h" #include "OutputParams.h" #include "TocBackend.h" +#include "support/docstream.h" #include "support/gettext.h" #include @@ -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{"; diff --git a/src/insets/InsetMarginal.h b/src/insets/InsetMarginal.h index 1899cf8d72..2c395d601d 100644 --- a/src/insets/InsetMarginal.h +++ b/src/insets/InsetMarginal.h @@ -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); }