Jean-Marc Lasgouttes wrote:
> I do not like much the new setLayoutWithoutUndo and would have
> preferred an optional bool argument to setLayout or maybe even the
> removal of the undo step from setLayout: I suspect that there are
> other cases where we want to avoid undo (when we switch classes?) and
> it is not difficult to do undo by hand.
Good point. It turned out that setLayout was only called once (from the
other LyXText::setLayout method), so I moved the undo stuff there.
OK to commit?
Georg
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2328
diff -u -p -r1.2328 ChangeLog
--- src/ChangeLog 25 Nov 2005 14:40:33 -0000 1.2328
+++ src/ChangeLog 28 Nov 2005 10:54:56 -0000
@@ -1,3 +1,11 @@
+2005-11-28 Georg Baum <[EMAIL PROTECTED]>
+
+ * text2.C (setLayout): move recUndo call to other setLayout method
+ * 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)
Index: src/lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.329
diff -u -p -r1.329 lyxtext.h
--- src/lyxtext.h 25 Oct 2005 09:14:11 -0000 1.329
+++ src/lyxtext.h 28 Nov 2005 10:54:56 -0000
@@ -75,7 +75,7 @@ public:
void breakParagraph(LCursor & cur, bool keep_layout = false);
/// set layout over selection
- pit_type setLayout(pit_type start, pit_type end,
+ void setLayout(pit_type start, pit_type end,
std::string const & layout);
///
void setLayout(LCursor & cur, std::string const & layout);
Index: src/tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.227
diff -u -p -r1.227 tabular.C
--- src/tabular.C 7 Sep 2005 10:37:00 -0000 1.227
+++ src/tabular.C 28 Nov 2005 10:54:57 -0000
@@ -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,36 @@ 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);
+ inset->getText(0)->setLayout(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 +912,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;
}
Index: src/tabular.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.h,v
retrieving revision 1.97
diff -u -p -r1.97 tabular.h
--- src/tabular.h 9 Jun 2005 09:58:05 -0000 1.97
+++ src/tabular.h 28 Nov 2005 10:54:57 -0000
@@ -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);
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.634
diff -u -p -r1.634 text2.C
--- src/text2.C 25 Oct 2005 09:14:11 -0000 1.634
+++ src/text2.C 28 Nov 2005 10:54:57 -0000
@@ -318,11 +318,9 @@ pit_type LyXText::undoSpan(pit_type pit)
}
-pit_type LyXText::setLayout(pit_type start, pit_type end, string const & layout)
+void LyXText::setLayout(pit_type start, pit_type end, string const & layout)
{
BOOST_ASSERT(start != end);
- pit_type undopit = undoSpan(end - 1);
- recUndo(start, undopit - 1);
BufferParams const & bufparams = bv()->buffer()->params();
LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
@@ -333,8 +331,6 @@ pit_type LyXText::setLayout(pit_type sta
if (lyxlayout->margintype == MARGIN_MANUAL)
pars_[pit].setLabelWidthString(lyxlayout->labelstring());
}
-
- return undopit;
}
@@ -361,6 +357,8 @@ void LyXText::setLayout(LCursor & cur, s
pit_type start = cur.selBegin().pit();
pit_type end = cur.selEnd().pit() + 1;
+ pit_type undopit = undoSpan(end - 1);
+ recUndo(start, undopit - 1);
setLayout(start, end, layout);
updateCounters(cur.buffer());
}
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1203
diff -u -p -r1.1203 ChangeLog
--- src/insets/ChangeLog 25 Nov 2005 14:40:31 -0000 1.1203
+++ src/insets/ChangeLog 28 Nov 2005 10:54:57 -0000
@@ -1,3 +1,8 @@
+2005-11-28 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:
Index: src/insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.492
diff -u -p -r1.492 insettabular.C
--- src/insets/insettabular.C 17 Nov 2005 08:41:53 -0000 1.492
+++ src/insets/insettabular.C 28 Nov 2005 10:54:57 -0000
@@ -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: