From: André Pönitz Date: Sun, 18 Apr 2004 19:41:40 +0000 (+0000) Subject: fix a few small bugs X-Git-Tag: 1.6.10~15303 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=91fdb608a00f4699ab1d456b530ecaa9a6dd5354;p=features.git fix a few small bugs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8665 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index e6a15edd05..e4d35dd53f 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -22,6 +22,7 @@ #include "cursor.h" #include "debug.h" #include "funcrequest.h" +#include "undo.h" #include "frontends/Painter.h" @@ -1026,6 +1027,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) // insert file functions case LFUN_DELETE_LINE_FORWARD: + recordUndo(cur); //autocorrect_ = false; //macroModeClose(); //if (selection_) { @@ -1041,12 +1043,12 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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); @@ -1059,14 +1061,15 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -1126,6 +1129,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_PASTE: { + recordUndo(cur); lyxerr << "MathGridInset: PASTE: " << cmd << std::endl; istringstream is(cmd.argument); int n = 0; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index f86761a840..da3d42eef8 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -890,10 +890,10 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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); @@ -902,7 +902,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & 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); @@ -915,8 +915,8 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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); @@ -924,6 +924,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -944,12 +945,12 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) } 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); @@ -965,6 +966,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_MATH_DISPLAY: { + recordUndoInset(cur); mutate(type_ == "simple" ? "equation" : "simple"); cur.idx() = 0; cur.pos() = cur.lastpos(); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index e67917f346..79c529bbc3 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -381,6 +381,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_PASTE: { + recordUndo(cur); cur.message(_("Paste")); replaceSelection(cur); size_t n = 0; @@ -425,12 +426,10 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -569,7 +568,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_DELETE_WORD_FORWARD: case LFUN_DELETE: - recordUndo(cur, Undo::ATOMIC); + recordUndo(cur); cur.erase(); cmd = FuncRequest(LFUN_FINISHED_LEFT); break; @@ -582,6 +581,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) break; case LFUN_INSET_TOGGLE: + recordUndo(cur); //lockToggle(); if (cur.pos() != cur.lastpos()) { // toggle previous inset ... @@ -594,11 +594,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -607,24 +603,10 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -707,20 +689,20 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; @@ -807,32 +789,6 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) 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; diff --git a/src/undo.C b/src/undo.C index 06f2b6f4aa..b0f0fe1931 100644 --- a/src/undo.C +++ b/src/undo.C @@ -212,9 +212,9 @@ void recordUndo(Undo::undo_kind kind, 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; } @@ -224,6 +224,14 @@ void recordUndo(LCursor & cur, Undo::undo_kind kind) } +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()); diff --git a/src/undo.h b/src/undo.h index b7dfdba70b..501ace924e 100644 --- a/src/undo.h +++ b/src/undo.h @@ -49,7 +49,7 @@ struct Undo { 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; @@ -81,19 +81,22 @@ void finishUndo(); * 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