]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
gtk sendto dialog
[lyx.git] / src / lyxfunc.C
index f4fac34f66115f3050800e2d55a387f41d6c6c73..b5c3ad161bf90a3a99a692beb678cb354d1738b3 100644 (file)
@@ -272,9 +272,19 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 {
        //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
        FuncStatus flag;
-       Buffer * buf = owner->buffer();
        LCursor & cur = view()->cursor();
 
+       /* In LyX/Mac, when a dialog is open, the menus of the
+          application can still be accessed without giving focus to
+          the main window. In this case, we want to disable the menu
+          entries that are buffer-related.
+       */
+       Buffer * buf;
+       if (cmd.origin == FuncRequest::UI && !owner->hasFocus())
+               buf = 0;
+       else
+               buf = owner->buffer();
+
        if (cmd.action == LFUN_NOACTION) {
                setStatusMessage(N_("Nothing to do"));
                flag.enabled(false);
@@ -447,7 +457,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_SEQUENCE: {
                // argument contains ';'-terminated commands
                string const firstcmd = token(cmd.argument, ';', 0);
-               flag = getStatus(lyxaction.lookupFunc(firstcmd));
+               FuncRequest func(lyxaction.lookupFunc(firstcmd));
+               func.origin = cmd.origin;
+               flag = getStatus(func);
        }
 
        case LFUN_MENUNEW:
@@ -503,6 +515,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_SAVE_AS_DEFAULT:
        case LFUN_BUFFERPARAMS_APPLY:
        case LFUN_LYXRC_APPLY:
+       case LFUN_NEXTBUFFER:
+       case LFUN_PREVIOUSBUFFER:
                // these are handled in our dispatch()
                break;
 
@@ -586,7 +600,7 @@ void loadTextclass(string const & name)
 } //namespace anon
 
 
-void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
+void LyXFunc::dispatch(FuncRequest const & cmd)
 {
        string const argument = cmd.argument;
        kb_action const action = cmd.action;
@@ -958,6 +972,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        view()->setBuffer(bufferlist.getBuffer(argument));
                        break;
 
+               case LFUN_NEXTBUFFER:
+                       view()->setBuffer(bufferlist.next(view()->buffer()));
+                       break;
+
+               case LFUN_PREVIOUSBUFFER:
+                       view()->setBuffer(bufferlist.previous(view()->buffer()));
+                       break;
+
                case LFUN_FILE_NEW:
                        NewFile(view(), argument);
                        break;
@@ -1209,7 +1231,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        while (!arg.empty()) {
                                string first;
                                arg = split(arg, first, ';');
-                               dispatch(lyxaction.lookupFunc(first));
+                               FuncRequest func(lyxaction.lookupFunc(first));
+                               func.origin = cmd.origin;
+                               dispatch(func);
                        }
                        break;
                }
@@ -1334,7 +1358,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                                       << (unknown_tokens == 1 ? "" : "s")
                                       << endl;
                        }
-                       
+
                        if (defaults.writeFile(defaults.fileName()))
                                setMessage(_("Document defaults saved in ")
                                           + MakeDisplayPath(fname));
@@ -1433,7 +1457,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                }
 
                if (view()->available()) {
-                       if (view()->fitCursor() || update)
+                       // Redraw screen unless explicitly told otherwise.
+                       // This also initializes the position cache for all insets
+                       // in (at least partially) visible top-level paragraphs.
+                       if (update)
+                               view()->update();
+
+                       // fitCursor() needs valid inset position. The previous call to
+                       // update() makes sure we have such even for freshly created
+                       // insets.
+                       if (view()->fitCursor())
                                view()->update();
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (getStatus(cmd).enabled()
@@ -1444,18 +1477,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
 
                if (view()->cursor().inTexted()) {
                        view()->owner()->updateLayoutChoice();
-                       sendDispatchMessage(getMessage(), cmd, verbose);
+                       sendDispatchMessage(getMessage(), cmd);
                }
        }
 }
 
 
-void LyXFunc::sendDispatchMessage(string const & msg,
-                                 FuncRequest const & cmd, bool verbose)
+void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
 {
        owner->updateMenubar();
        owner->updateToolbars();
 
+       const bool verbose = (cmd.origin == FuncRequest::UI
+                             || cmd.origin == FuncRequest::COMMANDBUFFER);
+
        if (cmd.action == LFUN_SELFINSERT || !verbose) {
                lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
                if (!msg.empty())