Am Freitag, 25. November 2005 12:19 schrieb Jean-Marc Lasgouttes:
> >>>>> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:
> 
> Juergen> Jean-Marc Lasgouttes wrote: Users will just not understand
> Juergen> why they cannot change back.
> >>  There is no problem of not changing back as long as you have not
> >> added a second paragraph to the cell. I am not proposing to disable
> >> going to non-fixed-width unconditionally.
> 
> Juergen> I understand that. But it will still irritate users in the
> Juergen> cases where it is disabled, unless make the reason for the
> Juergen> disabling transparent ui-wise. I do not see how this can be
> Juergen> done with our tabular dialog.
> 
> This is indeed a problem. Well, the UI change is only validated when
> clicking on Close (which is really a OK or something), so at this time
> a dialog could popup to explain why this change was refused.

The tabular dialog is so broken that I fear we'd open a can of worms if we 
touched it. Jean-Marc, I agree with you in general that we should not be 
too clever, but in this case I think we should restore the 1.3 behaviour 
(merge paragraphs) as an interim solution.
The ideal solution would be IMHO to enable multiple paragraphs even in 
variable width cells and add some LaTeX code to make that work. Then we 
can get rid of the merging code, but this is certainly not for now.
I have attached a patch that restores 1.3 behaviour. Once I found out the 
reason for the crash (it was the recUndo call in LyXText::setLayout), it 
was really easy.

Comments?


Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog
--- lyx-1.4-clean/src/ChangeLog	2005-11-25 20:28:39.000000000 +0100
+++ lyx-1.4-cvs/src/ChangeLog	2005-11-26 18:34:17.830892632 +0100
@@ -1,3 +1,12 @@
+2005-11-26  Georg Baum  <[EMAIL PROTECTED]>
+
+	* lyxtext.h, text2.C (setLayout): factor out some code into the new
+	method setLayoutWithoutUndo
+	* tabular.C (toggleFixedWidth): new, handle cell width changes
+	* tabular.C (setColumnPWidth): move some code from insettabular.C here
+	and use toggleFixedWidth
+	* tabular.C (setMColumnPWidth): ditto
+
 2005-11-25  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
 	* paragraph.C (asString): use new inset->textString method (fix bug 2089)
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog
--- lyx-1.4-clean/src/insets/ChangeLog	2005-11-25 20:29:20.000000000 +0100
+++ lyx-1.4-cvs/src/insets/ChangeLog	2005-11-26 18:30:50.074476408 +0100
@@ -1,3 +1,8 @@
+2005-11-26  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insettabular.C (tabularFeatures): Move some code to
+	setColumnPWidth and setMColumnPWidth
+
 2005-11-25  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
 	* insetbase.h: 
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.C lyx-1.4-cvs/src/insets/insettabular.C
--- lyx-1.4-clean/src/insets/insettabular.C	2005-11-17 20:45:02.000000000 +0100
+++ lyx-1.4-cvs/src/insets/insettabular.C	2005-11-26 18:07:40.000000000 +0100
@@ -1422,10 +1422,7 @@ void InsetTabular::tabularFeatures(LCurs
 
 	case LyXTabular::SET_PWIDTH: {
 		LyXLength const len(value);
-		tabular.setColumnPWidth(cur.idx(), len);
-		// cur position can become invalid after newlines were removed
-		if (cur.pos() > cur.lastpos())
-			cur.pos() = cur.lastpos();
+		tabular.setColumnPWidth(cur, cur.idx(), len);
 		if (len.zero()
 		    && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
 			tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
@@ -1433,10 +1430,7 @@ void InsetTabular::tabularFeatures(LCurs
 	}
 
 	case LyXTabular::SET_MPWIDTH:
-		tabular.setMColumnPWidth(cur.idx(), LyXLength(value));
-		// cur position can become invalid after newlines were removed
-		if (cur.pos() > cur.lastpos())
-			cur.pos() = cur.lastpos();
+		tabular.setMColumnPWidth(cur, cur.idx(), LyXLength(value));
 		break;
 
 	case LyXTabular::SET_SPECIAL_COLUMN:
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/lyxtext.h lyx-1.4-cvs/src/lyxtext.h
--- lyx-1.4-clean/src/lyxtext.h	2005-10-26 20:58:49.000000000 +0200
+++ lyx-1.4-cvs/src/lyxtext.h	2005-11-26 18:10:49.994916232 +0100
@@ -74,9 +74,11 @@ public:
 	/// what you expect when pressing <enter> at cursor position
 	void breakParagraph(LCursor & cur, bool keep_layout = false);
 
-	/// set layout over selection
+	/// set layout over selection with undo
 	pit_type setLayout(pit_type start, pit_type end,
 		std::string const & layout);
+	/// set layout over selection without undo
+	void setLayoutWithoutUndo(pit_type, pit_type, std::string const &);
 	///
 	void setLayout(LCursor & cur, std::string const & layout);
 
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tabular.C lyx-1.4-cvs/src/tabular.C
--- lyx-1.4-clean/src/tabular.C	2005-09-07 20:50:40.000000000 +0200
+++ lyx-1.4-cvs/src/tabular.C	2005-11-26 18:38:39.651089912 +0100
@@ -21,11 +21,14 @@
 
 #include "buffer.h"
 #include "bufferparams.h"
+#include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "LaTeXFeatures.h"
 #include "lyxlex.h"
 #include "outputparams.h"
 #include "paragraph.h"
+#include "paragraph_funcs.h"
 
 #include "insets/insettabular.h"
 
@@ -872,7 +875,38 @@ void LyXTabular::setVAlignment(idx_type 
 }
 
 
-void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width)
+namespace {
+
+/**
+ * Allow line and paragraph breaks for fixed width cells or disallow them,
+ * merge cell paragraphs and reset layout to standard for variable width
+ * cells.
+ */
+void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth)
+{
+	inset->setAutoBreakRows(fixedWidth);
+	if (fixedWidth)
+		return;
+
+	// merge all paragraphs to one
+	BufferParams const & bp =
+		inset->getText(0)->bv_owner->buffer()->params();
+	while (inset->paragraphs().size() > 1)
+		mergeParagraph(bp, inset->paragraphs(), 0);
+
+	// reset layout
+	cur.push(*inset);
+	// undo information has already been recorded
+	inset->getText(0)->setLayoutWithoutUndo(0, cur.lastpit() + 1,
+			"Standard");
+	cur.pop();
+}
+
+}
+
+
+void LyXTabular::setColumnPWidth(LCursor & cur, idx_type cell,
+		LyXLength const & width)
 {
 	col_type const j = column_of_cell(cell);
 
@@ -880,18 +913,32 @@ void LyXTabular::setColumnPWidth(idx_typ
 	for (row_type i = 0; i < rows_; ++i) {
 		idx_type const cell = getCellNumber(i, j);
 		// because of multicolumns
-		getCellInset(cell)->setAutoBreakRows(!getPWidth(cell).zero());
+		toggleFixedWidth(cur, getCellInset(cell).get(),
+		                 !getPWidth(cell).zero());
 	}
+	// cur paragraph can become invalid after paragraphs were merged
+	if (cur.pit() > cur.lastpit())
+		cur.pit() = cur.lastpit();
+	// cur position can become invalid after newlines were removed
+	if (cur.pos() > cur.lastpos())
+		cur.pos() = cur.lastpos();
 }
 
 
-bool LyXTabular::setMColumnPWidth(idx_type cell, LyXLength const & width)
+bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell,
+		LyXLength const & width)
 {
 	if (!isMultiColumn(cell))
 		return false;
 
 	cellinfo_of_cell(cell).p_width = width;
-	getCellInset(cell)->setAutoBreakRows(!width.zero());
+	toggleFixedWidth(cur, getCellInset(cell).get(), !width.zero());
+	// cur paragraph can become invalid after paragraphs were merged
+	if (cur.pit() > cur.lastpit())
+		cur.pit() = cur.lastpit();
+	// cur position can become invalid after newlines were removed
+	if (cur.pos() > cur.lastpos())
+		cur.pos() = cur.lastpos();
 	return true;
 }
 
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tabular.h lyx-1.4-cvs/src/tabular.h
--- lyx-1.4-clean/src/tabular.h	2005-06-10 18:46:39.000000000 +0200
+++ lyx-1.4-cvs/src/tabular.h	2005-11-26 18:05:44.000000000 +0100
@@ -24,6 +24,7 @@
 #include <vector>
 
 class InsetTabular;
+class LCursor;
 class OutputParams;
 
 /* The features the text class offers for tables */
@@ -241,9 +242,9 @@ public:
 	void setVAlignment(idx_type cell, VAlignment align,
 			   bool onlycolumn = false);
 	///
-	void setColumnPWidth(idx_type cell, LyXLength const & width);
+	void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
 	///
-	bool setMColumnPWidth(idx_type cell, LyXLength const & width);
+	bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
 	///
 	void setAlignSpecial(idx_type cell, std::string const & special,
 	                     Feature what);
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/text2.C lyx-1.4-cvs/src/text2.C
--- lyx-1.4-clean/src/text2.C	2005-10-26 20:58:56.000000000 +0200
+++ lyx-1.4-cvs/src/text2.C	2005-11-26 18:25:11.000000000 +0100
@@ -323,7 +323,14 @@ pit_type LyXText::setLayout(pit_type sta
 	BOOST_ASSERT(start != end);
 	pit_type undopit = undoSpan(end - 1);
 	recUndo(start, undopit - 1);
+	setLayoutWithoutUndo(start, end, layout);
+	return undopit;
+}
+
 
+void LyXText::setLayoutWithoutUndo(pit_type start, pit_type end,
+		string const & layout)
+{
 	BufferParams const & bufparams = bv()->buffer()->params();
 	LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
 
@@ -333,8 +340,6 @@ pit_type LyXText::setLayout(pit_type sta
 		if (lyxlayout->margintype == MARGIN_MANUAL)
 			pars_[pit].setLabelWidthString(lyxlayout->labelstring());
 	}
-
-	return undopit;
 }
 
 

Reply via email to