From: Georg Baum Date: Wed, 27 Sep 2006 16:28:09 +0000 (+0000) Subject: Implement copying of rows and columns in tables X-Git-Tag: 1.6.10~12498 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=70d57a230099e817579520242a73e182bd06b4d9;hp=864515f3a32c4df83c477281468434a4f0a54a33;p=lyx.git Implement copying of rows and columns in tables * src/insets/insettabular.C (InsetTabular::getStatus): enable COPY_ROW and COPY_COLUMN features (InsetTabular::tabularFeatures): handle COPY_ROW and COPY_COLUMN * src/tabular.h (TabularFeature): add COPY_ROW and COPY_COLUMN * src/tabular.[Ch] (LyXTabular::copyRow): new method, copy a row (LyXTabular::copyColumn): new method, copy a column git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15173 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 3b36294d40..0774f66c3f 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -95,6 +95,8 @@ TabularFeature tabularFeature[] = { LyXTabular::APPEND_COLUMN, "append-column" }, { LyXTabular::DELETE_ROW, "delete-row" }, { LyXTabular::DELETE_COLUMN, "delete-column" }, + { LyXTabular::COPY_ROW, "copy-row" }, + { LyXTabular::COPY_COLUMN, "copy-column" }, { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" }, { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" }, { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" }, @@ -826,6 +828,8 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd, case LyXTabular::APPEND_COLUMN: case LyXTabular::DELETE_ROW: case LyXTabular::DELETE_COLUMN: + case LyXTabular::COPY_ROW: + case LyXTabular::COPY_COLUMN: case LyXTabular::SET_ALL_LINES: case LyXTabular::UNSET_ALL_LINES: case LyXTabular::SET_TOP_SPACE: @@ -1461,6 +1465,15 @@ void InsetTabular::tabularFeatures(LCursor & cur, cur.selection() = false; break; + case LyXTabular::COPY_ROW: + tabular.copyRow(bv.buffer()->params(), row); + break; + + case LyXTabular::COPY_COLUMN: + tabular.copyColumn(bv.buffer()->params(), column); + cur.idx() = tabular.getCellNumber(row, column); + break; + case LyXTabular::M_TOGGLE_LINE_TOP: flag = false; case LyXTabular::TOGGLE_LINE_TOP: { diff --git a/src/tabular.C b/src/tabular.C index 60c20f9d55..25aea3843b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -516,6 +516,21 @@ void LyXTabular::deleteRow(row_type const row) } +void LyXTabular::copyRow(BufferParams const & bp, row_type const row) +{ + ++rows_; + + row_info.insert(row_info.begin() + row, row_info[row]); + cell_info.insert(cell_info.begin() + row, cell_info[row]); + + if (bp.tracking_changes) + for (col_type j = 0; j < columns_; ++j) + cell_info[row + 1][j].inset->markNew(true); + + set_row_column_number_info(); +} + + void LyXTabular::appendColumn(BufferParams const & bp, idx_type const cell) { ++columns_; @@ -561,6 +576,22 @@ void LyXTabular::deleteColumn(col_type const column) } +void LyXTabular::copyColumn(BufferParams const & bp, col_type const column) +{ + ++columns_; + + column_info.insert(column_info.begin() + column, column_info[column]); + + for (row_type i = 0; i < rows_; ++i) + cell_info[i].insert(cell_info[i].begin() + column, cell_info[i][column]); + + if (bp.tracking_changes) + for (row_type i = 0; i < rows_; ++i) + cell_info[i][column + 1].inset->markNew(true); + fixCellNums(); +} + + void LyXTabular::set_row_column_number_info() { numberofcells = 0; diff --git a/src/tabular.h b/src/tabular.h index 6b2fb6afde..e3fe328fe8 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -43,6 +43,10 @@ public: /// DELETE_COLUMN, /// + COPY_ROW, + /// + COPY_COLUMN, + /// TOGGLE_LINE_TOP, /// TOGGLE_LINE_BOTTOM, @@ -282,10 +286,14 @@ public: /// void deleteRow(row_type row); /// + void copyRow(BufferParams const &, row_type); + /// void appendColumn(BufferParams const &, idx_type cell); /// void deleteColumn(col_type column); /// + void copyColumn(BufferParams const &, col_type); + /// bool isFirstCellInRow(idx_type cell) const; /// idx_type getFirstCellInRow(row_type row) const;