]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Fix crash when running lyx -dbg insets -e ...
[lyx.git] / src / lyxfunc.C
index b4a1af2178517da99b48776c04bb8ba77ceeaa47..537ce1aeec2b70f240aac4f934b949721136f68a 100644 (file)
@@ -60,7 +60,6 @@
 #include "mathed/formulamacro.h"
 #include "mathed/math_cursor.h"
 #include "mathed/math_inset.h"
-#include "spellchecker.h" 
 #include "minibuffer.h"
 #include "vspace.h"
 #include "LyXView.h"
@@ -345,7 +344,7 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        
         bool tmp_sc = show_sc;
        show_sc = false;
-       Dispatch(action, argument);
+       dispatch(action, argument);
        show_sc = tmp_sc;
        
        //return 0;
@@ -429,15 +428,6 @@ func_status::value_type LyXFunc::getStatus(int ac,
                disable = !Exporter::IsExportable(buf, "program");
                break;
 
-       case LFUN_INSERTFOOTNOTE:
-               // Disable insertion of floats in a tabular.
-               disable = false;
-               if (owner->view()->theLockingInset()) {
-                       disable = (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) ||
-                               owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
-               }
-               break;
-
        case LFUN_LAYOUT_TABULAR:
                disable = true;
                if (owner->view()->theLockingInset()) {
@@ -491,6 +481,12 @@ func_status::value_type LyXFunc::getStatus(int ac,
        case LFUN_BOOKMARK_GOTO:
                disable =  !owner->view()->
                        isSavedPosition(strToUnsignedInt(argument));
+               break;
+
+
+       case LFUN_INSET_TOGGLE:
+               disable = (TEXT(false)->getInset() == 0);
+               break;
 
        case LFUN_MATH_VALIGN: {
     // I think this test can be simplified (Andre')
@@ -593,43 +589,127 @@ func_status::value_type LyXFunc::getStatus(int ac,
 
        default:
                break;
-        }
-        if (disable)
-                flag |= func_status::Disabled;
-
-       if (buf) {
-               func_status::value_type box = func_status::ToggleOff;
-               LyXFont const & font =
-                       TEXT(false)->real_current_font;
-               switch (action) {
-               case LFUN_EMPH:
-                       if (font.emph() == LyXFont::ON)
-                               box = func_status::ToggleOn;
-                       break;
-               case LFUN_NOUN:
-                       if (font.noun() == LyXFont::ON)
-                               box = func_status::ToggleOn;
-                       break;
-               case LFUN_BOLD:
-                       if (font.series() == LyXFont::BOLD_SERIES)
-                               box = func_status::ToggleOn;
-                       break;
+       }
+
+       // 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_INSET_GRAPHICS:
+               code = Inset::GRAPHICS_CODE;
+               break;
+       case LFUN_INSET_FOOTNOTE:
+               code = Inset::FOOT_CODE;
+               break;
+       case LFUN_INSET_TABULAR:
+               code = Inset::TABULAR_CODE;
+               break;
+       case LFUN_INSET_EXTERNAL:
+               code = Inset::EXTERNAL_CODE;
+               break;
+       case LFUN_INSET_MARGINAL:
+               code = Inset::MARGIN_CODE;
+               break;
+       case LFUN_INSET_MINIPAGE:
+               code = Inset::MINIPAGE_CODE;
+               break;
+       case LFUN_INSET_FLOAT:
+       case LFUN_INSET_WIDE_FLOAT:
+               code = Inset::FLOAT_CODE;
+               break;
+#if 0
+       case LFUN_INSET_LIST:
+               code = Inset::LIST_CODE;
+               break;
+#endif
+       case LFUN_INSET_THEOREM:
+               code = Inset::THEOREM_CODE;
+               break;
+       case LFUN_INSET_CAPTION:
+               code = Inset::CAPTION_CODE;
+               break;
+       case LFUN_INSERT_NOTE:
+               code = Inset::IGNORE_CODE;
+               break;
+       case LFUN_INSERT_LABEL:
+               code = Inset::LABEL_CODE;
+               break;
+       case LFUN_REF_INSERT:
+               code = Inset::REF_CODE;
+               break;
+       case LFUN_CITATION_INSERT:
+               code = Inset::CITE_CODE;
+               break;
+       case LFUN_INSERT_BIBTEX:
+               code = Inset::BIBTEX_CODE;
+               break;
+       case LFUN_INDEX_INSERT:
+       case LFUN_INDEX_INSERT_LAST:
+               code = Inset::INDEX_CODE;
+               break;
+#if 0
+       case LFUN_CHILD_INSERT:
+               code = Inset::CHILD_CODE;
+               break;
+#endif
+       case LFUN_TOC_INSERT:
+               code = Inset::TOC_CODE;
+               break;
+       case LFUN_PARENTINSERT:
+               code = Inset::PARENT_CODE;
+               break;
+       case LFUN_INSERT_URL:
+               code = Inset::URL_CODE;
+               break;
+       default:
+               break;
+       }
+       if (code != Inset::NO_CODE 
+           && owner->view()->theLockingInset()
+           && !owner->view()->theLockingInset()->insetAllowed(code)) {
+               disable = true;
+       }
+
+       if (disable)
+               flag |= func_status::Disabled;
+       
+       // the font related functions
+       func_status::value_type box = func_status::ToggleOff;
+       LyXFont const & font =
+               TEXT(false)->real_current_font;
+       switch (action) {
+       case LFUN_EMPH:
+               if (font.emph() == LyXFont::ON)
+                       box = func_status::ToggleOn;
+               break;
+       case LFUN_NOUN:
+               if (font.noun() == LyXFont::ON)
+                       box = func_status::ToggleOn;
+               break;
+       case LFUN_BOLD:
+               if (font.series() == LyXFont::BOLD_SERIES)
+                       box = func_status::ToggleOn;
+               break;
 #ifndef NO_LATEX
-               case LFUN_TEX:
-                       if (font.latex() == LyXFont::ON)
-                               box = func_status::ToggleOn;
-                       break;
+       case LFUN_TEX:
+               if (font.latex() == LyXFont::ON)
+                       box = func_status::ToggleOn;
+               break;
 #endif
-               case LFUN_READ_ONLY_TOGGLE:
-                       if (buf->isReadonly())
-                               box = func_status::ToggleOn;
-                       break;
-               default:
-                       box = func_status::OK;
-                       break;
-               }
-               flag |= box;
+       case LFUN_READ_ONLY_TOGGLE:
+               if (buf->isReadonly())
+                       box = func_status::ToggleOn;
+               break;
+       default:
+               box = func_status::OK;
+               break;
        }
+       flag |= box;
 
        return flag;
 }
@@ -639,23 +719,23 @@ func_status::value_type LyXFunc::getStatus(int ac,
 void LyXFunc::miniDispatch(string const & s) 
 {
        if (!s.empty()) {
-               Dispatch(s);
+               dispatch(s);
        }
 }
 
 
-string const LyXFunc::Dispatch(string const & s) 
+string const LyXFunc::dispatch(string const & s) 
 {
        // Split command string into command and argument
        string cmd;
        string line = frontStrip(s);
        string const arg = strip(frontStrip(split(line, cmd, ' ')));
 
-       return Dispatch(lyxaction.LookupFunc(cmd), arg);
+       return dispatch(lyxaction.LookupFunc(cmd), arg);
 }
 
 
-string const LyXFunc::Dispatch(int ac,
+string const LyXFunc::dispatch(int ac,
                               string const & do_not_use_this_arg)
 {
        lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
@@ -898,7 +978,7 @@ string const LyXFunc::Dispatch(int ac,
                meta_fake_bit = 0;
                if (owner->view()->available())
                        // cancel any selection
-                       Dispatch(LFUN_MARK_OFF);
+                       dispatch(LFUN_MARK_OFF);
                setMessage(N_("Cancel"));
                break;
 
@@ -926,15 +1006,15 @@ string const LyXFunc::Dispatch(int ac,
                
                // --- Menus -----------------------------------------------
        case LFUN_MENUNEW:
-               MenuNew(false);
+               menuNew(false);
                break;
                
        case LFUN_MENUNEWTMPLT:
-               MenuNew(true);
+               menuNew(true);
                break;
                
        case LFUN_CLOSEBUFFER:
-               CloseBuffer();
+               closeBuffer();
                break;
                
        case LFUN_MENUWRITE:
@@ -1091,13 +1171,13 @@ string const LyXFunc::Dispatch(int ac,
 #warning Find another implementation here (or another lyxfunc)!
 #endif
 #endif
-       case LFUN_HELP_COPYRIGHT:
-               owner->getDialogs()->showCopyright();
+       case LFUN_HELP_ABOUTLYX:
+               owner->getDialogs()->showAboutlyx();
                break;
 
+       case LFUN_HELP_COPYRIGHT:
        case LFUN_HELP_CREDITS:
-               owner->getDialogs()->showCredits();
-               break;
+               
 
         case LFUN_HELP_OPEN:
        {
@@ -1123,20 +1203,7 @@ string const LyXFunc::Dispatch(int ac,
                break;
         }
 
-       case LFUN_HELP_VERSION: {
-               owner->prohibitInput();
-               string msg(_("LyX Version "));
-               msg += LYX_VERSION;
-               msg += " of ";
-               msg += LYX_RELEASE;
-               fl_show_message(msg.c_str(),
-                               (_("Library directory: ")
-                                + MakeDisplayPath(system_lyxdir)).c_str(),
-                               (_("User directory: ") 
-                                + MakeDisplayPath(user_lyxdir)).c_str());
-               owner->allowInput();
-               break;
-       }
+       case LFUN_HELP_VERSION:
        
                // --- version control -------------------------------
        case LFUN_VC_REGISTER:
@@ -1196,7 +1263,7 @@ string const LyXFunc::Dispatch(int ac,
        break;
                        
        case LFUN_FILE_OPEN:
-               Open(argument);
+               open(argument);
                break;
 
        case LFUN_LATEX_LOG:
@@ -1216,7 +1283,7 @@ string const LyXFunc::Dispatch(int ac,
                --sel; // sel 1..., but layout 0...
 
                // Pretend we got the name instead.
-               Dispatch(int(LFUN_LAYOUT), 
+               dispatch(int(LFUN_LAYOUT), 
                         textclasslist.NameOfLayout(owner->view()
                                                    ->buffer()->params.textclass,
                                                    sel));
@@ -1268,8 +1335,8 @@ string const LyXFunc::Dispatch(int ac,
                
        case LFUN_SPELLCHECK:
                if (lyxrc.isp_command != "none")
-                       ShowSpellChecker(owner->view());
-               break; // RVDK_PATCH_5
+                       owner->getDialogs()->showSpellchecker();
+               break;
                
        // --- lyxserver commands ----------------------------
 
@@ -1326,7 +1393,7 @@ string const LyXFunc::Dispatch(int ac,
 
                int id;
                istr >> id;
-               Paragraph * par = TEXT()->getParFromID(id);
+               Paragraph * par = owner->buffer()->getParFromID(id);
                if (par == 0) {
                        lyxerr[Debug::INFO] << "No matching paragraph found! ["
                                            << id << "]" << std::endl;
@@ -1436,7 +1503,7 @@ string const LyXFunc::Dispatch(int ac,
                        } else {
                                p.setContents( argument );
                        }
-                       Dispatch(LFUN_CITATION_INSERT, p.getAsString());
+                       dispatch(LFUN_CITATION_INSERT, p.getAsString());
                } else
                        owner->getDialogs()->createCitation( p.getAsString() );
        }
@@ -1483,7 +1550,7 @@ string const LyXFunc::Dispatch(int ac,
                while (argument.find(';') != string::npos) {
                        string first;
                        argument = split(argument, first, ';');
-                       Dispatch(first);
+                       dispatch(first);
                }
        }
        break;
@@ -1555,7 +1622,8 @@ string const LyXFunc::Dispatch(int ac,
                // Then if it was none of the above
                if (!owner->view()->Dispatch(action, argument))
                        lyxerr << "A truly unknown func ["
-                              << action << "]!" << endl;
+                              << lyxaction.getActionName(action) << "]!"
+                              << endl;
                break;
        } // end of switch
 
@@ -1632,7 +1700,7 @@ void LyXFunc::setupLocalKeymap()
 }
 
 
-void LyXFunc::MenuNew(bool fromTemplate)
+void LyXFunc::menuNew(bool fromTemplate)
 {
        string initpath = lyxrc.document_path;
 
@@ -1758,7 +1826,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
 }
 
 
-void LyXFunc::Open(string const & fname)
+void LyXFunc::open(string const & fname)
 {
        string initpath = lyxrc.document_path;
   
@@ -1919,7 +1987,7 @@ void LyXFunc::reloadBuffer()
 }
 
 
-void LyXFunc::CloseBuffer()
+void LyXFunc::closeBuffer()
 {
        if (bufferlist.close(owner->buffer()) && !quitting) {
                if (bufferlist.empty()) {