]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
the spellcheck cleanup
[lyx.git] / src / lyxfunc.C
index 10df86c028bb15b4a529e64c44e1fe1cfe30a532..a4bac22fb7dadafc68621160c4b1f061c35ed74e 100644 (file)
@@ -29,6 +29,7 @@
 #include "BufferView.h"
 #include "cursor.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "encoding.h"
 #include "exporter.h"
 #include "format.h"
@@ -446,11 +447,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                                disable = true;
                        }
                } else {
-                       static InsetTabular inset(*owner->buffer(), 1, 1);
-                       FuncStatus ret;
-
+                       static InsetTabular inset(*buf, 1, 1);
                        disable = true;
-                       ret = inset.getStatus(ev.argument);
+                       FuncStatus ret = inset.getStatus(ev.argument);
                        if (ret.onoff(true) || ret.onoff(false))
                                flag.setOnOff(false);
                }
@@ -473,9 +472,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                disable = buf->isUnnamed() || buf->isClean();
                break;
        case LFUN_BOOKMARK_GOTO:
-               disable =  !view()->
+               disable = !view()->
                        isSavedPosition(strToUnsignedInt(ev.argument));
                break;
+
        case LFUN_MERGE_CHANGES:
        case LFUN_ACCEPT_CHANGE:
        case LFUN_REJECT_CHANGE:
@@ -483,6 +483,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_REJECT_ALL_CHANGES:
                disable = !buf->params().tracking_changes;
                break;
+
        case LFUN_INSET_TOGGLE: {
                LyXText * lt = view()->getLyXText();
                disable = !(isEditableInset(lt->getInset())
@@ -709,19 +710,18 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        code = InsetOld::SPACE_CODE;
                break;
        case LFUN_INSET_DIALOG_SHOW: {
-                       LyXText * lt = view()->getLyXText();
-                       InsetOld * inset = lt->getInset();
-                       disable = !inset;
-                       if (!disable) {
-                               code = inset->lyxCode();
-                               if (!(code == InsetOld::INCLUDE_CODE
-                                       || code == InsetOld::BIBTEX_CODE
-                                       || code == InsetOld::FLOAT_LIST_CODE
-                                       || code == InsetOld::TOC_CODE))
-                                       disable = true;
-                       }
+               InsetOld * inset = view()->getLyXText()->getInset();
+               disable = !inset;
+               if (!disable) {
+                       code = inset->lyxCode();
+                       if (!(code == InsetOld::INCLUDE_CODE
+                               || code == InsetOld::BIBTEX_CODE
+                               || code == InsetOld::FLOAT_LIST_CODE
+                               || code == InsetOld::TOC_CODE))
+                               disable = true;
                }
                break;
+       }
        default:
                break;
        }
@@ -814,7 +814,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        // solution, we consider only the first action of the sequence
        if (ev.action == LFUN_SEQUENCE) {
                // argument contains ';'-terminated commands
-#warning LyXAction arguements not handled here.
+#warning LyXAction arguments not handled here.
                flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
        }
 
@@ -881,20 +881,27 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
        if (view()->available())
                view()->hideCursor();
 
-#if 0
+#if 1
        {
                Cursor cursor;
                buildCursor(cursor, *view());
-               if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
+               DispatchResult result =
+                       cursor.dispatch(FuncRequest(func, view()));
+
+               if (result.dispatched()) {
+                       if (result.update()) {
+                               view()->update();
+                       }
                        lyxerr << "dispatched by Cursor::dispatch()\n";
                        goto exit_with_message;
                }
+               lyxerr << "### NOT DispatchResult(true, true) BY Cursor::dispatch() ###\n";
        }
 #endif
 
 
        if (view()->available() && view()->theLockingInset()) {
-               dispatch_result result;
+               DispatchResult result;
                if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
                                     !keyseq.deleted()))
                {
@@ -904,10 +911,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        int dummy_y;
                        inset->getCursorPos(view(), inset_x, dummy_y);
 #endif
-                       if (action == LFUN_UNKNOWN_ACTION
-                           && argument.empty()) {
+                       if (action == LFUN_UNKNOWN_ACTION && argument.empty())
                                argument = encoded_last_key;
-                       }
 
                        // the insets can't try to handle this,
                        // a table cell in the dummy position will
@@ -934,12 +939,15 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 
                        // Hand-over to inset's own dispatch:
                        result = inset->dispatch(FuncRequest(view(), action, argument));
-                       if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
+                       if (result.dispatched()) {
+                               if (result.update())
+                                       view()->update();
+
                                goto exit_with_message;
                        }
 
-                       // If UNDISPATCHED, just soldier on
-                       if (result == FINISHED) {
+                       // If DispatchResult(false), just soldier on
+                       if (result.val() == FINISHED) {
                                owner->clearMessage();
                                goto exit_with_message;
                                // We do not need special RTL handling here:
@@ -947,14 +955,14 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                                // one position after the inset.
                        }
 
-                       if (result == FINISHED_RIGHT) {
+                       if (result.val() == FINISHED_RIGHT) {
                                view()->text->cursorRight(view());
                                moveCursorUpdate();
                                owner->clearMessage();
                                goto exit_with_message;
                        }
 
-                       if (result == FINISHED_UP) {
+                       if (result.val() == FINISHED_UP) {
                                LyXText * text = view()->text;
                                ParagraphList::iterator pit = text->cursorPar();
                                Row const & row = *pit->getRow(text->cursor.pos());
@@ -964,7 +972,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                                                text->cursor.x() + inset_x,
                                                text->cursor.y() -
                                                row.baseline() - 1);
-                                       text->cursor.x_fix(text->cursor.x());
+                                       view()->x_target(text->cursor.x());
 #else
                                        text->cursorUp(view());
 #endif
@@ -976,7 +984,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                                goto exit_with_message;
                        }
 
-                       if (result == FINISHED_DOWN) {
+                       if (result.val() == FINISHED_DOWN) {
                                LyXText * text = view()->text;
                                ParagraphList::iterator pit = text->cursorPar();
                                Row const & row = *pit->getRow(text->cursor.pos());
@@ -987,7 +995,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                                                text->cursor.y() -
                                                row.baseline() +
                                                row.height() + 1);
-                                       text->cursor.x_fix(text->cursor.x());
+                                       view()->x_target(text->cursor.x());
 #else
                                        text->cursorDown(view());
 #endif
@@ -1000,7 +1008,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        }
 
 #warning I am not sure this is still right, please have a look! (Jug 20020417)
-                       // result == UNDISPATCHED
+                       // result == DispatchResult()
                        //setMessage(N_("Text mode"));
                        switch (action) {
                        case LFUN_UNKNOWN_ACTION:
@@ -1079,7 +1087,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                }
                bool fw = (action == LFUN_WORDFINDFORWARD);
                if (!searched_string.empty())
-                       lyx::find::find(view(), searched_string, fw);
+                       lyx::find::find(view(), searched_string,
+                                       true, false, fw);
                break;
        }
 
@@ -1197,8 +1206,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                QuitLyX();
                break;
 
-       case LFUN_TOCVIEW:
-       {
+       case LFUN_TOCVIEW: {
                InsetCommandParams p("tableofcontents");
                string const data = InsetCommandMailer::params2string("toc", p);
                owner->getDialogs().show("toc", data, 0);
@@ -1245,8 +1253,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 //#warning Find another implementation here (or another lyxfunc)!
 #endif
 #endif
-       case LFUN_HELP_OPEN:
-       {
+
+       case LFUN_HELP_OPEN: {
                string const arg = argument;
                if (arg.empty()) {
                        setErrorMessage(N_("Missing argument"));
@@ -1266,18 +1274,15 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 
                // --- version control -------------------------------
        case LFUN_VC_REGISTER:
-       {
                if (!ensureBufferClean(view()))
                        break;
                if (!owner->buffer()->lyxvc().inUse()) {
                        owner->buffer()->lyxvc().registrer();
                        view()->reload();
                }
-       }
-       break;
+               break;
 
        case LFUN_VC_CHECKIN:
-       {
                if (!ensureBufferClean(view()))
                        break;
                if (owner->buffer()->lyxvc().inUse()
@@ -1285,11 +1290,9 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        owner->buffer()->lyxvc().checkIn();
                        view()->reload();
                }
-       }
-       break;
+               break;
 
        case LFUN_VC_CHECKOUT:
-       {
                if (!ensureBufferClean(view()))
                        break;
                if (owner->buffer()->lyxvc().inUse()
@@ -1297,22 +1300,17 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        owner->buffer()->lyxvc().checkOut();
                        view()->reload();
                }
-       }
-       break;
+               break;
 
        case LFUN_VC_REVERT:
-       {
                owner->buffer()->lyxvc().revert();
                view()->reload();
-       }
-       break;
+               break;
 
        case LFUN_VC_UNDO:
-       {
                owner->buffer()->lyxvc().undoLast();
                view()->reload();
-       }
-       break;
+               break;
 
        // --- buffers ----------------------------------------
 
@@ -1328,20 +1326,19 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                open(argument);
                break;
 
-       case LFUN_LAYOUT_TABULAR:
-           if (view()->theLockingInset()) {
-               if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
-                   InsetTabular * inset = static_cast<InsetTabular *>
-                       (view()->theLockingInset());
-                   inset->openLayoutDialog(view());
-               } else if (view()->theLockingInset()->
-                          getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
-                   InsetTabular * inset = static_cast<InsetTabular *>(
-                       view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
-                   inset->openLayoutDialog(view());
+       case LFUN_LAYOUT_TABULAR: {
+               UpdatableInset * tli = view()->theLockingInset();
+               if (tli) {
+                       if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
+                               static_cast<InsetTabular *>(tli)->openLayoutDialog(view());
+                       } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
+                               static_cast<InsetTabular *>(
+                                       tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
+                                               ->openLayoutDialog(view());
+                       }
                }
-           }
-           break;
+               break;
+       }
 
        case LFUN_DROP_LAYOUTS_CHOICE:
                owner->getToolbar().openLayoutList();
@@ -1362,18 +1359,15 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                break;
 
        case LFUN_NOTIFY:
-       {
                dispatch_buffer = keyseq.print();
                lyxserver->notifyClient(dispatch_buffer);
-       }
-       break;
+               break;
 
-       case LFUN_GOTOFILEROW:
-       {
+       case LFUN_GOTOFILEROW: {
                string file_name;
                int row;
-               istringstream istr(argument.c_str());
-               istr >> file_name >> row;
+               istringstream is(argument);
+               is >> file_name >> row;
                if (prefixIs(file_name, getTmpDir())) {
                        // Needed by inverse dvi search. If it is a file
                        // in tmpdir, call the apropriated function
@@ -1381,7 +1375,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                } else {
                        // Must replace extension of the file to be .lyx
                        // and get full path
-                       string const s(ChangeExtension(file_name, ".lyx"));
+                       string const s = ChangeExtension(file_name, ".lyx");
                        // Either change buffer or load the file
                        if (bufferlist.exists(s)) {
                                view()->buffer(bufferlist.getBuffer(s));
@@ -1395,15 +1389,13 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                view()->center();
                // see BufferView_pimpl::center()
                view()->updateScrollbar();
+               break;
        }
-       break;
-
-       case LFUN_GOTO_PARAGRAPH:
-       {
-               istringstream istr(argument.c_str());
 
+       case LFUN_GOTO_PARAGRAPH: {
+               istringstream is(argument);
                int id;
-               istr >> id;
+               is >> id;
                ParIterator par = owner->buffer()->getParFromID(id);
                if (par == owner->buffer()->par_iterator_end()) {
                        lyxerr[Debug::INFO] << "No matching paragraph found! ["
@@ -1416,12 +1408,16 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 
                if (view()->theLockingInset())
                        view()->unlockInset(view()->theLockingInset());
+
+               LyXText * lt = view()->getLyXText();
                if (par->inInset()) {
                        FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
-                       par->inInset()->dispatch(cmd);
+                       par.inset()->dispatch(cmd);
+                       lt = par->inInset()->getLyXText(view());
                }
+
                // Set the cursor
-               view()->getLyXText()->setCursor(par.pit(), 0);
+               lt->setCursor(par.pit(), 0);
                view()->switchKeyMap();
                owner->view_state_changed();
 
@@ -1438,15 +1434,14 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_NONUMBER:
        case LFUN_MATH_LIMITS:
-       {
                setErrorMessage(N_("This is only allowed in math mode!"));
-       }
-       break;
+               break;
 
        // passthrough hat and underscore outside mathed:
        case LFUN_SUBSCRIPT:
                dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
                break;
+
        case LFUN_SUPERSCRIPT:
                dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
                break;
@@ -1495,22 +1490,18 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        data = InsetCommandMailer::params2string(name, p);
                }
                owner->getDialogs().show(name, data, 0);
+               break;
        }
-       break;
 
-       case LFUN_DIALOG_SHOW_NEXT_INSET: {
-       }
-       break;
+       case LFUN_DIALOG_SHOW_NEXT_INSET:
+               break;
 
        case LFUN_INSET_DIALOG_SHOW: {
-               LyXText * lt = view()->getLyXText();
-               InsetOld * inset = lt->getInset();
-               if (inset) {
-                       FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
-                       inset->dispatch(cmd);
-               }
+               InsetOld * inset = view()->getLyXText()->getInset();
+               if (inset)
+                       inset->dispatch(FuncRequest(view(), LFUN_INSET_DIALOG_SHOW));
+               break;
        }
-       break;
 
        case LFUN_DIALOG_UPDATE: {
                string const & name = argument;
@@ -1523,8 +1514,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                } else if (name == "paragraph") {
                        dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
                }
+               break;
        }
-       break;
 
        case LFUN_DIALOG_HIDE:
                Dialogs::hide(argument, 0);
@@ -1534,8 +1525,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                owner->getDialogs().disconnect(argument);
                break;
 
-       case LFUN_CHILDOPEN:
-       {
+       case LFUN_CHILDOPEN: {
                string const filename =
                        MakeAbsPath(argument, owner->buffer()->filePath());
                setMessage(N_("Opening child document ") +
@@ -1545,8 +1535,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                        view()->buffer(bufferlist.getBuffer(filename));
                else
                        view()->loadLyXFile(filename);
+               break;
        }
-       break;
 
        case LFUN_TOGGLECURSORFOLLOW:
                lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
@@ -1568,44 +1558,51 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                owner->getIntl().ToggleKeyMap();
                break;
 
+       case LFUN_REPEAT: {
+               // repeat command
+               string countstr;
+               argument = split(argument, countstr, ' ');
+               istringstream is(countstr);
+               int count = 0;
+               is >> count;
+               lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
+               for (int i = 0; i < count; ++i)
+                       dispatch(lyxaction.lookupFunc(argument));
+               break;
+       }
+
        case LFUN_SEQUENCE:
-       {
                // argument contains ';'-terminated commands
                while (!argument.empty()) {
                        string first;
                        argument = split(argument, first, ';');
                        dispatch(lyxaction.lookupFunc(first));
                }
-       }
-       break;
+               break;
 
-       case LFUN_SAVEPREFERENCES:
-       {
+       case LFUN_SAVEPREFERENCES: {
                Path p(user_lyxdir());
                lyxrc.write("preferences");
+               break;
        }
-       break;
 
        case LFUN_SCREEN_FONT_UPDATE:
-       {
                // handle the screen font changes.
                lyxrc.set_font_norm_type();
                lyx_gui::update_fonts();
                // All visible buffers will need resize
                view()->resize();
                view()->update();
-       }
-       break;
+               break;
 
-       case LFUN_SET_COLOR:
-       {
+       case LFUN_SET_COLOR: {
                string lyx_name;
                string const x11_name = split(argument, lyx_name, ' ');
                if (lyx_name.empty() || x11_name.empty()) {
                        setErrorMessage(N_("Syntax: set-color <lyx_name>"
                                                " <x11_name>"));
                        break;
-                       }
+               }
 
                bool const graphicsbg_changed =
                        (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
@@ -1626,9 +1623,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
 #endif
 #if 0
-                       lyx::graphics::GCache & gc =
-                               lyx::graphics::GCache::get();
-                       gc.changeDisplay(true);
+                       lyx::graphics::GCache::get().changeDisplay(true);
 #endif
                }
 
@@ -1641,24 +1636,20 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
                break;
 
        case LFUN_FORKS_KILL:
-       {
-               if (!isStrInt(argument))
-                       break;
-
-               pid_t const pid = strToInt(argument);
-               ForkedcallsController & fcc = ForkedcallsController::get();
-               fcc.kill(pid);
+               if (isStrInt(argument)) {
+                       pid_t const pid = strToInt(argument);
+                       ForkedcallsController & fcc = ForkedcallsController::get();
+                       fcc.kill(pid);
+               }
                break;
-       }
 
        case LFUN_TOOLTIPS_TOGGLE:
                owner->getDialogs().toggleTooltips();
                break;
 
-       case LFUN_EXTERNAL_EDIT: {
+       case LFUN_EXTERNAL_EDIT:
                InsetExternal().dispatch(FuncRequest(view(), action, argument));
                break;
-       }
 
        default:
                // Then if it was none of the above