From 08b63ad3c66f8c9e443526555031d09d0bcc0c16 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 18 Dec 2009 00:29:22 +0000 Subject: [PATCH] Enhance LyX by fixing bug 5587. We add a new ContentAsLabel tag to InsetLayout, per Jurgen's suggestion, so that insets can be told to display an abbreviated form of their content when closed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32575 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/doc/Customization.lyx | 83 ++++++++++++++++++++++++++++++--- lib/layouts/stdinsets.inc | 1 + lib/scripts/layout2layout.py | 7 ++- src/TextClass.cpp | 2 +- src/insets/InsetCollapsable.cpp | 8 +++- src/insets/InsetLayout.cpp | 9 +++- src/insets/InsetLayout.h | 4 ++ 7 files changed, 101 insertions(+), 13 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 35bd469e57..50e56bd7d3 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -1,5 +1,5 @@ #LyX 2.0.0svn created this file. For more info see http://www.lyx.org/ -\lyxformat 372 +\lyxformat 373 \begin_document \begin_header \textclass scrbook @@ -12868,6 +12868,43 @@ src/ColorCode.h \begin_inset Flex CharStyle:Code status collapsed +\begin_layout Plain Layout +ContentAsLabel +\end_layout + +\end_inset + + [ +\begin_inset Flex CharStyle:Code +status collapsed + +\begin_layout Plain Layout + +\emph on +0 +\end_layout + +\end_inset + +, +\begin_inset Flex CharStyle:Code +status collapsed + +\begin_layout Plain Layout +1 +\end_layout + +\end_inset + +] Whether to use the content of the inset as the label, when the inset is + closed. + Default is false. +\end_layout + +\begin_layout Description +\begin_inset Flex CharStyle:Code +status collapsed + \begin_layout Plain Layout CopyStyle \end_layout @@ -13121,6 +13158,7 @@ status collapsed ] Indicates whether the PlainLayout should be used or, instead, the user can change the paragraph style used in the inset. + Default is false. \end_layout \begin_layout Description @@ -13141,6 +13179,7 @@ reference "des:FreeSpacing" \end_inset ). + Default is false. \end_layout \begin_layout Description @@ -13201,6 +13240,7 @@ reference "des:KeepEmpty" \end_inset ). + Default is false. \end_layout \begin_layout Description @@ -13409,13 +13449,43 @@ status collapsed \end_inset ] Whether multiple paragraphs are permitted in this inset. - This will also set CustomPars to the same value and ForcePlain to the opposite - value. + This will also set +\begin_inset Flex CharStyle:Code +status collapsed + +\begin_layout Plain Layout +CustomPars +\end_layout + +\end_inset + + to the same value and +\begin_inset Flex CharStyle:Code +status collapsed + +\begin_layout Plain Layout +ForcePlain +\end_layout + +\end_inset + + to the opposite value. These can be reset to other values, if they are used \emph on after \emph default - MultiPar. + +\begin_inset Flex CharStyle:Code +status collapsed + +\begin_layout Plain Layout +MultiPar +\end_layout + +\end_inset + +. + Default is true. \end_layout \begin_layout Description @@ -13467,7 +13537,7 @@ protect \emph on not \emph default - whether the command should itself be protected.) + whether the command should itself be protected.) Default is false. \end_layout \begin_layout Description @@ -13504,12 +13574,13 @@ status collapsed ] As with paragraph styles (see page \begin_inset CommandInset ref -LatexCommand ref +LatexCommand pageref reference "des:PathThru" \end_inset ). + Default is false. \end_layout \begin_layout Description diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index cf371940b6..526432ebe8 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -305,6 +305,7 @@ InsetLayout URL LyXType standard Decoration classic LabelString URL + ContentAsLabel true LatexName url LatexType command Requires url diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 44af31d709..616e458d4a 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -73,10 +73,13 @@ import os, re, string, sys # Incremented to format 19, 17 November 2009 by rgh # Added InPreamble tag. +# Incremented to format 20, 17 December 2009 by rgh +# Added ContentAsLabel tag. + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). -currentFormat = 19 +currentFormat = 20 def usage(prog_name): @@ -245,7 +248,7 @@ def convert(lines): continue # This just involved new features, not any changes to old ones - if format == 14 or format == 15 or format == 16 or format == 17 or format == 18: + if format >= 14 and format <= 19: i += 1 continue diff --git a/src/TextClass.cpp b/src/TextClass.cpp index e19b0ec200..52f5c30340 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -66,7 +66,7 @@ private: }; // Keep the changes documented in the Customization manual. -int const FORMAT = 19; +int const FORMAT = 20; bool layout2layout(FileName const & filename, FileName const & tempfile) diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 4497e937d3..dc9939e5ac 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -573,10 +573,14 @@ void InsetCollapsable::setLabel(docstring const & l) } -docstring const InsetCollapsable::buttonLabel(BufferView const &) const +docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const { - return labelstring_.empty() ? + docstring const label = labelstring_.empty() ? translateIfPossible(getLayout().labelstring()) : labelstring_; + InsetLayout const & il = getLayout(); + if (!il.contentaslabel() || geometry(bv) != ButtonOnly) + return label; + return getNewLabel(label); } diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index f2b701dfb8..0b9963a0ee 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -31,8 +31,8 @@ namespace lyx { InsetLayout::InsetLayout() : name_(from_ascii("undefined")), lyxtype_(STANDARD), - labelstring_(from_ascii("UNDEFINED")), decoration_(DEFAULT), - latextype_(NOLATEXTYPE), font_(sane_font), + labelstring_(from_ascii("UNDEFINED")), contentaslabel_(false), + decoration_(DEFAULT), latextype_(NOLATEXTYPE), font_(sane_font), labelfont_(sane_font), bgcolor_(Color_error), htmlforcecss_ (false), htmlisblock_(true), multipar_(true), custompars_(true), forceplain_(false), @@ -74,6 +74,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) { enum { IL_BGCOLOR, + IL_CONTENTASLABEL, IL_COPYSTYLE, IL_COUNTER, IL_CUSTOMPARS, @@ -110,6 +111,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) LexerKeyword elementTags[] = { { "bgcolor", IL_BGCOLOR }, + { "contentaslabel", IL_CONTENTASLABEL }, { "copystyle", IL_COPYSTYLE }, { "counter", IL_COUNTER}, { "custompars", IL_CUSTOMPARS }, @@ -240,6 +242,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) case IL_NEEDPROTECT: lex >> needprotect_; break; + case IL_CONTENTASLABEL: + lex >> contentaslabel_; + break; case IL_COPYSTYLE: { // initialize with a known style docstring style; lex >> style; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 8237cd4029..533b62d0e8 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -66,6 +66,8 @@ public: /// docstring labelstring() const { return labelstring_; } /// + bool contentaslabel() const { return contentaslabel_; } + /// InsetDecoration decoration() const { return decoration_; } /// InsetLaTeXType latextype() const { return latextype_; } @@ -143,6 +145,8 @@ private: /// docstring labelstring_; /// + bool contentaslabel_; + /// InsetDecoration decoration_; /// InsetLaTeXType latextype_;