]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
fix "make dist" target
[lyx.git] / src / lyxfunc.C
index 210d46f49aa0999cbefb8941e6cdcb8fd0c33b95..d40c5a4a2272963d419d1df6e8f47d84152b48c7 100644 (file)
@@ -197,10 +197,10 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
 
 void LyXFunc::handleKeyFunc(kb_action action)
 {
-       char c = 0;
+       char c = keyseq.getiso();
 
-       if (keyseq.length == -1 && keyseq.getiso() != 0) 
-               c = keyseq.getiso();
+       if (keyseq.length != -1) c = 0;
+       
        owner->getIntl()->getTrans()
                .deadkey(c, get_accent(action).accent, TEXT(false));
        // Need to reset, in case the minibuffer calls these
@@ -214,12 +214,12 @@ void LyXFunc::handleKeyFunc(kb_action action)
 }
 
 
-int LyXFunc::processKeySym(KeySym keysym, unsigned int state) 
+void LyXFunc::processKeySym(KeySym keysym, unsigned int state) 
 {
        string argument;
        
        if (lyxerr.debugging(Debug::KEY)) {
-               char * tmp = XKeysymToString(keysym);
+               char const * tmp = XKeysymToString(keysym);
                string const stm = (tmp ? tmp : "");
                lyxerr << "KeySym is "
                       << stm
@@ -233,9 +233,14 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
                                   << endl;
                //return 0;
-               return FL_PREEMPT;
+               //return FL_PREEMPT;
+               return;
        }
 
+#if 0
+       // This if clause should not be here, but should rather be changed
+       // to a lyxfunc and get XK_Escape bound to it (Lgb)
+#warning Fix this please. (Lgb)
        if (owner->view()->available()) {
                // this function should be used always [asierra060396]
                UpdatableInset * tli = owner->view()->theLockingInset();
@@ -251,18 +256,22 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                                                        true);
                        }
                        //return 0;
-                       return FL_PREEMPT;
+                       //return FL_PREEMPT;
+                       return;
                }
        }
+#endif
        
        // Can we be sure that this will work for all X-Windows
        // implementations? (Lgb)
        // This code snippet makes lyx ignore some keys. Perhaps
        // all of them should be explictly mentioned?
        if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
-          || keysym == XK_Mode_switch || keysym == 0x0)
-               return 0;
-
+           || keysym == XK_Mode_switch || keysym == 0x0) {
+               //return 0;
+               return;
+       }
+       
        // Do a one-deep top-level lookup for
        // cancel and meta-fake keys. RVDK_PATCH_5
        cancel_meta_seq.reset();
@@ -317,26 +326,27 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        }
 
        if (action == -1) {
-               if (keyseq.length < -1) { // unknown key sequence...
-                       string buf;
-                       keyseq.print(buf);
-                       owner->message(_("Unknown sequence:") + ' ' + buf);
-                       return 0;
-               }
-       
-               char const isochar = keyseq.getiso();
-               if (!(state & ControlMask) &&
-                   !(state & Mod1Mask) &&
-                   (isochar && keysym < 0xF000)) {
-                       argument += isochar;
+               // It is unknown, but what if we remove all
+               // the modifiers? (Lgb)
+               action = keyseq.addkey(keysym, 0);
+
+               // We keep the shift state, but remove the others.
+               // This is for the sake of the LFUN_SELFINSERT below.
+               state &= ShiftMask;
+               
+               if (lyxerr.debugging(Debug::KEY)) {
+                       lyxerr << "Removing modifiers...\n"
+                              << "Action now set to ["
+                              << action << "]" << endl;
                }
-               if (argument.empty()) {
-                       lyxerr.debug() << "Empty argument!" << endl;
-                       // This can`t possibly be of any use
-                       // so we`ll skip the dispatch.
-                       return 0;
+               if (action == -1) {
+                       owner->message(_("Unknown function."));
+                       //return 0;
+                       return;
                }
-       } else if (action == LFUN_SELFINSERT) {
+       }
+
+       if (action == LFUN_SELFINSERT) {
                // We must set the argument to the char looked up by
                // XKeysymToString
                XKeyEvent xke;
@@ -357,13 +367,14 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                xke.same_screen = True;
                char ret[10];
                KeySym tmpkeysym;
-               int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
+               int const res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
                //Assert(keysym == tmpkeysym);
                lyxerr[Debug::KEY] << "TmpKeysym ["
                                   << tmpkeysym << "]" << endl;
                
                if (res > 0)
                        argument = string(ret, res);
+
                lyxerr[Debug::KEY] << "SelfInsert arg["
                                   << argument << "]" << endl;
        }
@@ -374,7 +385,7 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        Dispatch(action, argument);
        show_sc = tmp_sc;
        
-       return 0;
+       //return 0;
 } 
 
 
@@ -456,10 +467,6 @@ LyXFunc::func_status LyXFunc::getStatus(int ac,
                break;
 
        case LFUN_INSERTFOOTNOTE:
-#if 0
-       case LFUN_FOOTMELT:
-       case LFUN_MARGINMELT:
-#endif
                // Disable insertion of floats in a tabular.
                disable = false;
                if (owner->view()->theLockingInset()) {
@@ -565,6 +572,7 @@ void LyXFunc::miniDispatch(string const & s)
        Dispatch(s);
 }
 
+
 string const LyXFunc::Dispatch(string const & s) 
 {
        // Split command string into command and argument
@@ -603,7 +611,7 @@ string const LyXFunc::Dispatch(int ac,
        }
     
        selection_possible = false;
-
+       
        if (owner->view()->available())
                owner->view()->hideCursor();
 
@@ -747,9 +755,34 @@ string const LyXFunc::Dispatch(int ac,
                }
        }
 
-       Assert(action != LFUN_SELECT_FILE_SYNC);
+       lyx::Assert(action != LFUN_SELECT_FILE_SYNC);
 
        switch (action) {
+               
+       case LFUN_ESCAPE:
+       {
+               if (!owner->view()->available()) break;
+               
+               // this function should be used always [asierra060396]
+               UpdatableInset * tli =
+                       owner->view()->theLockingInset();
+               if (tli) {
+                       UpdatableInset * lock = tli->GetLockingInset();
+                       
+                       if (tli == lock) {
+                               owner->view()->unlockInset(tli);
+                               TEXT()->CursorRight(owner->view());
+                               moveCursorUpdate(true, false);
+                               owner->showState();
+                       } else {
+                               tli->UnlockInsetInInset(owner->view(),
+                                                       lock,
+                                                       true);
+                       }
+               }
+       }
+       break;
+                       
                // --- Misc -------------------------------------------
        case LFUN_WORDFINDFORWARD  : 
        case LFUN_WORDFINDBACKWARD : {
@@ -801,7 +834,6 @@ string const LyXFunc::Dispatch(int ac,
                }
                string buf;
                keyseq.print(buf, true);
-               //owner->getMiniBuffer()->Set(buf, string(), string(), 1);
                owner->message(buf);
        }
        break;
@@ -809,11 +841,11 @@ string const LyXFunc::Dispatch(int ac,
        // --- Misc -------------------------------------------
        case LFUN_EXEC_COMMAND:
        {
-               vector<string> allCmds;
-               transform(lyxaction.func_begin(), lyxaction.func_end(),
-                         back_inserter(allCmds), lyx::firster());
-               static vector<string> hist;
-               owner->getMiniBuffer()->getString(MiniBuffer::nospaces,
+               std::vector<string> allCmds;
+               std::transform(lyxaction.func_begin(), lyxaction.func_end(),
+                              std::back_inserter(allCmds), lyx::firster());
+               static std::vector<string> hist;
+               owner->getMiniBuffer()->getString(MiniBuffer::spaces,
                                                  allCmds, hist);
        }
        break;
@@ -918,22 +950,27 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_TOCVIEW:
+#if 0
        case LFUN_LOFVIEW:
        case LFUN_LOTVIEW:
        case LFUN_LOAVIEW:
+#endif
        {
                InsetCommandParams p;
-               
-               if (action == LFUN_TOCVIEW )
-                       p.setCmdName( "tableofcontents" );
+
+#if 0
+               if (action == LFUN_TOCVIEW)
+#endif
+                       p.setCmdName("tableofcontents");
+#if 0
                else if (action == LFUN_LOAVIEW )
-                       p.setCmdName( "listofalgorithms" );
-               else if (action == LFUN_LOFVIEW )
-                       p.setCmdName( "listoffigures" );
+                       p.setCmdName("listof{algorithm}{List of Algorithms}");
+               else if (action == LFUN_LOFVIEW)
+                       p.setCmdName("listoffigures");
                else
-                       p.setCmdName( "listoftables" );
-
-               owner->getDialogs()->createTOC( p.getAsString() );
+                       p.setCmdName("listoftables");
+#endif
+               owner->getDialogs()->createTOC(p.getAsString());
                break;
        }       
 
@@ -968,12 +1005,6 @@ string const LyXFunc::Dispatch(int ac,
                }
                break;
                
-#ifndef NEW_INSETS
-       case LFUN_OPENSTUFF:
-               owner->view()->openStuff();
-               break;
-#endif
-               
        case LFUN_HYPHENATION:
                owner->view()->hyphenationPoint();
                break;
@@ -1015,43 +1046,12 @@ string const LyXFunc::Dispatch(int ac,
                owner->view()->setState();
                owner->showState();
                break;
-#ifndef NEW_INSETS             
-       case LFUN_MELT:
-               Melt(owner->view());
-               break;
-#endif
+
        case LFUN_RECONFIGURE:
                Reconfigure(owner->view());
                break;
-#ifndef NEW_INSETS
-       case LFUN_FOOTMELT:
-               if (owner->view()->available()
-                   && !TEXT()->selection
-                   && TEXT()->cursor.par()->footnoteflag
-                   != LyXParagraph::NO_FOOTNOTE)
-                       { // only melt footnotes with FOOTMELT, not margins etc
-                               if (TEXT()->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE)
-                                       Melt(owner->view());
-                       }
-               else
-                       Foot(owner->view()); 
-               owner->view()->setState();
-               break;
 
-       case LFUN_MARGINMELT:
-               if (owner->view()->available()
-                   && !TEXT()->selection
-                   && TEXT()->cursor.par()->footnoteflag
-                   != LyXParagraph::NO_FOOTNOTE) {
-                       // only melt margins
-                       if (TEXT()->cursor.par()->footnotekind == LyXParagraph::MARGIN)
-                               Melt(owner->view());
-               } else
-                       Margin(owner->view()); 
-               owner->view()->setState();
-               break;
-#endif
-#ifndef NEW_INSETS
+#if 0
        case LFUN_FLOATSOPERATE:
                if (argument == "openfoot")
                        owner->view()->allFloats(1,0);
@@ -1374,11 +1374,11 @@ string const LyXFunc::Dispatch(int ac,
        }
        break;
        
+       case LFUN_MATH_EXTERN:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_LIMITS:
        {
                setErrorMessage(N_("This is only allowed in math mode!"));
-       
        }
        break;
 
@@ -1422,35 +1422,6 @@ string const LyXFunc::Dispatch(int ac,
        }
        break;
 
-#ifndef NEW_INSETS
-       case LFUN_INSERTFOOTNOTE: 
-       {
-               LyXParagraph::footnote_kind kind;
-               if (argument == "footnote") {
-                       kind = LyXParagraph::FOOTNOTE;
-               } else if (argument == "margin") {
-                       kind = LyXParagraph::MARGIN;
-               } else if (argument == "figure") {
-                       kind = LyXParagraph::FIG;
-               } else if (argument == "table") {
-                       kind = LyXParagraph::TAB;
-               } else if (argument == "wide-fig") {
-                       kind = LyXParagraph::WIDE_FIG;
-               } else if (argument == "wide-tab") {
-                       kind = LyXParagraph::WIDE_TAB;
-               } else if (argument == "algorithm") {
-                       kind = LyXParagraph::ALGORITHM;
-               } else {
-                       setErrorMessage(N_("Unknown kind of footnote"));
-                       break;
-               }
-               TEXT()->InsertFootnoteEnvironment(owner->view(), kind);
-               owner->view()->update(TEXT(),
-                                     BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               owner->view()->setState();
-       }
-       break;
-#endif
        case LFUN_TOGGLECURSORFOLLOW:
                lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
                break;
@@ -1548,7 +1519,8 @@ string const LyXFunc::Dispatch(int ac,
        default:
                // Then if it was none of the above
                if (!owner->view()->Dispatch(action, argument))
-                       lyxerr << "A truly unknown func!" << endl;
+                       lyxerr << "A truly unknown func ["
+                              << action << "]!" << endl;
                break;
        } // end of switch
 
@@ -1604,7 +1576,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                       _("newfile"));
        
                if (result.second.empty()) {
-                       Dispatch(LFUN_MESSAGE, _("Canceled."));
+                       owner->message(_("Canceled."));
                        lyxerr.debug() << "New Document Cancelled." << endl;
                        return;
                }
@@ -1631,7 +1603,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                owner->view()->buffer(bufferlist.getBuffer(s));
                                return;
                        case 3: // Cancel: Do nothing
-                               Dispatch(LFUN_MESSAGE, _("Canceled."));
+                               owner->message(_("Canceled."));
                                return;
                        }
                }
@@ -1643,14 +1615,14 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                        MakeDisplayPath(s, 50),
                                        _("Do you want to open the document?"))) {
                                // loads document
-                               Dispatch(LFUN_MESSAGE, _("Opening document")
-                                        + ' ' + MakeDisplayPath(s) + "...");
+                               owner->message(_("Opening document") + ' '
+                                              + MakeDisplayPath(s) + "...");
                                XFlush(fl_get_display());
                                owner->view()->buffer(
                                        bufferlist.loadLyXFile(s));
-                               Dispatch(LFUN_MESSAGE, _("Document")
-                                        + ' ' + MakeDisplayPath(s) + ' '
-                                        + _("opened."));
+                               owner->message(_("Document") + ' '
+                                              + MakeDisplayPath(s) + ' '
+                                              + _("opened."));
                                return;
                        }
                }
@@ -1729,7 +1701,7 @@ void LyXFunc::Open(string const & fname)
  
                // check selected filename
                if (filename.empty()) {
-                       Dispatch(LFUN_MESSAGE, _("Canceled."));
+                       owner->message(_("Canceled."));
                        return;
                }
        } else
@@ -1742,19 +1714,17 @@ void LyXFunc::Open(string const & fname)
                filename += ".lyx";
 
        // loads document
-       Dispatch(LFUN_MESSAGE,
-                _("Opening document") + ' '
-                + MakeDisplayPath(filename) + "...");
+       owner->message(_("Opening document") + ' '
+                      + MakeDisplayPath(filename) + "...");
        Buffer * openbuf = bufferlist.loadLyXFile(filename);
        if (openbuf) {
                owner->view()->buffer(openbuf);
-               Dispatch(LFUN_MESSAGE,
-                        _("Document") + ' '
-                        + MakeDisplayPath(filename) + ' ' + _("opened."));
+               owner->message(_("Document") + ' '
+                              + MakeDisplayPath(filename)
+                              + ' ' + _("opened."));
        } else {
-               Dispatch(LFUN_MESSAGE,
-                        _("Could not open document") + ' '
-                        + MakeDisplayPath(filename));
+               owner->message(_("Could not open document") + ' '
+                              + MakeDisplayPath(filename));
        }
 }
 
@@ -1801,7 +1771,7 @@ void LyXFunc::doImport(string const & argument)
  
                // check selected filename
                if (filename.empty())
-                       Dispatch(LFUN_MESSAGE, _("Canceled."));
+                       owner->message(_("Canceled."));
        }
 
        // still no filename? abort
@@ -1829,7 +1799,7 @@ void LyXFunc::doImport(string const & argument)
                                owner->view()->buffer(bufferlist.getBuffer(lyxfile));
                                return;
                        case 3: // Cancel: Do nothing
-                               Dispatch(LFUN_MESSAGE, _("Canceled."));
+                               owner->message(_("Canceled."));
                                return;
                        }
        }
@@ -1839,7 +1809,7 @@ void LyXFunc::doImport(string const & argument)
        if (f.exist() && !AskQuestion(_("A document by the name"), 
                                      MakeDisplayPath(lyxfile),
                                      _("already exists. Overwrite?"))) {
-               Dispatch(LFUN_MESSAGE, _("Canceled"));
+               owner->message(_("Canceled"));
                return;
        }
        // filename should be valid now