All of this sounds very reasonable. I'm attaching my last patch along these lines, in case some of it could prove useful.

Richard

Martin Vermeer wrote:
On Mon, Aug 13, 2007 at 01:18:52AM -0400, Richard Heck wrote:
 Martin Vermeer wrote:
The attached patch is the beginning of trying to make the
insets as configurable through the layout files as currently
paragrapshs are. It tries to more generally do what only
CharStyles are doing now. So Richard won't have to abuse CS
in the future...

The idea is that this will in the long run replace the
CS functionality. Currently only foot- and marginal notes
and note insets are done, sort-of. It's only a demonstration of princple offered here for review, but once in, it can be
easily extended.
I've studied this a bit, and I think I understand where it's supposed to be going. I'm still not sure if it's trying to do what I was trying to do before, or if it's more or less orthogonal to that. So let me say what I was trying to do.

Here's what I wanted to do: Make it possible for USERS to define collapsable insets, just as USERS can now define inline insets---which we call character styles and modify a bit from their most basic form. (I think it'd also be great for users to be able to define command insets, though this poses somewhat different issues.) So far as I can see, what's here doesn't do this, or really move us much in that direction---at least so far. Maybe it's intended to do so, though, and I'm missing the application. Otherwise, I'm not sure why LatexName is being defined in these InsetLayouts. It doesn't seem to be used anywhere in the code.

Not yet, yes.
That said, even if this doesn't help with my problem, it's still very useful: Users can now customize the appearance of the predefined insets. And the patch looks good to me, in general. One question, though: What happens if no InsetLayout has been defined for Foot? Then it seems we're calling getLayout() for an undefined key.

Then the button label will be empty (should be an error message)and the other 
attributes some default values, probably ;-)

Lots of help from Jean-Marc on this.
 You, too, eh?

 Regarding what I wanted, here's what seems to me a plausible plan:

1. Derive InsetCollapsableCustom as a subclass of InsetCollapsable. This will do all the general "customized inset" stuff shared between InsetCharStyle and the new thing: e.g, setDefined() and the like would appear here. Then InsetCharStyle could inherit from this, too. Another option would be to make InsetCustom a mixin, so that some of this could be used by a hypothetical InsetCommandCustom.

Thanks, InsetCustom sounds good.
My plan was to modify InsetCharStyle to InsetCustom. Then,
some of the custom insets may have an attribute that defines
them as being actually charstyles. (The menu system may put
these in a different place).

Note that currently a charstyle object may contain
an instance of layout_ (from collapsable) and a charstyle
parameters type member param_, containing pretty much the
same stuff. I wss planning to move over everything to layout_.
Not quite clear on the details though.

You would then have a user defined inset Custom:Endnote
with attribute CharStyle false. No C++ required.

 2. Other modifications:
*TextClass will need a list of customized collapsable insets, which now would be defined not using CharStyle but in some other way, say, via: InsetCollapsable. These will be read in read(), of course. *MenuBackend will have a routine to add the defined Collapsible inset to the menu, and their location will be set in stdmenus.inc, as usual, we'll need a "CollapsableInsets" menu entry, with corresponding changes in read(). We will also need something similar to expandCharStyleInsert(), and will need a similar bit in expand(). Need to add something to MenuItem, in MenuBackend.h, as well. *LaTeXFeatures::getTClassPreamble(): needs a corresponding bit for these things. *Need a new LFUN instead of LFUN_CHARSTYLE_INSERT, so this involves changes to factory.cpp, lfuns.h, LyXAction.cpp, Text3.cpp, insets/InsetERT.cpp, and insets/InsetTabular.cpp: Basically, we can mirror a lot of what happens with CharStyles in these files.

 Comments on the plan?

 Richard

Yes, I want those things too, but without almost duplicating
CharStyle. We should have predefined and (generic) user
defined insets being configurable through the same mechanism.

Perhaps button-style insets also by the same mechanism, though
they are rather different.

I hope to get this into a state during or shortly after the
meeting where others can build on it.

Regards Martin


--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: src/insets/InsetCharStyle.cpp
===================================================================
--- src/insets/InsetCharStyle.cpp	(revision 19117)
+++ src/insets/InsetCharStyle.cpp	(working copy)
@@ -35,6 +35,7 @@
 #include "frontends/Painter.h"
 
 #include "support/convert.h"
+#include "support/lstrings.h"
 
 #include <sstream>
 
@@ -51,8 +52,19 @@
 
 void InsetCharStyle::init()
 {
-	setInlined();
-	setDrawFrame(false);
+	if (isInline()) {
+		setInlined();
+		setDrawFrame(false);
+	} else {
+		setOpen();
+		Font font(Font::ALL_SANE);
+		font.decSize();
+		font.decSize();
+		font.setColor(Color::collapsable);
+		setLabelFont(font);
+		setDrawFrame(true);
+		setLabel(from_ascii(params_.type));
+	}
 }
 
 
@@ -82,6 +94,11 @@
 }
 
 
+bool InsetCharStyle::isInline() const {
+	return params_.inlineInset;
+}
+
+
 auto_ptr<Inset> InsetCharStyle::doClone() const
 {
 	return auto_ptr<Inset>(new InsetCharStyle(*this));
@@ -96,6 +113,7 @@
 
 void InsetCharStyle::setUndefined()
 {
+	params_.inlineInset = true;
 	params_.latextype.clear();
 	params_.latexname.clear();
 	params_.latexparam.clear();
@@ -103,17 +121,20 @@
 	params_.labelfont = Font(Font::ALL_INHERIT);
 	params_.labelfont.setColor(Color::error);
 	params_.show_label = true;
+	init();
 }
 
 
 void InsetCharStyle::setDefined(CharStyles::iterator cs)
 {
+	params_.inlineInset = cs->inlineInset;
 	params_.latextype = cs->latextype;
 	params_.latexname = cs->latexname;
 	params_.latexparam = cs->latexparam;
 	params_.font = cs->font;
 	params_.labelfont = cs->labelfont;
 	params_.show_label = true;
+	init();
 }
 
 
@@ -134,12 +155,16 @@
 {
 	params_.read(lex);
 	InsetCollapsable::read(buf, lex);
-	setInlined();
+	if (isInline())
+		setInlined();
 }
 
 
 bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+	if (!isInline())
+		return InsetCollapsable::metrics(mi, dim);
+
 	Font tmpfont = mi.base.font;
 	getDrawFont(mi.base.font);
 	mi.base.font.reduce(Font(Font::ALL_SANE));
@@ -177,6 +202,9 @@
 
 void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
 {
+	if (!isInline())
+		return InsetCollapsable::draw(pi, x, y);
+
 	setPosCache(pi, x, y);
 
 	Font tmpfont = pi.base.font;
@@ -236,15 +264,20 @@
 
 void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
+	if (!isInline()) {
+		InsetCollapsable::doDispatch(cur, cmd);
+		return;
+	}
+		
 	setInlined();
 	switch (cmd.action) {
 
 	case LFUN_MOUSE_RELEASE:
-			if (cmd.button() == mouse_button::button3)
-				params_.show_label = !params_.show_label;
-			else
-				InsetCollapsable::doDispatch(cur, cmd);
-			break;
+		if (cmd.button() == mouse_button::button3)
+			params_.show_label = !params_.show_label;
+		else
+			InsetCollapsable::doDispatch(cur, cmd);
+		break;
 
 	case LFUN_INSET_TOGGLE:
 		if (cmd.argument() == "open")
Index: src/insets/InsetCharStyle.h
===================================================================
--- src/insets/InsetCharStyle.h	(revision 19117)
+++ src/insets/InsetCharStyle.h	(working copy)
@@ -29,6 +29,8 @@
 	///
 	std::string type;
 	///
+	bool inlineInset;
+	///
 	std::string latextype;
 	///
 	std::string latexname;
@@ -112,6 +114,8 @@
 	void init();
 	///
 	InsetCharStyleParams params_;
+	///
+	bool isInline() const;
 };
 
 
Index: src/insets/InsetCollapsable.h
===================================================================
--- src/insets/InsetCollapsable.h	(revision 19117)
+++ src/insets/InsetCollapsable.h	(working copy)
@@ -72,6 +72,7 @@
 	virtual void setButtonLabel() {}
 	///
 	void setLabelFont(Font & f);
+	// Add: setLabelFont(Color_color & c) to do what the usual sequence does.
 	///
 	bool isOpen() const { return status_ == Open || status_ == Inlined; }
 	///
@@ -101,6 +102,10 @@
 	///
 	void setInlined() { status_ = Inlined; }
 	///
+	void setCollapsed() { status_ = Collapsed; }
+	///
+	void setOpen() {status_ = Open; }
+	///
 	docstring floatName(std::string const & type, BufferParams const &) const;
 
 protected:
Index: src/TextClass.cpp
===================================================================
--- src/TextClass.cpp	(revision 19117)
+++ src/TextClass.cpp	(working copy)
@@ -597,6 +597,7 @@
 
 enum CharStyleTags {
 	CS_FONT = 1,
+	CS_INLINE,
 	CS_LABELFONT,
 	CS_LATEXTYPE,
 	CS_LATEXNAME,
@@ -611,6 +612,7 @@
 	keyword_item elementTags[] = {
 		{ "end", CS_END },
 		{ "font", CS_FONT },
+		{ "inline", CS_INLINE },
 		{ "labelfont", CS_LABELFONT },
 		{ "latexname", CS_LATEXNAME },
 		{ "latexparam", CS_LATEXPARAM },
@@ -620,6 +622,7 @@
 
 	lexrc.pushTable(elementTags, CS_END);
 
+	bool inlineInset = true;
 	string latextype;
 	string latexname;
 	string latexparam;
@@ -641,6 +644,10 @@
 			lexrc.next();
 			latextype = lexrc.getString();
 			break;
+		case CS_INLINE:
+			lexrc.next();
+			inlineInset = lexrc.getBool();
+			break;
 		case CS_LATEXNAME:
 			lexrc.next();
 			latexname = lexrc.getString();
@@ -670,6 +677,7 @@
 	if (getout) {
 		CharStyle cs;
 		cs.name = name;
+		cs.inlineInset = inlineInset;
 		cs.latextype = latextype;
 		cs.latexname = latexname;
 		cs.latexparam = latexparam;
Index: src/TextClass.h
===================================================================
--- src/TextClass.h	(revision 19117)
+++ src/TextClass.h	(working copy)
@@ -31,6 +31,7 @@
 class CharStyle {
 public:
 	std::string name;
+	bool inlineInset;
 	std::string latextype;
 	std::string latexname;
 	std::string latexparam;
Index: lib/doc/Customization.lyx
===================================================================
--- lib/doc/Customization.lyx	(revision 19117)
+++ lib/doc/Customization.lyx	(working copy)
@@ -1,5 +1,5 @@
 #LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
-\lyxformat 274
+\lyxformat 276
 \begin_document
 \begin_header
 \textclass book
@@ -39,9 +39,8 @@
 \paperpagestyle headings
 \tracking_changes false
 \output_changes false
-\author "Richard Heck" 
-\author "Jean-Marc Lasgouttes" 
-\author "usti" 
+\author "" 
+\author "" 
 \end_header
 
 \begin_body
@@ -8339,6 +8338,20 @@
 
 \family typewriter
 \series medium
+Inline
+\family default
+\series default
+ Boolean, defaulting to true.
+ This setting defines the type of inset that will be used to represent the
+ character style.
+ Using false makes the inset collapsible, thus allowing you to define custom
+ insets representing single-argument LaTeX commands.
+\end_layout
+
+\begin_layout Description
+
+\family typewriter
+\series medium
 Font
 \family default
 \series default
@@ -8440,9 +8453,140 @@
 
 \end_inset
 
+.
+\end_layout
 
+\begin_layout Standard
+Here are a couple of examples:
 \end_layout
 
+\begin_layout Quote
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Standard
+
+CharStyle HugeSmallCaps
+\end_layout
+
+\begin_layout Standard
+
+  LatexType Command   
+\end_layout
+
+\begin_layout Standard
+
+  LatexName hugesc
+\end_layout
+
+\begin_layout Standard
+
+  Font     
+\end_layout
+
+\begin_layout Standard
+
+    Shape SmallCaps   
+\end_layout
+
+\begin_layout Standard
+
+    Size Huge
+\end_layout
+
+\begin_layout Standard
+
+  EndFont 
+\end_layout
+
+\begin_layout Standard
+
+  Preamble
+\end_layout
+
+\begin_layout Standard
+
+    
+\backslash
+newcommand{hugesc}{
+\backslash
+huge{
+\backslash
+textsc{#1}}}
+\end_layout
+
+\begin_layout Standard
+
+  EndPreamble
+\end_layout
+
+\begin_layout Standard
+
+End 
+\end_layout
+
+\end_inset
+
+This gives huge small caps, in a standard sort of inline representation.
+\end_layout
+
+\begin_layout Quote
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Standard
+
+CharStyle Endnote         
+\end_layout
+
+\begin_layout Standard
+
+  LatexType Command         
+\end_layout
+
+\begin_layout Standard
+
+  LatexName endnote         
+\end_layout
+
+\begin_layout Standard
+
+  Inline false
+\end_layout
+
+\begin_layout Standard
+
+  Preamble           
+\end_layout
+
+\begin_layout Standard
+
+    
+\backslash
+usepackage{endnotes}         
+\end_layout
+
+\begin_layout Standard
+
+  EndPreamble 
+\end_layout
+
+\begin_layout Standard
+
+End 
+\end_layout
+
+\end_inset
+
+This one defines a custom endnote inset, for use with the 
+\family sans
+endnotes
+\family default
+ package.
+\end_layout
+
 \begin_layout Subsection
 Counters
 \end_layout

Reply via email to