On Thu, 2005-02-10 at 10:34, Georg Baum wrote: ...
> It would be nice if you could merge the attached patch with yours and commit > it, because I don't have time to work on that right now. > > > Georg Done. Result attached. Works. - Martin
Index: lib/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ChangeLog,v retrieving revision 1.672 diff -u -r1.672 ChangeLog --- lib/ChangeLog 9 Feb 2005 18:56:00 -0000 1.672 +++ lib/ChangeLog 10 Feb 2005 13:38:07 -0000 @@ -1,3 +1,12 @@ +2005-02-10 Georg Baum <[EMAIL PROTECTED]> + + * ui/stdmenus.ui: add more facilities for drawing/deleting partition + lines in matrix + +2005-02-10 Martin Vermeer <[EMAIL PROTECTED]> + + * bind/math.bind: provide key bindings for lines in matrix + 2005-02-09 Martin Vermeer <[EMAIL PROTECTED]> * ui/stdmenus.ui: add facilities for drawing/deleting partition Index: src/mathed/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v retrieving revision 1.470 diff -u -r1.470 ChangeLog --- src/mathed/ChangeLog 9 Feb 2005 18:56:00 -0000 1.470 +++ src/mathed/ChangeLog 10 Feb 2005 13:38:08 -0000 @@ -1,4 +1,19 @@ -<<<<<<< ChangeLog +2005-02-10 Georg Baum <[EMAIL PROTECTED]> + + * math_gridinset.C (halign): fix '|' to the right of the last column + * math_gridinset.[Ch]: remove unused leftline_ and rightline_ + * math_gridinset.C: add more facilities for adding/deleting + partition lines in matrix. + * math_gridinset.C (getStatus): implement missing LFUN_TABULAR_FEATURE + * math_parser.C (delEmptyLastRow): new + * math_parser.C (parse1): Store active environment and use it to + detect nonmatching \end{} and removing superflous rows with + delEmptyLastRow() + +2005-02-10 Martin Vermeer <[EMAIL PROTECTED]> + + * math_gridinset.C: implement getStatus for tabular-features. + 2005-02-09 Martin Vermeer <[EMAIL PROTECTED]> * math_gridinset.[hC]: add facilities for drawing/deleting partition Index: src/mathed/math_gridinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.C,v retrieving revision 1.155 diff -u -r1.155 math_gridinset.C --- src/mathed/math_gridinset.C 9 Feb 2005 18:56:00 -0000 1.155 +++ src/mathed/math_gridinset.C 10 Feb 2005 13:38:08 -0000 @@ -22,6 +22,7 @@ #include "cursor.h" #include "debug.h" #include "funcrequest.h" +#include "gettext.h" #include "undo.h" #include "frontends/Painter.h" @@ -124,7 +125,7 @@ MathGridInset::ColInfo::ColInfo() - : align_('c'), leftline_(false), rightline_(false), lines_(0) + : align_('c'), lines_(0) {} @@ -215,11 +216,12 @@ { col_type col = 0; for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) { - if (col >= ncols()) - break; char c = *it; if (c == '|') { colinfo_[col].lines_++; + } else if (col >= ncols()) { + // Only '|' is allowed in the last dummy column + break; } else if (c == 'c' || c == 'l' || c == 'r') { colinfo_[col].align_ = c; ++col; @@ -1102,8 +1104,12 @@ swapRow(cur.row()); else if (s == "add-hline-above") rowinfo_[cur.row()].lines_++; + else if (s == "add-hline-below") + rowinfo_[cur.row()+1].lines_++; else if (s == "delete-hline-above") - rowinfo_[cur.row()].lines_ = 0; + rowinfo_[cur.row()].lines_--; + else if (s == "delete-hline-below") + rowinfo_[cur.row()+1].lines_--; else if (s == "append-column") for (int i = 0, n = extractInt(is); i < n; ++i) { row_type r = cur.row(); @@ -1125,9 +1131,13 @@ else if (s == "swap-column") swapCol(col(cur.idx())); else if (s == "add-vline-left") - colinfo_[col(cur.idx())].lines_++; + colinfo_[col(cur.idx())].lines_++; + else if (s == "add-vline-right") + colinfo_[col(cur.idx())+1].lines_++; else if (s == "delete-vline-left") - colinfo_[col(cur.idx())].lines_ = 0; + colinfo_[col(cur.idx())].lines_--; + else if (s == "delete-vline-right") + colinfo_[col(cur.idx())+1].lines_--; else { cur.undispatched(); break; @@ -1223,25 +1233,41 @@ { bool ret = true; switch (cmd.action) { - case LFUN_TABULAR_FEATURE: -#if 0 - // should be more precise - if (v_align_ == '\0') { - flag.enable(true); - break; + case LFUN_TABULAR_FEATURE: { + istringstream is(cmd.argument); + string s; + is >> s; + if (nrows() <= 1 + && (s == "delete-row" || s == "swap-row")) { + flag.message(N_("Only one row")); + flag.enabled(false); + return true; } - if (cmd.argument.empty()) { - flag.enable(false); - break; + if (ncols() <= 1 + && (s == "delete-column" || s == "swap-column")) { + flag.message(N_("Only one column")); + flag.enabled(false); + return true; } - if (!contains("tcb", cmd.argument[0])) { - flag.enable(false); - break; + if ((colinfo_[col(cur.idx())].lines_ == 0 + && (s == "delete-vline-left")) + || ((colinfo_[col(cur.idx()) + 1].lines_ == 0) + && (s == "delete-vline-right"))) { + flag.message(N_("No vline to delete")); + flag.enabled(false); + return true; } - flag.setOnOff(cmd.argument[0] == v_align_); -#endif + if ((rowinfo_[cur.row()].lines_ == 0 + && (s == "delete-hline-above")) + || ((rowinfo_[cur.row() + 1].lines_ == 0) + && (s == "delete-hline-below"))) { + flag.message(N_("No hline to delete")); + flag.enabled(false); + return true; + } flag.enabled(true); - break; + return true; + } default: ret = MathNestInset::getStatus(cur, cmd, flag); break; Index: src/mathed/math_gridinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.h,v retrieving revision 1.85 diff -u -r1.85 math_gridinset.h --- src/mathed/math_gridinset.h 19 Jan 2005 15:03:31 -0000 1.85 +++ src/mathed/math_gridinset.h 10 Feb 2005 13:38:08 -0000 @@ -74,10 +74,6 @@ mutable int width_; /// cached offset mutable int offset_; - /// do we need a line to the left? - bool leftline_; - /// do we need a line to the right? - bool rightline_; /// how many lines to the left of this column? int lines_; /// additional amount to be skipped when drawing @@ -159,21 +155,21 @@ /// pulls cell after pressing erase void idxGlue(idx_type idx); - /// + /// add a row virtual void addRow(row_type r); - /// + /// delete a row virtual void delRow(row_type r); - /// + /// copy a row virtual void copyRow(row_type r); - /// + /// swap two rows virtual void swapRow(row_type r); - /// + /// add a column virtual void addCol(col_type c); - /// + /// delete a column virtual void delCol(col_type c); - /// + /// copy a column virtual void copyCol(col_type c); - /// + /// swap two columns virtual void swapCol(col_type c); /// virtual void appendRow(); @@ -229,9 +225,11 @@ void splitCell(LCursor & cur); public: - /// row info + /// row info. + /// rowinfo_[nrows()] is a dummy row used only for hlines. std::vector<RowInfo> rowinfo_; - /// column info + /// column info. + /// colinfo_[ncols()] is a dummy column used only for vlines. std::vector<ColInfo> colinfo_; /// cell info std::vector<CellInfo> cellinfo_; Index: src/mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.310 diff -u -r1.310 math_parser.C --- src/mathed/math_parser.C 27 Jan 2005 21:05:43 -0000 1.310 +++ src/mathed/math_parser.C 10 Feb 2005 13:38:08 -0000 @@ -159,6 +159,29 @@ return true; } +/*! + * Check wether the last row is empty and remove it if yes. + * Otherwise the following code + * \verbatim +\begin{array}{|c|c|} +\hline +1 & 2 \\ \hline +3 & 4 \\ \hline +\end{array} + * \endverbatim + * will result in a grid with 3 rows (+ the dummy row that is always present), + * because the last '\\' opens a new row. + */ +void delEmptyLastRow(MathGridInset & grid) +{ + MathGridInset::row_type const row = grid.nrows() - 1; + for (MathGridInset::col_type col = 0; col < grid.ncols(); ++col) { + if (!grid.cell(grid.index(row, col)).empty()) + return; + } + grid.delRow(row + 1); +} + // These are TeX's catcodes enum CatCode { @@ -317,6 +340,8 @@ vector<Token> tokens_; /// unsigned pos_; + /// Stack of active environments + vector<string> environments_; }; @@ -897,12 +922,24 @@ else if (t.cs() == "end") { if (flags & FLAG_END) { // eat environment name - //string const name = - getArg('{', '}'); - // FIXME: check that we ended the correct environment - return; - } - error("found 'end' unexpectedly"); + string const name = getArg('{', '}'); + if (environments_.empty()) + error("'found \\end{" + name + + "}' without matching '\\begin{" + + name + "}'"); + else if (name != environments_.back()) + error("'\\end{" + name + + "}' does not match '\\begin{" + + environments_.back() + "}'"); + else { + environments_.pop_back(); + if (name == "array" || + name == "subarray") + delEmptyLastRow(grid); + return; + } + } else + error("found 'end' unexpectedly"); } else if (t.cs() == ")") { @@ -1028,6 +1065,7 @@ else if (t.cs() == "begin") { string const name = getArg('{', '}'); + environments_.push_back(name); if (name == "array" || name == "subarray") { string const valign = parse_verbatim_option() + 'c'; Index: lib/ui/stdmenus.ui =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/stdmenus.ui,v retrieving revision 1.40 diff -u -r1.40 stdmenus.ui --- lib/ui/stdmenus.ui 9 Feb 2005 18:56:01 -0000 1.40 +++ lib/ui/stdmenus.ui 10 Feb 2005 13:38:08 -0000 @@ -159,14 +159,18 @@ Item "Copy Row" "tabular-feature copy-row" Item "Swap Rows" "tabular-feature swap-row" Item "Add Line Above" "tabular-feature add-hline-above" + Item "Add Line Below" "tabular-feature add-hline-below" Item "Delete Line Above" "tabular-feature delete-hline-above" + Item "Delete Line Below" "tabular-feature delete-hline-below" Separator Item "Add Column|C" "tabular-feature append-column" Item "Delete Column|e" "tabular-feature delete-column" Item "Copy Column" "tabular-feature copy-column" Item "Swap Columns" "tabular-feature swap-column" Item "Add Line to Left" "tabular-feature add-vline-left" + Item "Add Line to Right" "tabular-feature add-vline-right" Item "Delete Line to Left" "tabular-feature delete-vline-left" + Item "Delete Line to Right" "tabular-feature delete-vline-right" End Menu "edit_math_limits" Index: lib/bind/math.bind =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/bind/math.bind,v retrieving revision 1.25 diff -u -r1.25 math.bind --- lib/bind/math.bind 19 May 2004 16:27:43 -0000 1.25 +++ lib/bind/math.bind 10 Feb 2005 13:38:08 -0000 @@ -77,11 +77,19 @@ \bind "M-m c d" "tabular-feature delete-column" \bind "M-m c c" "tabular-feature copy-column" \bind "M-m c s" "tabular-feature swap-column" +\bind "M-m c a" "tabular-feature add-vline-left" +\bind "M-m c e" "tabular-feature delete-vline-left" +\bind "M-m c z" "tabular-feature add-vline-right" +\bind "M-m c x" "tabular-feature delete-vline-right" \bind "M-m w i" "tabular-feature append-row" \bind "M-m w d" "tabular-feature delete-row" \bind "M-m w c" "tabular-feature copy-row" \bind "M-m w s" "tabular-feature swap-row" +\bind "M-m w a" "tabular-feature add-hline-above" +\bind "M-m w e" "tabular-feature delete-hline-above" +\bind "M-m w z" "tabular-feature add-hline-below" +\bind "M-m w x" "tabular-feature delete-hline-below" \bind "M-m w t" "tabular-feature valign-top" \bind "M-m w m" "tabular-feature valign-middle"
signature.asc
Description: This is a digitally signed message part