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);
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);
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;
#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"
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()));
}
}
-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;
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();
using std::vector;
+void mathed_parse_normal(MathGridInset &, string const & argument);
+
namespace {
string verboseHLine(int n)
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;
#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>
}
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
///
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_; }
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);
{
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);
+}
+
class MathAtom;
class MathArray;
+class MathGridInset;
class LyXLex;
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 &);