]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
Fix part of bug #6127: Roundtrip Lyx->Latex->Lyx fails.
[lyx.git] / src / LyXFunc.cpp
index 0fa60b1276e826e30b05a895cd24ce28462db692..8dac8f676b68eb5ac178e4a82fcf63d1ce115871 100644 (file)
@@ -265,7 +265,7 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
                dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
 
        // if the current buffer is not that one, switch to it.
-       if (lyx_view_->buffer()->fileName() != tmp.filename) {
+       if (!lyx_view_->buffer() || lyx_view_->buffer()->fileName() != tmp.filename) {
                if (!switchToBuffer)
                        return;
                dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
@@ -398,7 +398,22 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
        FuncStatus flag;
 
-       Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
+       /* 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 or view-related.
+
+          If this code is moved somewhere else (like in
+          GuiView::getStatus), then several functions will not be
+          handled correctly.
+       */
+       frontend::LyXView * lv = 0;
+       Buffer * buf = 0;
+       if (lyx_view_ 
+           && (cmd.origin != FuncRequest::MENU || lyx_view_->hasFocus())) {
+               lv = lyx_view_;
+               buf = lyx_view_->buffer();
+       }
 
        if (cmd.action == LFUN_NOACTION) {
                flag.message(from_utf8(N_("Nothing to do")));
@@ -471,6 +486,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_VC_CHECK_OUT:
                enable = buf->lyxvc().checkOutEnabled();
                break;
+       case LFUN_VC_LOCKING_TOGGLE:
+               enable = !buf->isReadonly() && buf->lyxvc().lockingToggleEnabled();
+               flag.setOnOff(enable && !buf->lyxvc().locker().empty());
+               break;
        case LFUN_VC_REVERT:
                enable = buf->lyxvc().inUse();
                break;
@@ -563,9 +582,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                        flag = getStatus(func);
                        theTopLevelCmdDef().release(name);
                } else {
-                       // catch recursion or unknown command definiton
-                       // all operations until the recursion or unknown command 
-                       // definiton occures are performed, so set the state to enabled
+                       // catch recursion or unknown command
+                       // definition. all operations until the
+                       // recursion or unknown command definition
+                       // occurs are performed, so set the state to
+                       // enabled
                        enable = true;
                }
                break;
@@ -657,11 +678,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                        break;
 
                // Does the view know something?
-               if (!lyx_view_) {
+               if (!lv) {
                        enable = false;
                        break;
                }
-               if (lyx_view_->getStatus(cmd, flag))
+               if (lv->getStatus(cmd, flag))
                        break;
 
                // If we do not have a BufferView, then other functions are disabled
@@ -858,6 +879,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        updateFlags = Update::None;
                        break;
 
+               case LFUN_BUFFER_CLOSE_ALL:
+                       lyx_view_->closeBufferAll();
+                       buffer = 0;
+                       updateFlags = Update::None;
+                       break;
+
                case LFUN_BUFFER_RELOAD: {
                        LASSERT(lyx_view_ && buffer, /**/);
                        docstring const file = makeDisplayPath(buffer->absFileName(), 20);
@@ -1043,6 +1070,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        break;
 
+               case LFUN_VC_LOCKING_TOGGLE:
+                       LASSERT(lyx_view_ && buffer, /**/);
+                       if (!ensureBufferClean(view()) || buffer->isReadonly())
+                               break;
+                       if (buffer->lyxvc().inUse()) {
+                               string res = buffer->lyxvc().lockingToggle();
+                               if (res.empty())
+                                       frontend::Alert::error(_("Revision control error."),
+                                               _("Error when setting the locking property."));
+                               else {
+                                       setMessage(from_utf8(res));
+                                       reloadBuffer();
+                               }
+                       }
+                       break;
+
                case LFUN_VC_REVERT:
                        LASSERT(lyx_view_ && buffer, /**/);
                        buffer->lyxvc().revert();
@@ -1530,6 +1573,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_LYXRC_APPLY: {
+                       // reset active key sequences, since the bindings
+                       // are updated (bug 6064)
+                       keyseq.reset();
                        LyXRC const lyxrc_orig = lyxrc;
 
                        istringstream ss(argument);
@@ -1686,7 +1732,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // processKeySym to avoid another redraw just for a
                        // changed inline completion
                        if (cmd.origin == FuncRequest::KEYBOARD) {
-                               if (cmd.action == LFUN_SELF_INSERT)
+                               if (cmd.action == LFUN_SELF_INSERT
+                                   || (cmd.action == LFUN_ERT_INSERT && view()->cursor().inMathed()))
                                        lyx_view_->updateCompletion(view()->cursor(), true, true);
                                else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
                                        lyx_view_->updateCompletion(view()->cursor(), false, true);