]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
"ding-dong, the witch is dead!", says John
[lyx.git] / src / lyxfunc.C
index 5ca26ab25748ad788cd2e22aa87d8b57d28eb4ae..dac09f18e7c9e9fa6320be0675da40954d7d5cbe 100644 (file)
@@ -48,7 +48,6 @@
 #include "lyxfind.h"
 #include "undo_funcs.h"
 #include "ParagraphParameters.h"
-#include "figureForm.h"
 
 #include "insets/inseturl.h"
 #include "insets/insetlatexaccent.h"
 #include "frontends/Menubar.h"
 #include "frontends/Alert.h"
 
+#include "graphics/GraphicsCache.h"
+
 #include "support/lyxalgo.h"
 #include "support/LAssert.h"
 #include "support/filetools.h"
 #include "support/FileInfo.h"
-#include "support/syscall.h"
+#include "support/forkedcontr.h"
 #include "support/lstrings.h"
 #include "support/path.h"
 #include "support/lyxfunctional.h"
@@ -106,6 +107,9 @@ using std::pair;
 using std::make_pair; 
 using std::endl;
 using std::find_if;
+using std::vector;
+using std::transform;
+using std::back_inserter;
 
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
@@ -357,6 +361,9 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                setStatusMessage(N_("Unknown action"));
                return flag.unknown(true);
        }
+
+       // the default error message if we disable the command
+       setStatusMessage(N_("Command disabled"));
        
        // Check whether we need a buffer
        if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
@@ -473,10 +480,14 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
 
-       case LFUN_INSET_TOGGLE:
-               disable = (TEXT(false)->getInset() == 0);
+       case LFUN_INSET_TOGGLE: {
+               LyXText * lt = owner->view()->getLyXText();
+               disable = !(isEditableInset(lt->getInset())
+                           || (lt->inset_owner
+                               && lt->inset_owner->owner()
+                               && lt->inset_owner->owner()->isOpen()));
                break;
-
+       }
        case LFUN_MATH_VALIGN: 
                if (mathcursor) {
                        char align = mathcursor->valign();
@@ -566,7 +577,6 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        case LFUN_INSET_ERT:
                code = Inset::ERT_CODE;         
                break;
-       case LFUN_FIGURE:
        case LFUN_INSET_GRAPHICS:
                code = Inset::GRAPHICS_CODE;
                break;
@@ -673,6 +683,12 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        case LFUN_APPENDIX:
                flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
                break;
+       case LFUN_SWITCHBUFFER:
+               // toggle on the current buffer, but do not toggle off
+               // the other ones (is that a good idea?) 
+               if (argument == buf->fileName())
+                       flag.setOnOff(true);
+               break;
        default:
                break;
        }
@@ -867,7 +883,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                                     (!keyseq.deleted())))
                {
                        if ((action == LFUN_UNKNOWN_ACTION)
-                           && argument.empty()){
+                           && argument.empty()) {
                                argument = keyseq.getiso();
                        }
                        // Undo/Redo is a bit tricky for insets.
@@ -878,10 +894,12 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                                owner->view()->menuRedo();
                                goto exit_with_message;
                        } else if (((result=owner->view()->theLockingInset()->
+                                    // Hand-over to inset's own dispatch:
                                     localDispatch(owner->view(), action, argument)) ==
                                    UpdatableInset::DISPATCHED) ||
                                   (result == UpdatableInset::DISPATCHED_NOUPDATE))
                                goto exit_with_message;
+                                       // If UNDISPATCHED, just soldier on
                        else if (result == UpdatableInset::FINISHED) {
                                        if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
                                                TEXT()->cursorRight(owner->view());
@@ -951,7 +969,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        }
 
        switch (action) {
-               
+
        case LFUN_ESCAPE:
        {
                if (!owner->view()->available()) break;
@@ -1009,10 +1027,10 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        // --- Misc -------------------------------------------
        case LFUN_EXEC_COMMAND:
        {
-               std::vector<string> allCmds;
-               std::transform(lyxaction.func_begin(), lyxaction.func_end(),
-                              std::back_inserter(allCmds), lyx::firster());
-               static std::vector<string> hist;
+               vector<string> allCmds;
+               transform(lyxaction.func_begin(), lyxaction.func_end(),
+                         back_inserter(allCmds), lyx::firster());
+               static vector<string> hist;
                owner->getMiniBuffer()->getString(MiniBuffer::spaces,
                                                  allCmds, hist);
        }
@@ -1128,7 +1146,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 #endif
                        p.setCmdName("tableofcontents");
 #if 0
-               else if (action == LFUN_LOAVIEW )
+               else if (action == LFUN_LOAVIEW)
                        p.setCmdName("listof{algorithm}{List of Algorithms}");
                else if (action == LFUN_LOFVIEW)
                        p.setCmdName("listoffigures");
@@ -1143,10 +1161,6 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                owner->getDialogs()->showTabularCreate();
                break;
                
-       case LFUN_FIGURE:
-               Figure();
-               break;
-
        case LFUN_AUTOSAVE:
                AutoSave(owner->view());
                break;
@@ -1397,7 +1411,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                Paragraph * par = owner->buffer()->getParFromID(id);
                if (par == 0) {
                        lyxerr[Debug::INFO] << "No matching paragraph found! ["
-                                           << id << "]" << std::endl;
+                                           << id << "]" << endl;
                        break;
                } else {
                        lyxerr << "Paragraph " << par->id()
@@ -1483,7 +1497,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        
        case LFUN_CITATION_CREATE:
        {
-               InsetCommandParams p( "cite" );
+               InsetCommandParams p("cite");
                
                if (!argument.empty()) {
                        // This should be set at source, ie when typing
@@ -1491,14 +1505,14 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        // Question: would pybibliographer also need to be
                        // changed. Suspect so. Leave as-is therefore.
                        if (contains(argument, "|")) {
-                               p.setContents( token(argument, '|', 0) );
-                               p.setOptions(  token(argument, '|', 1) );
+                               p.setContents(token(argument, '|', 0));
+                               p.setOptions( token(argument, '|', 1));
                        } else {
-                               p.setContents( argument );
+                               p.setContents(argument);
                        }
                        dispatch(LFUN_CITATION_INSERT, p.getAsString());
                } else
-                       owner->getDialogs()->createCitation( p.getAsString() );
+                       owner->getDialogs()->createCitation(p.getAsString());
        }
        break;
                    
@@ -1586,6 +1600,10 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        break;
                        }
 
+               bool const graphicsbg_changed =
+                       (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
+                        x11_name != lcolor.getX11Name(LColor::graphicsbg));
+
                if (!lcolor.setColor(lyx_name, x11_name)) {
                        static string const err1 (N_("Set-color \""));
                        static string const err2 (
@@ -1594,7 +1612,14 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        setErrorMessage(_(err1) + lyx_name + _(err2));
                        break;
                }
+
                lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
+
+               if (graphicsbg_changed) {
+                       grfx::GCache & gc = grfx::GCache::get();
+                       gc.changeDisplay(true);
+               }
+               
                owner->view()->redraw();
                break;
        }
@@ -1611,8 +1636,24 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                owner->messagePop();
                break;
 
+       case LFUN_FORKS_SHOW:
+               owner->getDialogs()->showForks();
+               break;
+
+       case LFUN_FORKS_KILL:
+       {
+               if (!isStrInt(argument))
+                       break;
+
+               pid_t const pid = strToInt(argument);
+               ForkedcallsController & fcc = ForkedcallsController::get();
+               fcc.kill(pid);
+               break;
+       }
+
        default:
                // Then if it was none of the above
+               // Trying the BufferView::pimpl dispatch:
                if (!owner->view()->Dispatch(action, argument))
                        lyxerr << "A truly unknown func ["
                               << lyxaction.getActionName(action) << "]!"