]> git.lyx.org Git - features.git/commitdiff
more lfun localization
authorAndré Pönitz <poenitz@gmx.net>
Wed, 14 Aug 2002 16:11:55 +0000 (16:11 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 14 Aug 2002 16:11:55 +0000 (16:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4971 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_gridinset.C
src/mathed/math_hullinset.C
src/mathed/math_parser.C
src/mathed/math_parser.h

index 6bba12d070a90779e030217d38228c3c0f685efb..acc8ac788d83eb95bb2c27e6db9f6528683314fa 100644 (file)
@@ -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<bool, string> 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);
index dd3879219067966af738cdc80e1964e8568639d4..f19c00cec118a527245627a8686b5bda9c92de96 100644 (file)
@@ -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;
index 02593a8b5e4d894cbb950add31a059e7331f2803..ea9cfc5d4a862abd8fcc38b984b8487cb9e897e1 100644 (file)
@@ -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;
index a653a4950b52ee7600df32960b40b80ccd731ff8..5fad2e14b5ef2f4cb85010d95b4de025e973d5e3 100644 (file)
@@ -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();
index 3042e0085f65d7ba7f8003880b3e049699b9e302..70fb5c6ccbe96bc8ce31759a6adc7aa5de33a0de 100644 (file)
@@ -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;
index 80f855a41f8cc1ffc374299705c8ae387b8d598c..e4b1768b738bab089678e1b59bfdd90ac5e571e8 100644 (file)
@@ -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 <vector>
 
@@ -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<bool, string> 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
index f24ea2abfef77620af24acf013bdb4ad7715e196..0ea4cee7c238c5d41b5723734b0c960bae044664 100644 (file)
@@ -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);
+}
+
index 25e57dd769cd7e6b41f7deab07e76c5c30643ebe..533496f15f32a993301d17ffe1879e7e60cd7ee3 100644 (file)
@@ -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 &);