]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_hullinset.C
revert Buffer LyxText->InsetText commit
[lyx.git] / src / mathed / math_hullinset.C
index 3792460af2da39ebd842ff63bca371eee7969092..3f46a091c1a015ea127865f8455b4d6611da6be0 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "support/std_sstream.h"
 
-using lyx::support::trim;
 
 using std::endl;
 using std::max;
@@ -785,96 +784,98 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
 }
 
 
-DispatchResult
-MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       lyxerr << "*** MathHullInset: request: " << cmd << endl;
+       //lyxerr << "*** MathHullInset: request: " << cmd << endl;
        switch (cmd.action) {
 
-               case LFUN_BREAKLINE:
-                       if (type_ == "simple" || type_ == "equation") {
-                               mutate("eqnarray");
-                               cur.idx() = 1;
-                               cur.pos() = 0;
-                               return DispatchResult(true, FINISHED);
-                       }
-                       return MathGridInset::priv_dispatch(cur, cmd);
-
-               case LFUN_MATH_NUMBER:
-                       //lyxerr << "toggling all numbers" << endl;
-                       if (display()) {
-                               ////recordUndo(cur, Undo::INSERT);
-                               bool old = numberedType();
-                               if (type_ == "multline")
-                                       numbered(nrows() - 1, !old);
-                               else
-                                       for (row_type row = 0; row < nrows(); ++row)
-                                               numbered(row, !old);
-                               cur.message(old ? _("No number") : _("Number"));
-                       }
-                       return DispatchResult(true, true);
-
-               case LFUN_MATH_NONUMBER:
-                       if (display()) {
-                               row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
-                               ////recordUndo(cur, Undo::INSERT);
-                               bool old = numbered(r);
-                               cur.message(old ? _("No number") : _("Number"));
-                               numbered(r, !old);
-                       }
-                       return DispatchResult(true, true);
-
-               case LFUN_INSERT_LABEL: {
-                       row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
-                       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)
-                                       return DispatchResult(false);
-                               new_label = trim(res.second);
-                       }
+       case LFUN_BREAKLINE:
+               if (type_ == "simple" || type_ == "equation") {
+                       mutate("eqnarray");
+                       cur.idx() = 1;
+                       cur.pos() = 0;
+                       //cur.dispatched(FINISHED);
+                       return;
+               }
+               MathGridInset::priv_dispatch(cur, cmd);
+               return;
 
-                       //if (new_label == old_label)
-                       //      break;  // Nothing to do
+       case LFUN_MATH_NUMBER:
+               //lyxerr << "toggling all numbers" << endl;
+               if (display()) {
+                       ////recordUndo(cur, Undo::INSERT);
+                       bool old = numberedType();
+                       if (type_ == "multline")
+                               numbered(nrows() - 1, !old);
+                       else
+                               for (row_type row = 0; row < nrows(); ++row)
+                                       numbered(row, !old);
+                       cur.message(old ? _("No number") : _("Number"));
+               }
+               return;
 
-                       if (!new_label.empty())
-                               numbered(r, true);
-                       label(r, new_label);
-                       return DispatchResult(true, true);
+       case LFUN_MATH_NONUMBER:
+               if (display()) {
+                       row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+                       ////recordUndo(cur, Undo::INSERT);
+                       bool old = numbered(r);
+                       cur.message(old ? _("No number") : _("Number"));
+                       numbered(r, !old);
                }
+               return;
 
-               case LFUN_MATH_EXTERN:
-                       doExtern(cur, cmd);
-                       return DispatchResult(true, FINISHED);
-
-               case LFUN_MATH_MUTATE: {
-                       lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
-                       row_type r = cur.row();
-                       col_type c = cur.col();
-                       mutate(cmd.argument);
-                       cur.idx() = r * ncols() + c;
-                       if (cur.idx() >= nargs())
-                               cur.idx() = nargs() - 1;
-                       if (cur.pos() > cur.lastpos())
-                               cur.pos() = cur.lastpos();
-                       return DispatchResult(true, FINISHED);
+       case LFUN_INSERT_LABEL: {
+               row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+               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);
+                       new_label = lyx::support::trim(res.second);
                }
 
-               case LFUN_MATH_DISPLAY: {
-                       mutate(type_ == "simple" ? "equation" : "simple");
-                       cur.idx() = 0;
+               if (!new_label.empty())
+                       numbered(r, true);
+               label(r, new_label);
+               return;
+       }
+
+       case LFUN_MATH_EXTERN:
+               doExtern(cur, cmd);
+               //cur.dispatched(FINISHED);
+               return;
+
+       case LFUN_MATH_MUTATE: {
+               lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
+               row_type row = cur.row();
+               col_type col = cur.col();
+               mutate(cmd.argument);
+               cur.idx() = row * ncols() + col;
+               if (cur.idx() > cur.lastidx()) {
+                       cur.idx() = cur.lastidx();
                        cur.pos() = cur.lastpos();
-                       return DispatchResult(true, FINISHED);
                }
+               if (cur.pos() > cur.lastpos())
+                       cur.pos() = cur.lastpos();
+               //cur.dispatched(FINISHED);
+               return;
+       }
+
+       case LFUN_MATH_DISPLAY: {
+               mutate(type_ == "simple" ? "equation" : "simple");
+               cur.idx() = 0;
+               cur.pos() = cur.lastpos();
+               //cur.dispatched(FINISHED);
+               return;
+       }
 
-               default:
-                       return MathGridInset::priv_dispatch(cur, cmd);
+       default:
+               MathGridInset::priv_dispatch(cur, cmd);
+               return;
        }
 }
 
@@ -994,7 +995,6 @@ void MathHullInset::insetUnlock(BufferView & bv)
        if (bv.cursor().inMathed()) {
                if (bv.cursor().inMacroMode())
                        bv.cursor().macroModeClose();
-               bv.cursor().releaseMathCursor();
        }
        if (bv.buffer())
                generatePreview(*bv.buffer());
@@ -1070,7 +1070,7 @@ bool MathHullInset::searchForward(BufferView * bv, string const & str,
 #warning pretty ugly
 #endif
        static MathHullInset * lastformula = 0;
-       static CursorBase current = CursorBase(ibegin(nucleus()));
+       static CursorBase current = DocumentIterator(ibegin(nucleus()));
        static MathArray ar;
        static string laststr;
 
@@ -1086,7 +1086,7 @@ bool MathHullInset::searchForward(BufferView * bv, string const & str,
        }
        //lyxerr << "searching '" << str << "' in " << this << ar << endl;
 
-       for (CursorBase it = current; it != iend(nucleus()); increment(it)) {
+       for (DocumentIterator it = current; it != iend(nucleus()); increment(it)) {
                CursorSlice & top = it.back();
                MathArray const & a = top.asMathInset()->cell(top.idx_);
                if (a.matchpart(ar, top.pos_)) {
@@ -1183,108 +1183,3 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
        ms << ETag("equation");
        return ms.line() + res;
 }
-
-
-
-/////////////////////////////////////////////
-
-namespace {
-
-bool openNewInset(LCursor & cur, InsetBase * inset)
-{
-       cur.bv().getLyXText()->insertInset(inset);
-       inset->edit(cur, true);
-       return true;
-}
-
-
-void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
-       bool display)
-{
-       // use selection if available..
-       //string sel;
-       //if (action == LFUN_MATH_IMPORT_SELECTION)
-       //      sel = "";
-       //else
-
-       string sel =
-               cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
-
-       if (sel.empty()) {
-               InsetBase * f = new MathHullInset;
-               if (openNewInset(cur, f)) {
-                       cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
-                       // don't do that also for LFUN_MATH_MODE unless you want end up with
-                       // always changing to mathrm when opening an inlined inset
-                       // -- I really hate "LyXfunc overloading"...
-                       if (display)
-                               f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
-                       f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
-               }
-       } else {
-               // create a macro if we see "\\newcommand" somewhere, and an ordinary
-               // formula otherwise
-               InsetBase * f;
-               if (sel.find("\\newcommand") == string::npos &&
-                               sel.find("\\def") == string::npos)
-                       f = new MathHullInset(sel);
-               else
-                       f = new InsetFormulaMacro(sel);
-               cur.bv().getLyXText()->cutSelection(true, false);
-               openNewInset(cur, f);
-       }
-       cur.message(N_("Math editor mode"));
-}
-
-} // namespace anon
-
-
-void mathDispatch(LCursor & cur, FuncRequest const & cmd)
-{
-       if (!cur.bv().available())
-               return;
-
-       switch (cmd.action) {
-
-               case LFUN_MATH_DISPLAY:
-                       mathDispatchCreation(cur, cmd, true);
-                       break;
-
-               case LFUN_MATH_MODE:
-                       mathDispatchCreation(cur, cmd, false);
-                       break;
-
-               case LFUN_MATH_IMPORT_SELECTION:
-                       mathDispatchCreation(cur, cmd, false);
-                       break;
-
-/*
-               case LFUN_MATH_MACRO:
-                       if (cmd.argument.empty())
-                               cmd.errorMessage(N_("Missing argument"));
-                       else {
-                               string s = cmd.argument;
-                               string const s1 = token(s, ' ', 1);
-                               int const nargs = s1.empty() ? 0 : atoi(s1);
-                               string const s2 = token(s, ' ', 2);
-                               string const type = s2.empty() ? "newcommand" : s2;
-                               openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
-                       }
-                       break;
-
-               case LFUN_INSERT_MATH:
-               case LFUN_INSERT_MATRIX:
-               case LFUN_MATH_DELIM: {
-                       MathHullInset * f = new MathHullInset;
-                       if (openNewInset(cur, f)) {
-                               cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
-                               cur.inset()->dispatch(cur, cmd);
-                       }
-                       break;
-               }
-*/
-
-               default:
-                       break;
-       }
-}