]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Upgrading of my xforms libs showed that lots of files thought they depended
[lyx.git] / src / lyxfunc.C
index adfe50ce56f93e9fc323694f72c12155baa3826c..5b8ea4cf835e07f4516797b6479e4cb7cd6671f1 100644 (file)
@@ -38,7 +38,6 @@
 #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 +47,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 +106,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 +360,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 +385,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 +421,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 +454,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 +479,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 +506,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 +526,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 +544,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: 
@@ -571,7 +576,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;
@@ -663,9 +667,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;
        }
 
@@ -680,6 +682,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;
        }
@@ -754,18 +762,13 @@ void LyXFunc::miniDispatch(string const & s)
 }
 
 
-void const LyXFunc::verboseDispatch(string const & s, bool show_sc) 
+void LyXFunc::verboseDispatch(string const & s, bool show_sc) 
 {
-       // Split command string into command and argument
-       string cmd;
-       string line = frontStrip(s);
-       string const arg = strip(frontStrip(split(line, cmd, ' ')));
-
-       int action = lyxaction.LookupFunc(cmd);
+       int action = lyxaction.LookupFunc(frontStrip(s));
  
        if (action == LFUN_UNKNOWN_ACTION) {
                string const msg = string(_("Unknown function ("))
-                       + cmd + ")";
+                       + s + ")";
                owner->message(msg);
        } else {
                verboseDispatch(action, show_sc);
@@ -773,7 +776,7 @@ void const LyXFunc::verboseDispatch(string const & s, bool show_sc)
 }
 
 
-void const LyXFunc::verboseDispatch(int ac, bool show_sc) 
+void LyXFunc::verboseDispatch(int ac, bool show_sc) 
 {
        string argument;
        kb_action action;
@@ -786,8 +789,8 @@ void const LyXFunc::verboseDispatch(int ac, bool show_sc)
 
 
 
-void const LyXFunc::verboseDispatch(kb_action action,
-                                   string const & argument, bool show_sc)
+void LyXFunc::verboseDispatch(kb_action action,
+                             string const & argument, bool show_sc)
 {
        string res = dispatch(action, argument);
 
@@ -879,7 +882,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.
@@ -890,10 +893,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());
@@ -963,7 +968,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        }
 
        switch (action) {
-               
+
        case LFUN_ESCAPE:
        {
                if (!owner->view()->available()) break;
@@ -1021,10 +1026,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);
        }
@@ -1140,7 +1145,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");
@@ -1155,10 +1160,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;
@@ -1402,22 +1403,27 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
        case LFUN_GOTO_PARAGRAPH:
        {
-                istringstream istr(argument.c_str());
+               istringstream istr(argument.c_str());
 
                int id;
                istr >> id;
                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()
                               << " found." << endl;
                }
 
+               if (owner->view()->theLockingInset())
+                       owner->view()->unlockInset(owner->view()->theLockingInset());
+               if (par->inInset()) {
+                       par->inInset()->edit(owner->view());
+               }
                // Set the cursor
-               owner->view()->text->setCursor(owner->view(), par, 0);
+               owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
                owner->view()->setState();
                owner->showState();
 
@@ -1490,7 +1496,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 +1504,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;
                    
@@ -1513,7 +1519,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        {
                string const filename =
                        MakeAbsPath(argument, 
-                                   OnlyPath(owner->buffer()->fileName()));
+                                   owner->buffer()->filePath());
                setMessage(N_("Opening child document ") +
                           MakeDisplayPath(filename) + "...");
                owner->view()->savePosition(0);
@@ -1593,6 +1599,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 +1611,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 +1635,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) << "]!"
@@ -1652,7 +1685,7 @@ void LyXFunc::menuNew(bool fromTemplate)
        string initpath = lyxrc.document_path;
 
        if (owner->view()->available()) {
-               string const trypath = owner->buffer()->filepath;
+               string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath))
                        initpath = trypath;
@@ -1778,7 +1811,7 @@ void LyXFunc::open(string const & fname)
        string initpath = lyxrc.document_path;
   
        if (owner->view()->available()) {
-               string const trypath = owner->buffer()->filepath;
+               string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath))
                        initpath = trypath;
@@ -1855,7 +1888,7 @@ void LyXFunc::doImport(string const & argument)
                string initpath = lyxrc.document_path;
                
                if (owner->view()->available()) {
-                       string const trypath = owner->buffer()->filepath;
+                       string const trypath = owner->buffer()->filePath();
                        // If directory is writeable, use this as default.
                        if (IsDirWriteable(trypath))
                                initpath = trypath;