]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
John's msg3.diff
[lyx.git] / src / lyxfunc.C
index 08da67032660b54effaac2d1e5d6e01b30a91ddd..a7e0443845b04c4b02753a4a17427ffdc210e1d7 100644 (file)
 #include "Lsstream.h"
 #include "trans_mgr.h"
 #include "layout.h"
-#include "WorkArea.h"
 #include "bufferview_funcs.h"
 #include "minibuffer.h"
 #include "vspace.h"
 #include "LyXView.h"
-#include "lyx_gui_misc.h"
 #include "FloatList.h"
 #include "converter.h"
 #include "exporter.h"
@@ -48,7 +46,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,11 +105,13 @@ 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;
 extern bool selection_possible;
-extern void MenuSendto();
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
@@ -299,7 +300,7 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        // why not return already here if action == -1 and
        // num_bytes == 0? (Lgb)
 
-       if (keyseq.length() > 1 && !keyseq.deleted()) {
+       if (keyseq.length() > 1) {
                owner->message(keyseq.print());
        }
 
@@ -357,6 +358,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)) {
@@ -379,6 +383,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                }
        }
 
+       UpdatableInset * tli = owner->view()->theLockingInset();
+       
        // I would really like to avoid having this switch and rather try to
        // encode this in the function itself.
         bool disable = false;
@@ -413,27 +419,30 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
        case LFUN_LAYOUT_TABULAR:
-               disable = true;
-               if (owner->view()->theLockingInset()) {
-                       disable = (owner->view()->theLockingInset()->lyxCode() != Inset::TABULAR_CODE) &&
-                               !owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
-               }
+               disable = !tli
+                       || (tli->lyxCode() != Inset::TABULAR_CODE
+                           && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
                break;
 
+       case LFUN_LAYOUT:
+       case LFUN_LAYOUT_PARAGRAPH: {
+               Inset * inset = TEXT(false)->cursor.par()->inInset();
+               disable = inset && inset->forceDefaultParagraphs(inset);
+               break;
+       }
+
        case LFUN_TABULAR_FEATURE:
                disable = true;
-               if (owner->view()->theLockingInset()) {
+               if (tli) {
                        FuncStatus ret;
                        //ret.disabled(true);
-                       if (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) {
-                               ret = static_cast<InsetTabular *>
-                                       (owner->view()->theLockingInset())->
-                                       getStatus(argument);
-                       } else if (owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
+                       if (tli->lyxCode() == Inset::TABULAR_CODE) {
+                               ret = static_cast<InsetTabular *>(tli)
+                                       ->getStatus(argument);
+                       } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
                                ret = static_cast<InsetTabular *>
-                                       (owner->view()->theLockingInset()->
-                                        getFirstLockingInsetOfType(Inset::TABULAR_CODE))->
-                                       getStatus(argument);
+                                       (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
+                                       ->getStatus(argument);
                        }
                        flag |= ret;
                        disable = false;
@@ -443,7 +452,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
 
                        disable = true;
                        ret = inset.getStatus(argument);
-                       if (ret.onoff(true) || ret.onoff(false)) flag.setOnOff(false);
+                       if (ret.onoff(true) || ret.onoff(false))
+                               flag.setOnOff(false);
                }
                break;
 
@@ -467,17 +477,15 @@ 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: {
-    // I think this test can be simplified (Andre')
-               // mathcursor is != 0  iff we are in math mode
-               //Inset * tli = owner->view()->theLockingInset();
-               //if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-               //          || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
-               //
+       }
+       case LFUN_MATH_VALIGN: 
                if (mathcursor) {
                        char align = mathcursor->valign();
                        if (align == '\0') {
@@ -496,11 +504,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
-       case LFUN_MATH_HALIGN: {
-               //Inset * tli = owner->view()->theLockingInset();
-               //if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-               //          || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+
+       case LFUN_MATH_HALIGN: 
                if (mathcursor) {
                        char align = mathcursor->halign();
                        if (align == '\0') {
@@ -519,9 +524,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
-       case LFUN_MATH_MUTATE: {
-               Inset * tli = owner->view()->theLockingInset();
+
+       case LFUN_MATH_MUTATE: 
                if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
                        MathInsetTypes type = mathcursor->formula()->getType();
                        if (argument == "inline") {
@@ -538,7 +542,6 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
 
        // we just need to be in math mode to enable that
        case LFUN_MATH_SIZE: 
@@ -565,13 +568,9 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        // the functions which insert insets
        Inset::Code code = Inset::NO_CODE;
        switch (action) {
-       case LFUN_INSET_TEXT:
-               code = Inset::TEXT_CODE;
-               break;
        case LFUN_INSET_ERT:
                code = Inset::ERT_CODE;         
                break;
-       case LFUN_FIGURE:
        case LFUN_INSET_GRAPHICS:
                code = Inset::GRAPHICS_CODE;
                break;
@@ -663,9 +662,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        default:
                break;
        }
-       if (code != Inset::NO_CODE 
-           && owner->view()->theLockingInset()
-           && !owner->view()->theLockingInset()->insetAllowed(code)) {
+       if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
                disable = true;
        }
 
@@ -674,12 +671,22 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        
        // A few general toggles
        switch (action) {
+       case LFUN_TOOLTIPS_TOGGLE:
+               flag.setOnOff(owner->getDialogs()->tooltipsEnabled());
+               break;
+
        case LFUN_READ_ONLY_TOGGLE:
                flag.setOnOff(buf->isReadonly());
                break;
        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;
        }
@@ -874,7 +881,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.
@@ -885,10 +892,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());
@@ -958,7 +967,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        }
 
        switch (action) {
-               
+
        case LFUN_ESCAPE:
        {
                if (!owner->view()->available()) break;
@@ -1009,17 +1018,17 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        owner->view()->update(TEXT(),
                                              BufferView::SELECT|BufferView::FITCUR);
                }
-               owner->message(keyseq.print());
+               owner->message(keyseq.printOptions());
        }
        break;
 
        // --- 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);
        }
@@ -1089,15 +1098,15 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        case LFUN_UPDATE:
                Exporter::Export(owner->buffer(), argument, true);
                break;
-
+               
        case LFUN_PREVIEW:
                Exporter::Preview(owner->buffer(), argument);
                break;
-               
+
         case LFUN_BUILDPROG:
                Exporter::Export(owner->buffer(), "program", true);
-                break;
-                
+               break;
+
        case LFUN_RUNCHKTEX:
                MenuRunChktex(owner->buffer());
                break;
@@ -1108,7 +1117,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
        case LFUN_EXPORT:
                if (argument == "custom")
-                       MenuSendto();
+                       owner->getDialogs()->showSendto();
                else
                        Exporter::Export(owner->buffer(), argument, false);
                break;
@@ -1135,7 +1144,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");
@@ -1150,10 +1159,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;
@@ -1404,7 +1409,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()
@@ -1490,7 +1495,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
@@ -1498,14 +1503,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;
                    
@@ -1593,6 +1598,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 (
@@ -1601,7 +1610,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;
        }
@@ -1618,8 +1634,28 @@ 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;
+       }
+
+       case LFUN_TOOLTIPS_TOGGLE:
+               owner->getDialogs()->toggleTooltips();
+               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) << "]!"