On Thu, 04 Oct 2007 22:10:25 +0200
Helge Hafting <[EMAIL PROTECTED]> wrote:

> I tried making a custom inset, and found that
> if I don't specify "Font . . . EndFont", then LyX crashes
> as soon as I try "Insert->Custom Insets->my inset"
> 
> I didn't want to specify a font, I though LyX could use whatever font
> that was in effect at the moment. Some cases don't need to
> set a font, they are merely meant to add some latex command
> or environment to the output.

I think I fixed this with the attached... please verify.

...
 
> Now for the question. Is it possible to create an inset that can
> contain severla paragraphs of various types, similiar to how the
> minipage or branch inset works?

Added the multipar boolean parameter which should do the trick.



Now _my_ question:

Looking at Text3.cpp, I find the passage

               if (gotsel && pastesel) {
                        lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
                        // reset first par to default
                        if (cur.lastpit() != 0 || cur.lastpos() != 0) {
                                LayoutPtr const layout =
                                        
cur.buffer().params().getTextClass().defaultLayout();
                                
cur.text()->paragraphs().begin()->layout(layout);
                        }
                }

If I read this correctly, what's happening is that if an inset is
created around selected text, and under some circumstances the first
paragraph inside the inset is reset to default layout.

Now my question is, what precisely is happening here, and is this what
we really want? Those 'some circumstances' look suspicious.

I am asking because we could use the multipar inset layout parameter
for this. Reset to default only if multipar = false, because these are
typically small insets embedded in a running paragraph. When selecting
and enclosing multiple paragraphs in an inset, I find the resetting of
the first paragraph often irritating.

OTOH if the surrounding text para becomes empty after the cut, I think
resetting _that_ to default makes sense. Think enclosing a section
header plus text into a (branch) inset. Or a numbered/bullet list.

Ideas?

- Martin
Index: TextClass.cpp
===================================================================
--- TextClass.cpp	(revision 20732)
+++ TextClass.cpp	(working copy)
@@ -620,6 +620,7 @@
 	IL_LATEXPARAM,
 	IL_LATEXTYPE,
 	IL_LYXTYPE,
+	IL_MULTIPAR,
 	IL_PREAMBLE,
 	IL_END
 };
@@ -638,6 +639,7 @@
 		{ "latexparam", IL_LATEXPARAM },
 		{ "latextype", IL_LATEXTYPE },
 		{ "lyxtype", IL_LYXTYPE },
+		{ "multipar", IL_MULTIPAR },
 		{ "preamble", IL_PREAMBLE }
 	};
 
@@ -649,10 +651,11 @@
 	string decoration;
 	string latexname;
 	string latexparam;
-	Font font(Font::ALL_INHERIT);
-	Font labelfont(Font::ALL_INHERIT);
+	Font font(defaultfont());
+	Font labelfont(defaultfont());
 	Color::color bgcolor(Color::background);
 	string preamble;
+	bool multipar(false);
 
 	bool getout = false;
 	while (!getout && lexrc.isOK()) {
@@ -692,6 +695,10 @@
 			labelfont.lyxRead(lexrc);
 			labelfont.realize(defaultfont());
 			break;
+		case IL_MULTIPAR:
+			lexrc.next();
+			multipar = lexrc.getBool();
+			break;
 		case IL_FONT:
 			font.lyxRead(lexrc);
 			font.realize(defaultfont());
@@ -724,6 +731,7 @@
 		il.latextype = latextype;
 		il.latexname = latexname;
 		il.latexparam = latexparam;
+		il.multipar = multipar;
 		il.font = font;
 		il.labelfont = labelfont;
 		il.bgcolor = bgcolor;		
Index: TextClass.h
===================================================================
--- TextClass.h	(revision 20732)
+++ TextClass.h	(working copy)
@@ -45,6 +45,7 @@
 	Font labelfont;
 	Color::color bgcolor;
 	std::string preamble;
+	bool multipar;
 };
 
 
Index: insets/InsetFlex.cpp
===================================================================
--- insets/InsetFlex.cpp	(revision 20732)
+++ insets/InsetFlex.cpp	(working copy)
@@ -138,7 +138,7 @@
 		case LFUN_BREAK_PARAGRAPH:
 		case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
 		case LFUN_BREAK_PARAGRAPH_SKIP:
-			status.enabled(false);
+			status.enabled(layout_.multipar);
 			return true;
 
 		default:

Reply via email to