]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
more cursor dispatch
[lyx.git] / src / lyxfunc.C
index d4ef9aa8d0e39ec9cdb104cd11d6c44a32a7074f..eee8bb805e99b32a84bb66e41fb365caf3489c8c 100644 (file)
@@ -63,8 +63,6 @@
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
 
-#include "mathed/math_cursor.h"
-
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
@@ -162,16 +160,9 @@ void LyXFunc::handleKeyFunc(kb_action action)
 }
 
 
-void LyXFunc::processKeySym(LyXKeySymPtr keysym,
-                           key_modifier::state state)
+void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 {
-       string argument;
-
-       if (lyxerr.debugging(Debug::KEY)) {
-               lyxerr << "KeySym is "
-                      << keysym->getSymbolName()
-                      << endl;
-       }
+       lyxerr[Debug::KEY] << "KeySym is " << keysym->getSymbolName() << endl;
 
        // Do nothing if we have nothing (JMarc)
        if (!keysym->isOK()) {
@@ -257,9 +248,11 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                if (encoded_last_key != 0) {
                        string arg;
                        arg += encoded_last_key;
+                       lyxerr << "SelfInsert arg[`"
+                                  << arg << "']" << endl;
                        dispatch(FuncRequest(LFUN_SELFINSERT, arg));
-                       lyxerr[Debug::KEY] << "SelfInsert arg[`"
-                                  << argument << "']" << endl;
+                       lyxerr[Debug::KEY]
+                               << "SelfInsert arg[`" << arg << "']" << endl;
                }
        } else {
                dispatch(func);
@@ -343,7 +336,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (tab && tab->hasSelection())
                        disable = false;
                else
-                       disable = !inMathed() && !view()->cursor().selection();
+                       disable = !view()->cursor().inMathed() && !view()->cursor().selection();
                break;
 
        case LFUN_RUNCHKTEX:
@@ -379,7 +372,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
        case LFUN_TABULAR_FEATURE:
 #if 0
-               if (inMathed()) {
+               if (view()->cursor().inMathed()) {
                        // FIXME: check temporarily disabled
                        // valign code
                        char align = mathcursor::valign();
@@ -511,7 +504,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        }
 
        case LFUN_MATH_MUTATE:
-               if (inMathed())
+               if (view()->cursor().inMathed())
                        //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument);
                        flag.setOnOff(false);
                else
@@ -525,7 +518,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_MATH_NONUMBER:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
-               disable = !inMathed();
+               disable = !view()->cursor().inMathed();
                break;
 
        case LFUN_DIALOG_SHOW: {
@@ -684,13 +677,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        case LFUN_SPACE_INSERT:
                // slight hack: we know this is allowed in math mode
-               if (!inMathed())
+               if (!view()->cursor().inMathed())
                        code = InsetOld::SPACE_CODE;
                break;
        case LFUN_INSET_DIALOG_SHOW: {
-               InsetOld * inset = view()->getLyXText()->getInset();
+               InsetBase * inset = view()->cursor().nextInset();
                disable = !inset;
-               if (!disable) {
+               if (inset) {
                        code = inset->lyxCode();
                        if (!(code == InsetOld::INCLUDE_CODE
                                || code == InsetOld::BIBTEX_CODE
@@ -736,7 +729,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
 
 #ifdef LOCK
        // the font related toggles
-       if (!inMathed()) {
+       if (!view()->cursor().inMathed()) {
                LyXFont const & font = view()->getLyXText()->real_current_font;
                switch (ev.action) {
                case LFUN_EMPH:
@@ -827,29 +820,21 @@ bool ensureBufferClean(BufferView * bv)
 } //namespace anon
 
 
-void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
+void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
 {
-       string argument = func.argument;
-       kb_action action = func.action;
+       string argument = cmd.argument;
+       kb_action action = cmd.action;
 
-       //lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << func << endl;
-       lyxerr << "LyXFunc::dispatch: cmd: " << func << endl;
+       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
+       //lyxerr << "*** LyXFunc::dispatch: cmd: " << cmd << endl;
 
        // we have not done anything wrong yet.
        errorstat = false;
        dispatch_buffer.erase();
-
-#ifdef NEW_DISPATCHER
-       // We try do call the most specific dispatcher first:
-       //  1. the lockinginset's dispatch
-       //  2. the bufferview's dispatch
-       //  3. the lyxview's dispatch
-#endif
-
        selection_possible = false;
 
        // We cannot use this function here
-       if (getStatus(func).disabled()) {
+       if (getStatus(cmd).disabled()) {
                lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
                       << lyxaction.getActionName(action)
                       << " [" << action << "] is disabled at this location"
@@ -1167,11 +1152,9 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                                                                << " found." << endl;
                        }
 
-                       par.lockPath(view());
-                       LyXText * lt = par.text(*view()->buffer());
-
                        // Set the cursor
-                       lt->setCursor(par.pit(), 0);
+                       view()->setCursor(par, 0);
+
                        view()->switchKeyMap();
                        owner->view_state_changed();
 
@@ -1190,8 +1173,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                case LFUN_DIALOG_SHOW: {
-                       string const name = func.getArg(0);
-                       string data = trim(func.argument.substr(name.size()));
+                       string const name = cmd.getArg(0);
+                       string data = trim(cmd.argument.substr(name.size()));
 
                        if (name == "character") {
                                data = freefont2string();
@@ -1200,8 +1183,6 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        }
                        else if (name == "document")
                                owner->getDialogs().showDocument();
-                       else if (name == "findreplace")
-                               owner->getDialogs().showSearch();
                        else if (name == "forks")
                                owner->getDialogs().showForks();
                        else if (name == "preamble")
@@ -1238,8 +1219,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                }
 
                case LFUN_DIALOG_SHOW_NEW_INSET: {
-                       string const name = func.getArg(0);
-                       string data = trim(func.argument.substr(name.size()));
+                       string const name = cmd.getArg(0);
+                       string data = trim(cmd.argument.substr(name.size()));
                        if (name == "bibitem" ||
                            name == "bibtex" ||
                            name == "include" ||
@@ -1291,7 +1272,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                case LFUN_INSET_DIALOG_SHOW: {
-                       InsetOld * inset = view()->getLyXText()->getInset();
+                       InsetBase * inset = view()->cursor().nextInset();
                        if (inset)
                                inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
                        break;
@@ -1302,7 +1283,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        // Can only update a dialog connected to an existing inset
                        InsetBase * inset = owner->getDialogs().getOpenInset(name);
                        if (inset) {
-                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, func.argument);
+                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument);
                                inset->dispatch(view()->cursor(), fr);
                        } else if (name == "paragraph") {
                                dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@@ -1445,35 +1426,39 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        break;
 
                default:
-                       view()->cursor().dispatch(FuncRequest(func));
+                       DispatchResult res = view()->cursor().dispatch(cmd);
+                       if (!res.dispatched());
+                               view()->dispatch(cmd);
                        break;
                }
        }
 
-       view()->owner()->updateLayoutChoice();
+       if (!view()->cursor().inMathed())
+               view()->owner()->updateLayoutChoice();
 
        if (view()->available()) {
                view()->fitCursor();
                view()->update();
                view()->cursor().updatePos();
                // if we executed a mutating lfun, mark the buffer as dirty
-               if (!getStatus(func).disabled()
-                   && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer)
-                   && !lyxaction.funcHasFlag(func.action, LyXAction::ReadOnly))
+               if (!getStatus(cmd).disabled()
+                   && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
+                   && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
                        view()->buffer()->markDirty();
        }
 
-       sendDispatchMessage(getMessage(), func, verbose);
+       if (!view()->cursor().inMathed())
+               sendDispatchMessage(getMessage(), cmd, verbose);
 }
 
 
 void LyXFunc::sendDispatchMessage(string const & msg,
-                                 FuncRequest const & func, bool verbose)
+                                 FuncRequest const & cmd, bool verbose)
 {
        owner->updateMenubar();
        owner->updateToolbar();
 
-       if (func.action == LFUN_SELFINSERT || !verbose) {
+       if (cmd.action == LFUN_SELFINSERT || !verbose) {
                lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
                if (!msg.empty())
                        owner->message(msg);
@@ -1484,23 +1469,23 @@ void LyXFunc::sendDispatchMessage(string const & msg,
        if (!dispatch_msg.empty())
                dispatch_msg += ' ';
 
-       string comname = lyxaction.getActionName(func.action);
+       string comname = lyxaction.getActionName(cmd.action);
 
        bool argsadded = false;
 
-       if (!func.argument.empty()) {
-               if (func.action != LFUN_UNKNOWN_ACTION) {
-                       comname += ' ' + func.argument;
+       if (!cmd.argument.empty()) {
+               if (cmd.action != LFUN_UNKNOWN_ACTION) {
+                       comname += ' ' + cmd.argument;
                        argsadded = true;
                }
        }
 
-       string const shortcuts = toplevel_keymap->findbinding(func);
+       string const shortcuts = toplevel_keymap->findbinding(cmd);
 
        if (!shortcuts.empty()) {
                comname += ": " + shortcuts;
-       } else if (!argsadded && !func.argument.empty()) {
-               comname += ' ' + func.argument;
+       } else if (!argsadded && !cmd.argument.empty()) {
+               comname += ' ' + cmd.argument;
        }
 
        if (!comname.empty()) {
@@ -1745,7 +1730,7 @@ void LyXFunc::closeBuffer()
 // Each "owner" should have it's own message method. lyxview and
 // the minibuffer would use the minibuffer, but lyxserver would
 // send an ERROR signal to its client.  Alejandro 970603
-// This func is bit problematic when it comes to NLS, to make the
+// This function is bit problematic when it comes to NLS, to make the
 // lyx servers client be language indepenent we must not translate
 // strings sent to this func.
 void LyXFunc::setErrorMessage(string const & m) const