]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathGrid.cpp
index f3058c54c1fa61e1b3f19d1a5d4e99e9951549b9..61e13dfe8c0904839ad562563138a05d8cc9b6bd 100644 (file)
@@ -766,7 +766,7 @@ void InsetMathGrid::delCol(col_type col)
 
 void InsetMathGrid::copyCol(col_type col)
 {
-       addCol(col);
+       addCol(col+1);
        for (row_type row = 0; row < nrows(); ++row)
                cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
 }
@@ -980,20 +980,27 @@ void InsetMathGrid::mathmlize(MathStream & os) const
 
 
 void InsetMathGrid::write(WriteStream & os) const
+{
+       write(os, 0, 0, nrows(), ncols());
+}
+
+void InsetMathGrid::write(WriteStream & os,
+                         row_type beg_row, col_type beg_col,
+                         row_type end_row, col_type end_col) const
 {
        MathEnsurer ensurer(os, false);
        docstring eol;
-       for (row_type row = 0; row < nrows(); ++row) {
+       for (row_type row = beg_row; row < end_row; ++row) {
                os << verboseHLine(rowinfo_[row].lines_);
                // don't write & and empty cells at end of line
                col_type lastcol = 0;
                bool emptyline = true;
-               for (col_type col = 0; col < ncols(); ++col)
+               for (col_type col = beg_col; col < end_col; ++col)
                        if (!cell(index(row, col)).empty()) {
                                lastcol = col + 1;
                                emptyline = false;
                        }
-               for (col_type col = 0; col < lastcol; ++col) {
+               for (col_type col = beg_col; col < lastcol; ++col) {
                        os << cell(index(row, col));
                        if (os.pendingBrace())
                                ModeSpecifier specifier(os, TEXT_MODE);
@@ -1003,9 +1010,10 @@ void InsetMathGrid::write(WriteStream & os) const
                os << eol;
                // append newline only if line wasn't completely empty
                // and this was not the last line in the grid
-               if (!emptyline && row + 1 < nrows())
+               if (!emptyline && row + 1 < end_row)
                        os << "\n";
        }
+       // @TODO use end_row instead of nrows() ?
        docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
        if (!s.empty()) {
                if (eol.empty()) {
@@ -1366,7 +1374,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        switch (cmd.action) {
        case LFUN_TABULAR_FEATURE: {
-               string const s = to_utf8(cmd.argument());
+               string const s = cmd.getArg(0);
                if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
                        status.setEnabled(false);
                        status.message(from_utf8(N_("Only one row")));
@@ -1397,8 +1405,18 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                }
                if (s == "valign-top" || s == "valign-middle" ||
                    s == "valign-bottom" || s == "align-left" ||
-                   s == "align-right" || s == "align-center" ||
-                   s == "append-row" || s == "delete-row" ||
+                   s == "align-right" || s == "align-center") {
+                       status.setEnabled(true);
+                       char const ha = horizontalAlignment(cur.col());
+                       char const va = verticalAlignment();
+                       status.setOnOff((s == "align-left" && ha == 'l')
+                                       || (s == "align-right"   && ha == 'r')
+                                       || (s == "align-center"  && ha == 'c')
+                                       || (s == "valign-top"    && va == 't')
+                                       || (s == "valign-bottom" && va == 'b')
+                                       || (s == "valign-middle" && va == 'm'));
+               }
+               if (s == "append-row" || s == "delete-row" ||
                    s == "copy-row" || s == "swap-row" ||
                    s == "add-hline-above" || s == "add-hline-below" ||
                    s == "delete-hline-above" || s == "delete-hline-below" ||
@@ -1413,15 +1431,6 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                                from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
                }
 
-               char const ha = horizontalAlignment(cur.col());
-               char const va = verticalAlignment();
-               status.setOnOff((s == "align-left" && ha == 'l')
-                          || (s == "align-right"   && ha == 'r')
-                          || (s == "align-center"  && ha == 'c')
-                          || (s == "valign-top"    && va == 't')
-                          || (s == "valign-bottom" && va == 'b')
-                          || (s == "valign-middle" && va == 'm'));
-
 #if 0
                // FIXME: What did this code do?
                // Please check whether it is still needed!