From 69a1e730ae9e0834c7e0c58a63f54341d6e146d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 14 Aug 2002 16:11:55 +0000 Subject: [PATCH] more lfun localization git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4971 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formula.C | 43 +--------------------------------- src/mathed/formulabase.C | 34 ++++++--------------------- src/mathed/math_cursor.C | 46 ++++--------------------------------- src/mathed/math_cursor.h | 8 ------- src/mathed/math_gridinset.C | 35 +++++++++++++++++++++++++++- src/mathed/math_hullinset.C | 39 ++++++++++++++++++++++++++++++- src/mathed/math_parser.C | 14 ++++++++--- src/mathed/math_parser.h | 3 +++ 8 files changed, 99 insertions(+), 123 deletions(-) diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 6bba12d070..acc8ac788d 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -254,51 +254,10 @@ UpdatableInset::RESULT InsetFormula::localDispatch(FuncRequest const & ev) { RESULT result = DISPATCHED; - BufferView *bv = ev.view(); + BufferView * bv = ev.view(); switch (ev.action) { - case LFUN_INSERT_LABEL: - { - if (!hull()) - break; - - bv->lockedInsetStoreUndo(Undo::EDIT); - - MathCursor::row_type row = mathcursor->hullRow(); - string old_label = hull()->label(row); - string new_label = ev.argument; - - if (new_label.empty()) { - string const default_label = - (lyxrc.label_init_length >= 0) ? "eq:" : ""; - pair const res = old_label.empty() - ? Alert::askForText(_("Enter new label to insert:"), default_label) - : Alert::askForText(_("Enter label:"), old_label); - if (!res.first) - break; - new_label = trim(res.second); - } - - //if (new_label == old_label) - // break; // Nothing to do - - if (!new_label.empty()) { - lyxerr << "setting label to '" << new_label << "'\n"; - hull()->numbered(row, true); - } - -#warning FIXME: please check you really mean repaint() ... is it needed, -#warning and if so, should it be update() instead ? - if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label)) - bv->repaint(); - - hull()->label(row, new_label); - - updateLocal(bv, true); - break; - } - case LFUN_MATH_MUTATE: { bv->lockedInsetStoreUndo(Undo::EDIT); diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index dd38792190..f19c00cec1 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -416,11 +416,18 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev) switch (ev.action) { + case LFUN_MATH_HALIGN: + case LFUN_MATH_VALIGN: + case LFUN_MATH_ROW_INSERT: + case LFUN_MATH_ROW_DELETE: + case LFUN_MATH_COLUMN_INSERT: + case LFUN_MATH_COLUMN_DELETE: case LFUN_MATH_NUMBER: case LFUN_MATH_NONUMBER: case LFUN_TABINSERT: case LFUN_BREAKLINE: case LFUN_DELETE_LINE_FORWARD: + case LFUN_INSERT_LABEL: bv->lockedInsetStoreUndo(Undo::EDIT); mathcursor->dispatch(ev); updateLocal(bv, true); @@ -663,33 +670,6 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev) break; - case LFUN_MATH_HALIGN: - case LFUN_MATH_VALIGN: - case LFUN_MATH_ROW_INSERT: - case LFUN_MATH_ROW_DELETE: - case LFUN_MATH_COLUMN_INSERT: - case LFUN_MATH_COLUMN_DELETE: - { - MathInset::idx_type idx = 0; - MathGridInset * p = mathcursor ? mathcursor->enclosingGrid(idx) : 0; - if (p) { - mathcursor->popToEnclosingGrid(); - bv->lockedInsetStoreUndo(Undo::EDIT); - char align = ev.argument.size() ? ev.argument[0] : 'c'; - switch (ev.action) { - case LFUN_MATH_HALIGN: p->halign(align, p->col(idx)); break; - case LFUN_MATH_VALIGN: p->valign(align); break; - case LFUN_MATH_ROW_INSERT: p->addRow(p->row(idx)); break; - case LFUN_MATH_ROW_DELETE: p->delRow(p->row(idx)); break; - case LFUN_MATH_COLUMN_INSERT: p->addFancyCol(p->col(idx)); break; - case LFUN_MATH_COLUMN_DELETE: p->delFancyCol(p->col(idx)); break; - default: ; - } - updateLocal(bv, true); - } - break; - } - case LFUN_EXEC_COMMAND: result = UNDISPATCHED; break; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 02593a8b5e..ea9cfc5d4a 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -30,6 +30,7 @@ #include "frontends/Painter.h" #include "math_cursor.h" #include "formulabase.h" +#include "funcrequest.h" #include "math_autocorrect.h" #include "math_arrayinset.h" #include "math_braceinset.h" @@ -411,31 +412,10 @@ void MathCursor::paste(MathArray const & ar) void MathCursor::paste(MathGridInset const & data) { - if (data.nargs() == 1) { - // single cell/part of cell - paste(data.cell(0)); - } else { - // multiple cells - idx_type idx; // index of upper left cell - MathGridInset * p = enclosingGrid(idx); - col_type const numcols = min(data.ncols(), p->ncols() - p->col(idx)); - row_type const numrows = min(data.nrows(), p->nrows() - p->row(idx)); - for (row_type row = 0; row < numrows; ++row) { - for (col_type col = 0; col < numcols; ++col) { - idx_type i = p->index(row + p->row(idx), col + p->col(idx)); - p->cell(i).append(data.cell(data.index(row, col))); - } - // append the left over horizontal cells to the last column - idx_type i = p->index(row + p->row(idx), p->ncols() - 1); - for (MathInset::col_type col = numcols; col < data.ncols(); ++col) - p->cell(i).append(data.cell(data.index(row, col))); - } - // append the left over vertical cells to the last _cell_ - idx_type i = p->nargs() - 1; - for (row_type row = numrows; row < data.nrows(); ++row) - for (col_type col = 0; col < data.ncols(); ++col) - p->cell(i).append(data.cell(data.index(row, col))); - } + ostringstream os; + WriteStream wi(os, false, false); + data.write(wi); + dispatch(FuncRequest(LFUN_PASTE, os.str())); } @@ -870,22 +850,6 @@ MathCursor::size_type MathCursor::size() const } -MathCursor::col_type MathCursor::hullCol() const -{ - idx_type idx = 0; - MathHullInset * p = enclosingHull(idx); - return p->col(idx); -} - - -MathCursor::row_type MathCursor::hullRow() const -{ - idx_type idx = 0; - MathHullInset * p = enclosingHull(idx); - return p->row(idx); -} - - bool MathCursor::hasPrevAtom() const { return pos() > 0; diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index a653a4950b..5fad2e14b5 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -177,14 +177,6 @@ public: char valign() const; /// char halign() const; - /// - col_type hullCol() const; - /// - row_type hullRow() const; - /// - col_type gridCol() const; - /// - row_type gridRow() const; /// make sure cursor position is valid void normalize(); diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 3042e0085f..70fb5c6ccb 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -17,6 +17,8 @@ using std::min; using std::vector; +void mathed_parse_normal(MathGridInset &, string const & argument); + namespace { string verboseHLine(int n) @@ -995,7 +997,38 @@ MathInset::result_type MathGridInset::dispatch if (idx > nargs()) idx -= ncols(); return DISPATCHED_POP; - } + } + + case LFUN_PASTE: { + //lyxerr << "pasting '" << cmd.argument << "'\n"; + MathGridInset grid(1, 1); + mathed_parse_normal(grid, cmd.argument); + if (grid.nargs() == 1) { + // single cell/part of cell + cell(idx).insert(pos, grid.cell(0)); + pos += grid.cell(0).size(); + } else { + // multiple cells + col_type const numcols = min(grid.ncols(), ncols() - col(idx)); + row_type const numrows = min(grid.nrows(), nrows() - row(idx)); + for (row_type r = 0; r < numrows; ++r) { + for (col_type c = 0; c < numcols; ++c) { + idx_type i = index(r + row(idx), c + col(idx)); + cell(i).append(grid.cell(grid.index(r, c))); + } + // append the left over horizontal cells to the last column + idx_type i = index(r + row(idx), ncols() - 1); + for (MathInset::col_type c = numcols; c < grid.ncols(); ++c) + cell(i).append(grid.cell(grid.index(r, c))); + } + // append the left over vertical cells to the last _cell_ + idx_type i = nargs() - 1; + for (row_type r = numrows; r < grid.nrows(); ++r) + for (col_type c = 0; c < grid.ncols(); ++c) + cell(i).append(grid.cell(grid.index(r, c))); + } + return DISPATCHED_POP; + } default: break; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 80f855a41f..e4b1768b73 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -9,12 +9,17 @@ #include "math_streamstr.h" #include "math_support.h" #include "debug.h" -#include "frontends/Painter.h" #include "textpainter.h" #include "funcrequest.h" #include "Lsstream.h" #include "LaTeXFeatures.h" #include "support/LAssert.h" +#include "frontends/Painter.h" + +#include "frontends/Alert.h" +#include "lyxrc.h" +#include "gettext.h" +#include "BufferView.h" #include @@ -684,6 +689,38 @@ MathInset::result_type MathHullInset::dispatch } return DISPATCHED; + case LFUN_INSERT_LABEL: { + row_type r = row(idx); + string old_label = label(r); + string new_label = cmd.argument; + + if (new_label.empty()) { + string const default_label = + (lyxrc.label_init_length >= 0) ? "eq:" : ""; + pair const res = old_label.empty() + ? Alert::askForText(_("Enter new label to insert:"), default_label) + : Alert::askForText(_("Enter label:"), old_label); + if (!res.first) + break; + new_label = trim(res.second); + } + + //if (new_label == old_label) + // break; // Nothing to do + + if (!new_label.empty()) + numbered(r, true); + +#warning FIXME: please check you really mean repaint() ... is it needed, +#warning and if so, should it be update() instead ? + if (!new_label.empty() + && cmd.view()->ChangeRefsIfUnique(old_label, new_label)) + cmd.view()->repaint(); + + label(r, new_label); + return DISPATCHED; + } + case LFUN_MATH_HALIGN: case LFUN_MATH_VALIGN: // we explicitly don't want the default behaviour here diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index f24ea2abfe..0ea4cee7c2 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -232,6 +232,9 @@ public: /// void parse(MathArray & array, unsigned flags, mode_type mode); /// + void parse1(MathGridInset & grid, unsigned flags, mode_type mode, + bool numbered); + /// MathArray parse(unsigned flags, mode_type mode); /// int lineno() const { return lineno_; } @@ -240,9 +243,6 @@ public: private: /// - void parse1(MathGridInset & grid, unsigned flags, mode_type mode, - bool numbered); - /// void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered); /// get arg delimited by 'left' and 'right' string getArg(char left, char right); @@ -1187,3 +1187,11 @@ bool mathed_parse_normal(MathAtom & t, LyXLex & lex) { return Parser(lex).parse(t); } + + +void mathed_parse_normal(MathGridInset & grid, string const & str) +{ + istringstream is(str.c_str()); + Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false); +} + diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 25e57dd769..533496f15f 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -27,6 +27,7 @@ class MathAtom; class MathArray; +class MathGridInset; class LyXLex; @@ -54,6 +55,8 @@ bool mathed_parse_normal(MathAtom &, string const &); bool mathed_parse_normal(MathAtom &, std::istream &); /// ... the LyX lexxer bool mathed_parse_normal(MathAtom &, LyXLex &); +/// ... the LyX lexxer +void mathed_parse_normal(MathGridInset &, string const &); /// parse a single cell from a string void mathed_parse_cell(MathArray & ar, string const &); -- 2.39.2