]> git.lyx.org Git - features.git/commitdiff
fix a few small bugs
authorAndré Pönitz <poenitz@gmx.net>
Sun, 18 Apr 2004 19:41:40 +0000 (19:41 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 18 Apr 2004 19:41:40 +0000 (19:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8665 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_gridinset.C
src/mathed/math_hullinset.C
src/mathed/math_nestinset.C
src/undo.C
src/undo.h

index e6a15edd05fad23e1720e6a644a0546d0c920299..e4d35dd53f297e01d7891d1802c51e71f1fab1b6 100644 (file)
@@ -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;
index f86761a8403bae299a27f2d80e10be65f45a1d6d..da3d42eef8733ac6c5da7afd96d351fce126a9c0 100644 (file)
@@ -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();
index e67917f34661a4a59d3e71035bea7fbdba0de0de..79c529bbc3f61731e829f28aa0b2c0917ba97da6 100644 (file)
@@ -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;
index 06f2b6f4aa430f9b8d90dc6edcbdcea338e34475..b0f0fe19310d43d5fa1863009ce08c87ee5641dd 100644 (file)
@@ -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());
index b7dfdba70bbbc1858b6d35410a270b0ec5d1163c..501ace924e1b0bc713d4d9b6ff9ea66ace85b1ed 100644 (file)
@@ -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