]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
Move OS specific code to proper place. Also make sure that no other
[lyx.git] / src / LyXFunc.cpp
index dc04fc4c1bf17b0a92af49277c651336ff64c12b..a99c290b7f98744196849d317ac15f7dcb01d944 100644 (file)
@@ -55,6 +55,7 @@
 #include "Row.h"
 #include "Server.h"
 #include "Session.h"
+#include "SpellChecker.h"
 
 #include "insets/InsetBox.h"
 #include "insets/InsetBranch.h"
@@ -265,7 +266,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 +399,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 +487,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 +583,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 +679,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 +880,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 +1071,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();
@@ -1078,6 +1122,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        bool loaded = false;
                        string const abstmp = package().temp_dir().absFilename();
                        string const realtmp = package().temp_dir().realPath();
+                       // We have to use os::path_prefix_is() here, instead of
+                       // simply prefixIs(), because the file name comes from
+                       // an external application and may need case adjustment.
                        if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
                            || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
                                // Needed by inverse dvi search. If it is a file
@@ -1527,6 +1574,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);
@@ -1541,6 +1591,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        actOnUpdatedPrefs(lyxrc_orig, lyxrc);
 
+                       setSpellChecker();
+
                        theApp()->resetGui();
 
                        /// We force the redraw in any case because there might be
@@ -1683,7 +1735,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);
@@ -1919,6 +1972,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_FONT_ENCODING:
        case LyXRC::RC_FORMAT:
        case LyXRC::RC_GROUP_LAYOUTS:
+       case LyXRC::RC_HUNSPELLDIR_PATH:
        case LyXRC::RC_INDEX_ALTERNATIVES:
        case LyXRC::RC_INDEX_COMMAND:
        case LyXRC::RC_JBIBTEX_COMMAND:
@@ -1986,6 +2040,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_SHOW_BANNER:
        case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
        case LyXRC::RC_SPELL_COMMAND:
+       case LyXRC::RC_SPELLCHECKER:
        case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
        case LyXRC::RC_SPLITINDEX_COMMAND:
        case LyXRC::RC_TEMPDIRPATH:
@@ -2012,6 +2067,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_SORT_LAYOUTS:
        case LyXRC::RC_FULL_SCREEN_LIMIT:
        case LyXRC::RC_FULL_SCREEN_SCROLLBAR:
+       case LyXRC::RC_FULL_SCREEN_MENUBAR:
        case LyXRC::RC_FULL_SCREEN_TABBAR:
        case LyXRC::RC_FULL_SCREEN_TOOLBARS:
        case LyXRC::RC_FULL_SCREEN_WIDTH: