]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Minor code shuffle.
[lyx.git] / src / lyxfunc.C
index f123166106065c16c8e0f58aa2e9d85565844b1b..9a6fbe629a1847622d0f6d76eb0509bd2af27e98 100644 (file)
@@ -32,7 +32,6 @@
 #include "BufferView.h"
 #include "ColorHandler.h"
 #include "lyxserver.h"
-#include "figure_form.h"
 #include "intl.h"
 #include "lyx_main.h"
 #include "lyx_cb.h"
@@ -61,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"
@@ -91,6 +89,7 @@
 #include "FontLoader.h"
 #include "TextCache.h"
 #include "lyxfind.h"
+#include "undo_funcs.h"
 
 using std::pair;
 using std::make_pair; 
@@ -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;
@@ -491,10 +490,15 @@ func_status::value_type LyXFunc::getStatus(int ac,
        case LFUN_BOOKMARK_GOTO:
                disable =  !owner->view()->
                        isSavedPosition(strToUnsignedInt(argument));
+
        case LFUN_MATH_VALIGN: {
-               Inset * tli = owner->view()->theLockingInset();
-               if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-                           || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+    // 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)) {
+               //
+               if (mathcursor) {
                        char align = mathcursor->valign();
                        if (align == '\0') {
                                disable = true;
@@ -517,9 +521,10 @@ func_status::value_type LyXFunc::getStatus(int ac,
                break;
        }
        case LFUN_MATH_HALIGN: {
-               Inset * tli = owner->view()->theLockingInset();
-               if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-                           || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+               //Inset * tli = owner->view()->theLockingInset();
+               //if (tli && (tli->lyxCode() == Inset::MATH_CODE 
+               //          || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+               if (mathcursor) {
                        char align = mathcursor->halign();
                        if (align == '\0') {
                                disable = true;
@@ -567,6 +572,24 @@ func_status::value_type LyXFunc::getStatus(int ac,
                        disable = true;
                break;
        }
+
+       // we just need to be in math mode to enable that
+       case LFUN_MATH_SIZE: 
+       case LFUN_MATH_LIMITS: 
+       case LFUN_MATH_NONUMBER: 
+       case LFUN_MATH_NUMBER:
+               disable = !mathcursor;
+               break;
+
+       // we need to be math mode and a math array for that
+       // Hack: halign produces non-zero result iff we are in a math array
+       case LFUN_MATH_ROW_INSERT: 
+       case LFUN_MATH_ROW_DELETE: 
+       case LFUN_MATH_COLUMN_INSERT: 
+       case LFUN_MATH_COLUMN_DELETE: 
+               disable = !mathcursor || !mathcursor->halign();
+               break;
+
        default:
                break;
         }
@@ -615,23 +638,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
@@ -656,7 +679,14 @@ string const LyXFunc::Dispatch(int ac,
                if (!do_not_use_this_arg.empty())
                        argument = do_not_use_this_arg; // except here
        }
-    
+
+#ifdef NEW_DISPATCHER
+       // We try do call the most specific dispatcher first:
+       //  1. the lockinginset's dispatch
+       //  2. the bufferview's dispatch
+       //  3. the lyxview's dispatch
+#endif
+       
        selection_possible = false;
        
        if (owner->view()->available())
@@ -676,14 +706,21 @@ string const LyXFunc::Dispatch(int ac,
                                argument = keyseq.getiso();
                        }
                        // Undo/Redo is a bit tricky for insets.
-                       if (action == LFUN_UNDO) {
+                       if (action == LFUN_UNDO) {
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
                                int slx;
                                int sly;
                                UpdatableInset * inset = 
-                                       owner->view()->theLockingInset();
+                                       owner->view()->theLockingInset()->getLockingInset();
+                               int inset_id = inset->id();
                                inset->getCursorPos(owner->view(), slx, sly);
                                owner->view()->unlockInset(inset);
+#else
+                               owner->view()->unlockInset(owner->view()->theLockingInset());
+#endif
                                owner->view()->menuUndo();
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
+#if 0
                                if (TEXT()->cursor.par()->
                                    isInset(TEXT()->cursor.pos())) {
                                        inset = static_cast<UpdatableInset*>(
@@ -693,8 +730,12 @@ string const LyXFunc::Dispatch(int ac,
                                } else {
                                        inset = 0;
                                }
+#else
+                               inset = static_cast<UpdatableInset *>(owner->view()->buffer()->getInsetFromID(inset_id));
+#endif
                                if (inset)
                                        inset->edit(owner->view(),slx,sly,0);
+#endif
                                return string();
                        } else if (action == LFUN_REDO) {
                                int slx;
@@ -813,7 +854,7 @@ string const LyXFunc::Dispatch(int ac,
                        // Move cursor so that successive C-s 's will not stand in place. 
                        if (action == LFUN_WORDFINDFORWARD ) 
                                TEXT()->cursorRightOneWord(owner->view());
-                       TEXT()->finishUndo();
+                       finishUndo();
                        moveCursorUpdate(true, false);
 
                        // ??? Needed ???
@@ -856,7 +897,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;
 
@@ -884,15 +925,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:
@@ -1049,13 +1090,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:
        {
@@ -1064,37 +1105,24 @@ string const LyXFunc::Dispatch(int ac,
                        setErrorMessage(N_("Missing argument"));
                        break;
                }
-               ProhibitInput(owner->view());
+               owner->prohibitInput();
                string const fname = i18nLibFileSearch("doc", arg, "lyx");
                if (fname.empty()) {
                        lyxerr << "LyX: unable to find documentation file `"
                               << arg << "'. Bad installation?" << endl;
-                       AllowInput(owner->view());
+                       owner->allowInput();
                        break;
                }
                ostringstream str;
                str << _("Opening help file") << ' '
                    << MakeDisplayPath(fname) << "...";
                owner->message(str.str().c_str());
-               owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
-               AllowInput(owner->view());
+               owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
+               owner->allowInput();
                break;
         }
 
-       case LFUN_HELP_VERSION: {
-               ProhibitInput(owner->view());
-               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());
-               AllowInput(owner->view());
-               break;
-       }
+       case LFUN_HELP_VERSION:
        
                // --- version control -------------------------------
        case LFUN_VC_REGISTER:
@@ -1154,7 +1182,7 @@ string const LyXFunc::Dispatch(int ac,
        break;
                        
        case LFUN_FILE_OPEN:
-               Open(argument);
+               open(argument);
                break;
 
        case LFUN_LATEX_LOG:
@@ -1174,7 +1202,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));
@@ -1226,8 +1254,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 ----------------------------
 
@@ -1250,19 +1278,26 @@ string const LyXFunc::Dispatch(int ac,
 
        case LFUN_GOTOFILEROW:
        {
+#if 0
                char file_name[100];
                int row;
                ::sscanf(argument.c_str(), " %s %d", file_name, &row);
-
+#else
+               string file_name;
+               int row;
+               istringstream istr(argument.c_str());
+               istr >> file_name >> row;
+#endif
                // Must replace extension of the file to be .lyx and get full path
-               string s = ChangeExtension(string(file_name), ".lyx");
+               string const s(ChangeExtension(file_name, ".lyx"));
 
                // Either change buffer or load the file
-               if (bufferlist.exists(s))
+               if (bufferlist.exists(s)) {
                        owner->view()->buffer(bufferlist.getBuffer(s));
-               else
+               } else {
                        owner->view()->buffer(bufferlist.loadLyXFile(s));
-
+               }
+               
                // Set the cursor  
                owner->view()->setCursorFromRow(row);
 
@@ -1277,9 +1312,12 @@ string const LyXFunc::Dispatch(int ac,
 
                int id;
                istr >> id;
-               Paragraph * par = TEXT()->getParFromID(id);
-               if (par == 0)
+               Paragraph * par = owner->buffer()->getParFromID(id);
+               if (par == 0) {
+                       lyxerr[Debug::INFO] << "No matching paragraph found! ["
+                                           << id << "]" << std::endl;
                        break;
+               }
 
                // Set the cursor
                TEXT()->setCursor(owner->view(), par, 0);
@@ -1384,7 +1422,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() );
        }
@@ -1431,7 +1469,7 @@ string const LyXFunc::Dispatch(int ac,
                while (argument.find(';') != string::npos) {
                        string first;
                        argument = split(argument, first, ';');
-                       Dispatch(first);
+                       dispatch(first);
                }
        }
        break;
@@ -1503,7 +1541,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
 
@@ -1580,7 +1619,7 @@ void LyXFunc::setupLocalKeymap()
 }
 
 
-void LyXFunc::MenuNew(bool fromTemplate)
+void LyXFunc::menuNew(bool fromTemplate)
 {
        string initpath = lyxrc.document_path;
 
@@ -1706,7 +1745,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
 }
 
 
-void LyXFunc::Open(string const & fname)
+void LyXFunc::open(string const & fname)
 {
        string initpath = lyxrc.document_path;
   
@@ -1867,7 +1906,7 @@ void LyXFunc::reloadBuffer()
 }
 
 
-void LyXFunc::CloseBuffer()
+void LyXFunc::closeBuffer()
 {
        if (bufferlist.close(owner->buffer()) && !quitting) {
                if (bufferlist.empty()) {