]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
* fix crashing special menu items on Mac after preferences have been changed.
[lyx.git] / src / LyXFunc.cpp
index 9af54af532a72252b5cb25080ceb1f48bd760b48..ca9e5fef6bcf759eb1de00d29dee38545c5d71aa 100644 (file)
@@ -533,6 +533,23 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
+       // we want to check if at least one of these is enabled
+       case LFUN_COMMAND_ALTERNATIVES: {
+               // argument contains ';'-terminated commands
+               string arg = to_utf8(cmd.argument());
+               while (!arg.empty()) {
+                       string first;
+                       arg = split(arg, first, ';');
+                       FuncRequest func(lyxaction.lookupFunc(first));
+                       func.origin = cmd.origin;
+                       flag = getStatus(func);
+                       // if this one is enabled, the whole thing is
+                       if (flag.enabled())
+                               break;
+               }
+               break;
+       }
+
        case LFUN_CALL: {
                FuncRequest func;
                string name = to_utf8(cmd.argument());
@@ -731,6 +748,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                       << lyxaction.getActionName(action)
                       << " [" << action << "] is disabled at this location");
                setErrorMessage(flag.message());
+               if (lyx_view_)
+                       lyx_view_->restartCursor();
        } else {
                switch (action) {
 
@@ -1344,6 +1363,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
+               case LFUN_COMMAND_ALTERNATIVES: {
+                       // argument contains ';'-terminated commands
+                       string arg = argument;
+                       while (!arg.empty()) {
+                               string first;
+                               arg = split(arg, first, ';');
+                               FuncRequest func(lyxaction.lookupFunc(first));
+                               func.origin = cmd.origin;
+                               FuncStatus stat = getStatus(func);
+                               if (stat.enabled()) {
+                                       dispatch(func);
+                                       break;
+                               }
+                       }
+                       break;
+               }
+
                case LFUN_CALL: {
                        FuncRequest func;
                        if (theTopLevelCmdDef().lock(argument, func)) {
@@ -1463,7 +1499,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_LAYOUT_MODULE_ADD: {
                        LASSERT(lyx_view_, /**/);
                        Buffer * buffer = lyx_view_->buffer();
-                       DocumentClass const * const oldClass = buffer->params().documentClassPtr();
+                       BufferParams const & params = buffer->params();
+                       if (!params.moduleCanBeAdded(argument)) {
+                               LYXERR0("Module `" << argument << 
+                                               "' cannot be added due to failed requirements or "
+                                               "conflicts with installed modules.");
+                               break;
+                       }
+                       DocumentClass const * const oldClass = params.documentClassPtr();
                        view()->cursor().recordUndoFullDocument();
                        buffer->params().addLayoutModule(argument);
                        buffer->params().makeDocumentClass();
@@ -1561,20 +1604,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (lyx_view_ == 0)
                                break;
 
+                       // Start an undo group. This may be needed for
+                       // some stuff like inset-apply on labels.
+                       if (lyx_view_->view())
+                               view()->cursor().beginUndoGroup();
+                               
                        // Let the current LyXView dispatch its own actions.
                        if (lyx_view_->dispatch(cmd)) {
-                               if (lyx_view_->view())
+                               if (lyx_view_->view()) {
                                        updateFlags = lyx_view_->view()->cursor().result().update();
+                                       view()->cursor().endUndoGroup();
+                               }
                                break;
                        }
 
                        LASSERT(lyx_view_->view(), /**/);
 
-                       // Start an undo group. Normally, all the code
-                       // above only invoked recordUndoFullDocument,
-                       // which does not really require a group.
-                       view()->cursor().beginUndoGroup();
-
                        // Let the current BufferView dispatch its own actions.
                        if (view()->dispatch(cmd)) {
                                // The BufferView took care of its own updates if needed.
@@ -1589,10 +1634,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                                cursorPosBeforeDispatchY_);
                        view()->cursor().dispatch(cmd);
 
-                       // we assume here that the buffer view has not
-                       // changed since the beginUndoGroup.
-                       view()->cursor().endUndoGroup();
-
                        // notify insets we just left
                        if (view()->cursor() != old) {
                                old.fixIfBroken();
@@ -1601,6 +1642,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        view()->cursor().fixIfBroken();
                        }
 
+                       // we assume here that the buffer view has not
+                       // changed since the beginUndoGroup.
+                       view()->cursor().endUndoGroup();
+
                        // update completion. We do it here and not in
                        // processKeySym to avoid another redraw just for a
                        // changed inline completion