The attached patch implements a usability request which strikes me very
sensible: when the cursor hovers over a collapsed float that has a caption,
the inset tooltip displays the caption's text (including the figure/table
number).

Similar things could be done for other collapsables (a truncated text of
footnotes comes to mind)

Objections?

Jürgen
Index: src/insets/InsetCaption.cpp
===================================================================
--- src/insets/InsetCaption.cpp	(Revision 23841)
+++ src/insets/InsetCaption.cpp	(Arbeitskopie)
@@ -268,6 +268,14 @@
 }
 
 
+int InsetCaption::getCaptionText(odocstream & os,
+			OutputParams const & runparams) const
+{
+	os << full_label_ << ' ';
+	return InsetText::plaintext(os, runparams);
+}
+
+
 void InsetCaption::updateLabels(ParIterator const & it)
 {
 	DocumentClass const & tclass = buffer().params().documentClass();
Index: src/insets/InsetCaption.h
===================================================================
--- src/insets/InsetCaption.h	(Revision 23841)
+++ src/insets/InsetCaption.h	(Arbeitskopie)
@@ -28,6 +28,8 @@
 	int getArgument(odocstream & os, OutputParams const &) const;
 	/// return the optional argument(s) only
 	int getOptArg(odocstream & os, OutputParams const &) const;
+	/// return the caption text
+	int getCaptionText(odocstream & os, OutputParams const &) const;
 private:
 	///
 	void write(std::ostream & os) const;
Index: src/insets/InsetFloat.cpp
===================================================================
--- src/insets/InsetFloat.cpp	(Revision 23841)
+++ src/insets/InsetFloat.cpp	(Arbeitskopie)
@@ -125,6 +125,17 @@
 }
 
 
+docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
+{
+	OutputParams rp(&buffer().params().encoding());
+	docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
+	docstring caption_tip = getCaptionText(rp);
+	if (!isOpen() && !caption_tip.empty())
+		return caption_tip + '\n' + default_tip;
+	return default_tip;
+}
+
+
 void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
 	switch (cmd.action) {
@@ -453,6 +464,29 @@
 }
 
 
+docstring InsetFloat::getCaptionText(OutputParams const & runparams) const
+{
+	if (paragraphs().empty())
+		return docstring();
+
+	ParagraphList::const_iterator pit = paragraphs().begin();
+	for (; pit != paragraphs().end(); ++pit) {
+		InsetList::const_iterator it = pit->insetList().begin();
+		for (; it != pit->insetList().end(); ++it) {
+			Inset & inset = *it->inset;
+			if (inset.lyxCode() == CAPTION_CODE) {
+				odocstringstream ods;
+				InsetCaption * ins =
+					static_cast<InsetCaption *>(it->inset);
+				ins->getCaptionText(ods, runparams);
+				return ods.str();
+			}
+		}
+	}
+	return docstring();
+}
+
+
 string const InsetFloatMailer::name_("float");
 
 InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
Index: src/insets/InsetFloat.h
===================================================================
--- src/insets/InsetFloat.h	(Revision 23841)
+++ src/insets/InsetFloat.h	(Arbeitskopie)
@@ -53,6 +53,8 @@
 	///
 	docstring name() const { return name_; }
 	///
+	docstring toolTip(BufferView const & bv, int x, int y) const;
+	///
 	void write(std::ostream & os) const;
 	///
 	void read(Lexer & lex);
@@ -96,6 +98,8 @@
 	///
 	docstring getCaption(OutputParams const &) const;
 	///
+	docstring getCaptionText(OutputParams const &) const;
+	///
 	InsetFloatParams params_;
 	///
 	docstring name_;

Reply via email to