#include "cursor.h"
#include "debug.h"
#include "funcrequest.h"
+#include "undo.h"
#include "frontends/Painter.h"
// insert file functions
case LFUN_DELETE_LINE_FORWARD:
+ recordUndo(cur);
//autocorrect_ = false;
//macroModeClose();
//if (selection_) {
break;
case LFUN_CELL_SPLIT:
- ////recordUndo(cur, Undo::ATOMIC);
+ recordUndo(cur);
splitCell(cur);
break;
case LFUN_BREAKLINE: {
- ////recordUndo(cur, Undo::INSERT);
+ recordUndo(cur);
row_type const r = cur.row();
addRow(r);
swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
if (cur.idx() > 0)
--cur.idx();
- cur.idx() = cur.lastpos();
+ cur.pos() = cur.lastpos();
//mathcursor->normalize();
- cmd = FuncRequest(LFUN_FINISHED_LEFT);
+ //cmd = FuncRequest(LFUN_FINISHED_LEFT);
break;
}
case LFUN_TABULAR_FEATURE: {
+ recordUndo(cur);
//lyxerr << "handling tabular-feature " << cmd.argument << endl;
istringstream is(cmd.argument);
string s;
}
case LFUN_PASTE: {
+ recordUndo(cur);
lyxerr << "MathGridInset: PASTE: " << cmd << std::endl;
istringstream is(cmd.argument);
int n = 0;
case LFUN_BREAKLINE:
if (type_ == "simple" || type_ == "equation") {
+ recordUndoInset(cur);
mutate("eqnarray");
- cur.idx() = 1;
- cur.pos() = 0;
- //cur.dispatched(FINISHED);
+ cur.idx() = 0;
+ cur.pos() = cur.lastpos();
break;
}
MathGridInset::priv_dispatch(cur, cmd);
case LFUN_MATH_NUMBER:
//lyxerr << "toggling all numbers" << endl;
if (display()) {
- recordUndo(cur);
+ recordUndoInset(cur);
bool old = numberedType();
if (type_ == "multline")
numbered(nrows() - 1, !old);
case LFUN_MATH_NONUMBER:
if (display()) {
+ recordUndoInset(cur);
row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
- recordUndo(cur);
bool old = numbered(r);
cur.message(old ? _("No number") : _("Number"));
numbered(r, !old);
break;
case LFUN_INSERT_LABEL: {
+ recordUndoInset(cur);
row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
string old_label = label(r);
string new_label = cmd.argument;
}
case LFUN_MATH_EXTERN:
+ recordUndoInset(cur);
doExtern(cur, cmd);
- //cur.dispatched(FINISHED);
break;
case LFUN_MATH_MUTATE: {
- lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
+ recordUndoInset(cur);
row_type row = cur.row();
col_type col = cur.col();
mutate(cmd.argument);
}
case LFUN_MATH_DISPLAY: {
+ recordUndoInset(cur);
mutate(type_ == "simple" ? "equation" : "simple");
cur.idx() = 0;
cur.pos() = cur.lastpos();
switch (cmd.action) {
case LFUN_PASTE: {
+ recordUndo(cur);
cur.message(_("Paste"));
replaceSelection(cur);
size_t n = 0;
break;
case LFUN_FINISHED_UP:
- //idxUpDown(cur, true);
cur.bv().cursor() = cur;
break;
case LFUN_FINISHED_DOWN:
- //idxUpDown(cur, false);
cur.bv().cursor() = cur;
break;
case LFUN_DELETE_WORD_FORWARD:
case LFUN_DELETE:
- recordUndo(cur, Undo::ATOMIC);
+ recordUndo(cur);
cur.erase();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
break;
break;
case LFUN_INSET_TOGGLE:
+ recordUndo(cur);
//lockToggle();
if (cur.pos() != cur.lastpos()) {
// toggle previous inset ...
break;
case LFUN_SELFINSERT:
- if (cmd.argument.empty()) {
- cmd = FuncRequest(LFUN_FINISHED_RIGHT);
- break;
- }
- recordUndo(cur, Undo::ATOMIC);
+ recordUndo(cur);
if (cmd.argument.size() != 1) {
cur.insert(cmd.argument);
break;
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
break;
-#if 0
-//
-// this needs to be incorporated
-//
- // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
- bool remove_inset = false;
-
- DispatchResult result(true);
- bool was_macro = cur.inMacroMode();
-
- cur.normalize();
- cur.touch();
-#endif
+ //case LFUN_GETXY:
+ // sprintf(dispatch_buffer, "%d %d",);
+ // break;
- // case LFUN_GETXY:
- // sprintf(dispatch_buffer, "%d %d",);
- // DispatchResult= dispatch_buffer;
- // break;
case LFUN_SETXY: {
lyxerr << "LFUN_SETXY broken!" << endl;
int x = 0;
cur.posLeft();
cur.pushLeft(*cur.nextInset());
#else
- if (currentMode() == InsetBase::TEXT_MODE)
+ if (currentMode() == InsetBase::TEXT_MODE) {
cur.niceInsert(MathAtom(new MathHullInset("simple")));
- else
+ cur.message(_("create new math text environment ($...$)"));
+ } else {
handleFont(cur, cmd.argument, "textrm");
- //cur.owner()->message(_("math text mode toggled"));
+ cur.message(_("entered math text mode (textrm)"));
+ }
#endif
break;
case LFUN_MATH_SIZE:
#if 0
- if (!arg.empty()) {
- recordUndo(cur, Undo::ATOMIC);
- cur.setSize(arg);
- }
+ recordUndo(cur);
+ cur.setSize(arg);
#endif
break;
break;
}
-#ifdef WITH_WARNINGS
-#warning look here
-#endif
-#if 0
-
- case LFUN_WORD_REPLACE:
- case LFUN_WORD_FIND:
- if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
- cur.undispatched();
- break;
-
- cur.normalize();
- cur.touch();
-
- BOOST_ASSERT(cur.inMathed());
-
- if (result.dispatched()) {
- revealCodes(cur);
- cur.bv().stuffClipboard(cur.grabSelection());
- } else {
- if (remove_inset)
- cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
- }
- break;
-#endif
-
default:
MathDimInset::priv_dispatch(cur, cmd);
break;
Buffer * buf = cur.bv().buffer();
recordUndo(kind, cur, first, last, buf->undostack());
buf->redostack().clear();
- //lyxerr << "undostack:\n";
- //for (size_t i = 0, n = buf->undostack().size(); i != n && i < 6; ++i)
- // lyxerr << " " << i << ": " << buf->undostack()[i] << std::endl;
+ lyxerr << "undostack:\n";
+ for (size_t i = 0, n = buf->undostack().size(); i != n && i < 6; ++i)
+ lyxerr << " " << i << ": " << buf->undostack()[i] << std::endl;
}
}
+void recordUndoInset(LCursor & cur, Undo::undo_kind kind)
+{
+ LCursor c = cur;
+ c.pop();
+ recordUndo(c, kind);
+}
+
+
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind)
{
recordUndo(kind, cur, cur.selBegin().par(), cur.selEnd().par());
ATOMIC
};
- /// which kind of operation are we recording for?
+ /// Which kind of operation are we recording for?
undo_kind kind;
/// the position of the cursor
StableDocIterator cursor;
* will record the original information of the paragraphs in the undo stack.
*/
-/// the common case: prepare undo for an arbitrary range
+/// The general case: prepare undo for an arbitrary range.
void recordUndo(LCursor & cur, Undo::undo_kind kind,
lyx::par_type from, lyx::par_type to);
-/// convienience: prepare undo for the range between 'from' and cursor.
+/// Convenience: prepare undo for the range between 'from' and cursor.
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::par_type from);
-/// convienience: prepare undo for the single paragraph containing the cursor
+/// Convenience: prepare undo for the single paragraph or cell
+/// containing the cursor
void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
-/// convienience: prepare undo for the selected paragraphs
+/// Convenience: prepare undo for the inset containing the cursor
+void recordUndoInset(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
+/// Convenience: prepare undo for the selected paragraphs
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
-/// convienience: prepare undo for the single paragraph containing the cursor
+/// Convenience: prepare undo for the single paragraph containing the cursor
void recordUndoFullDocument(LCursor & cur);
#endif // UNDO_FUNCS_H