]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
InsetText/Tabular fixes (buglist from SF.NET)
[lyx.git] / src / lyxfunc.C
index b44f6c808c7018ab3ab15d9956222d65959bfbca..1ff937641a2012ac839fa9426e692bae64d9da69 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
 
 #include <time.h>
 #include <locale.h>
+#include <utility> 
+#include <algorithm> 
 
 #include <cstdlib>
 #include <cctype>
-#include <cstring>
+//#include <cstring>
 
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
+#include "support/lyxalgo.h"
 #include "version.h"
 #include "kbmap.h"
 #include "lyxfunc.h"
 #include "bufferlist.h"
 #include "ColorHandler.h"
 #include "lyxserver.h"
-#include "lyx.h"
+#include "figure_form.h"
 #include "intl.h"
 #include "lyx_main.h"
 #include "lyx_cb.h"
@@ -60,7 +63,6 @@
 #include "minibuffer.h"
 #include "vspace.h"
 #include "LyXView.h"
-#include "filedlg.h"
 #include "lyx_gui_misc.h"
 #include "support/filetools.h"
 #include "support/FileInfo.h"
@@ -75,8 +77,8 @@
 #include "trans_mgr.h"
 #include "layout.h"
 #include "WorkArea.h"
-#include "lyxfr1.h"
 #include "bufferview_funcs.h"
+#include "frontends/FileDialog.h"
 #include "frontends/Dialogs.h"
 #include "frontends/Toolbar.h"
 #include "frontends/Menubar.h"
 #include "importer.h"
 #include "FontLoader.h"
 #include "TextCache.h"
+#include "lyxfind.h"
 
 using std::pair;
+using std::make_pair; 
 using std::endl;
 using std::find_if;
 
-extern void math_insert_symbol(BufferView *, string const &);
-extern bool math_insert_greek(BufferView *, char);
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
 extern int greek_kb_flag;
 extern bool selection_possible;
 extern void MenuSendto();
 
-extern kb_keymap * toplevel_keymap;
+extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 extern void show_symbols_form(LyXFunc *);
 
@@ -111,10 +113,46 @@ extern LyXTextClass::size_type current_layout;
 
 extern void ShowLatexLog();
 
+
+#if 0
+
+///
+class MiniBufferController : public SigC::Object {
+public:
+       ///
+       MiniBufferController() {
+               minibuffer
+                       .cmdReady
+                       .connect(slot(this,
+                                     &MiniBufferController::receiveCommand));
+               minibuffer
+                       .argReady
+                       .connect(slot(this,
+                                     &MiniBufferController::receiveArg));
+       }
+       ///
+       void receiveCmd(string const & cmd) {}
+       ///
+       void receiveArg(string const & arg) {}
+       
+       
+private:
+};
+
+namespace {
+
+MiniBufferController mb_ctrl;
+
+}
+#endif
+
+
 /* === globals =========================================================== */
 
+// Initialization of static member var
 bool LyXFunc::show_sc = true;
 
+
 LyXFunc::LyXFunc(LyXView * o)
        : owner(o)
 {
@@ -124,14 +162,16 @@ LyXFunc::LyXFunc(LyXView * o)
        setupLocalKeymap();
 }
 
+
 inline
-LyXText * LyXFunc::TEXT(bool flag=true) const
+LyXText * LyXFunc::TEXT(bool flag = true) const
 {
        if (flag)
                return owner->view()->text;
        return owner->view()->getLyXText();
 }
 
+
 // I changed this func slightly. I commented out the ...FinishUndo(),
 // this means that all places that used to have a moveCursorUpdate, now
 // have a ...FinishUndo() as the preceeding statement. I have also added
@@ -140,7 +180,7 @@ LyXText * LyXFunc::TEXT(bool flag=true) const
 inline
 void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
 {
-       if (selecting || TEXT(flag)->mark_set) {
+       if (selecting || TEXT(flag)->selection.mark()) {
                TEXT(flag)->SetSelection(owner->view());
                if (TEXT(flag)->bv_owner)
                    owner->view()->toggleToggle();
@@ -157,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
@@ -170,16 +210,16 @@ void LyXFunc::handleKeyFunc(kb_action action)
        // copied verbatim from do_accent_char
        owner->view()->update(TEXT(false),
               BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-       TEXT(false)->sel_cursor = TEXT(false)->cursor;
+       TEXT(false)->selection.cursor = TEXT(false)->cursor;
 }
 
 
-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
@@ -193,35 +233,20 @@ 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 (owner->view()->available()) {
-               // this function should be used always [asierra060396]
-               UpdatableInset * tli = owner->view()->theLockingInset();
-               if (tli && (keysym == XK_Escape)) {
-                       if (tli == tli->GetLockingInset()) {
-                               owner->view()->unlockInset(tli);
-                               TEXT()->CursorRight(owner->view());
-                               moveCursorUpdate(true, false);
-                               owner->showState();
-                       } else {
-                               tli->UnlockInsetInInset(owner->view(),
-                                                       tli->GetLockingInset(),true);
-                       }
-                       //return 0;
-                       return FL_PREEMPT;
-               }
-       }
-       
        // 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();
@@ -238,7 +263,8 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
        if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
                if (lyxerr.debugging(Debug::KEY)) {
-                       lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
+                       lyxerr << "meta_fake_bit is ["
+                              << meta_fake_bit << "]" << endl;
                }
                // remove Caps Lock and Mod2 as a modifiers
                action = keyseq.addkey(keysym,
@@ -246,7 +272,8 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                                       &(ShiftMask|ControlMask
                                         |Mod1Mask));
                if (lyxerr.debugging(Debug::KEY)) {
-                       lyxerr << "action now set to [" << action << "]" << endl;
+                       lyxerr << "action now set to ["
+                              << action << "]" << endl;
                }
        }
        // Dont remove this unless you know what you are doing.
@@ -257,7 +284,7 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        if (lyxerr.debugging(Debug::KEY)) {
                string buf;
                keyseq.print(buf);
-               lyxerr << "Key ["
+               lyxerr << "Key [action="
                       << action << "]["
                       << buf << "]"
                       << endl;
@@ -270,76 +297,72 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        if (keyseq.length > 1 || keyseq.length < -1) {
                string buf;
                keyseq.print(buf);
-               owner->getMiniBuffer()->Set(buf);
+               owner->message(buf);
        }
 
        if (action == -1) {
-               if (keyseq.length < -1) { // unknown key sequence...
-                       string buf;
-                       keyseq.print(buf);
-                       owner->getMiniBuffer()->Set(_("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);
+
+               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) {
-               // We must set the argument to the char looked up by
-               // XKeysymToString
-               XKeyEvent xke;
-               xke.type = KeyPress;
-               xke.serial = 0;
-               xke.send_event = False;
-               xke.display = fl_get_display();
-               xke.window = 0;
-               xke.root = 0;
-               xke.subwindow = 0;
-               xke.time = 0;
-               xke.x = 0;
-               xke.y = 0;
-               xke.x_root = 0;
-               xke.y_root = 0;
-               xke.state = state;
-               xke.keycode = XKeysymToKeycode(fl_get_display(), keysym);
-               xke.same_screen = True;
-               char ret[10];
-               KeySym tmpkeysym;
-               int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
-               //Assert(keysym == tmpkeysym);
-               lyxerr[Debug::KEY] << "TmpKeysym ["
-                                  << tmpkeysym << "]" << endl;
+       }
+
+       if (action == LFUN_SELFINSERT) {
+               // This is very X dependant.
+               unsigned int c = keysym;
                
-               if (res > 0)
-                       argument = string(ret, res);
-               lyxerr[Debug::KEY] << "SelfInsert arg["
-                                  << argument << "]" << endl;
+               switch (c & 0x0000FF00) {
+                       // latin 1 byte 3 = 0
+               case 0x00000000: break;
+                       // latin 2 byte 3 = 1
+               case 0x00000100:
+                       // latin 3 byte 3 = 2
+               case 0x00000200:
+                       // latin 4 byte 3 = 3
+               case 0x00000300:
+                       // latin 8 byte 3 = 18 (0x12)
+               case 0x00001200:
+                       // latin 9 byte 3 = 19 (0x13)
+               case 0x00001300:
+                       c &= 0x000000FF;
+                       break;
+               default:
+                       c = 0;
+                       break;
+               }
+               if (c > 0)
+                       argument = static_cast<char>(c);
+               lyxerr[Debug::KEY] << "SelfInsert arg[`"
+                                  << argument << "']" << endl;
        }
        
-
         bool tmp_sc = show_sc;
        show_sc = false;
        Dispatch(action, argument);
        show_sc = tmp_sc;
        
-       return 0;
+       //return 0;
 } 
 
+
 LyXFunc::func_status LyXFunc::getStatus(int ac) const
 {
        return getStatus(ac, string());
 }
 
-LyXFunc::func_status LyXFunc::getStatus(int ac, string const & not_to_use_arg) const
+
+LyXFunc::func_status LyXFunc::getStatus(int ac,
+                                       string const & not_to_use_arg) const
 {
         kb_action action;
         func_status flag = LyXFunc::OK;
@@ -410,8 +433,6 @@ LyXFunc::func_status LyXFunc::getStatus(int ac, string const & not_to_use_arg) c
                break;
 
        case LFUN_INSERTFOOTNOTE:
-       case LFUN_FOOTMELT:
-       case LFUN_MARGINMELT:
                // Disable insertion of floats in a tabular.
                disable = false;
                if (owner->view()->theLockingInset()) {
@@ -511,6 +532,13 @@ LyXFunc::func_status LyXFunc::getStatus(int ac, string const & not_to_use_arg) c
 }
 
 
+// temporary dispatch method
+void LyXFunc::miniDispatch(string const & s) 
+{
+       Dispatch(s);
+}
+
+
 string const LyXFunc::Dispatch(string const & s) 
 {
        // Split command string into command and argument
@@ -523,7 +551,7 @@ string const LyXFunc::Dispatch(string const & s)
 
 
 string const LyXFunc::Dispatch(int ac,
-                        string const & do_not_use_this_arg)
+                              string const & do_not_use_this_arg)
 {
        lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
                              <<"] arg[" << do_not_use_this_arg << "]" << endl;
@@ -595,7 +623,8 @@ string const LyXFunc::Dispatch(int ac,
                        if (!comname.empty()) {
                                comname = strip(comname);
                                commandshortcut = "(" + comname + ')';
-                               owner->getMiniBuffer()->Set(commandshortcut);
+                               owner->message(commandshortcut);
+
                                // Here we could even add a small pause,
                                // to annoy the user and make him learn
                                // the shortcuts.
@@ -681,7 +710,10 @@ string const LyXFunc::Dispatch(int ac,
                                        }
                                        return string();
                                case LFUN_DOWN:
-                                       TEXT()->CursorDown(owner->view());
+                                       if (TEXT()->cursor.row()->next())
+                                               TEXT()->CursorDown(owner->view());
+                                       else
+                                               TEXT()->CursorRight(owner->view());
                                        moveCursorUpdate(true, false);
                                        owner->showState();
                                        return string();
@@ -692,7 +724,34 @@ string const LyXFunc::Dispatch(int ac,
                }
        }
 
+       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 : {
@@ -708,8 +767,8 @@ string const LyXFunc::Dispatch(int ac,
 
                if (!searched_string.empty() &&
                    ((action == LFUN_WORDFINDBACKWARD) ? 
-                    TEXT()->SearchBackward(owner->view(), searched_string) :
-                    TEXT()->SearchForward(owner->view(), searched_string))) {
+                    SearchBackward(owner->view(), searched_string) :
+                    SearchForward(owner->view(), searched_string))) {
 
                        // ??? What is that ???
                        owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
@@ -738,20 +797,27 @@ string const LyXFunc::Dispatch(int ac,
                
        case LFUN_PREFIX:
        {
-               if (owner->view()->available()) {
+               if (owner->view()->available() && !owner->view()->theLockingInset()) {
                        owner->view()->update(TEXT(),
                                              BufferView::SELECT|BufferView::FITCUR);
                }
                string buf;
                keyseq.print(buf, true);
-               owner->getMiniBuffer()->Set(buf, string(), string(), 1);
+               owner->message(buf);
        }
        break;
 
        // --- Misc -------------------------------------------
        case LFUN_EXEC_COMMAND:
-               owner->getMiniBuffer()->PrepareForCommand(); 
-               break;
+       {
+               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;
                
        case LFUN_CANCEL:                   // RVDK_PATCH_5
                keyseq.reset();
@@ -793,33 +859,24 @@ string const LyXFunc::Dispatch(int ac,
                MenuNew(true);
                break;
                
-       case LFUN_MENUOPEN:
-               MenuOpen();
-               break;
-               
        case LFUN_CLOSEBUFFER:
                CloseBuffer();
                break;
                
        case LFUN_MENUWRITE:
                if (!owner->buffer()->isUnnamed()) {
-                       owner->getMiniBuffer()->Set(_("Saving document"),
-                                                   MakeDisplayPath(owner->buffer()->fileName()),
-                                                   "...");
+                       string const s1 = _("Saving document") + ' '
+                               + MakeDisplayPath(owner->buffer()->fileName()
+                                                 + "...");
+                       
+                       owner->message(s1);
                        MenuWrite(owner->view(), owner->buffer());
-                       //owner->getMiniBuffer()-> {
-                       //      Set(_("Document saved as"),
-                       //          MakeDisplayPath(owner->buffer()->fileName()));
-                       //} else {
-                       //owner->getMiniBuffer()->Set(_("Save failed!"));
-                       //}
-               } else {
-                       MenuWriteAs(owner->view(), owner->buffer());
-               }
+               } else
+                       WriteAs(owner->view(), owner->buffer());
                break;
                
-       case LFUN_MENUWRITEAS:
-               MenuWriteAs(owner->view(), owner->buffer());
+       case LFUN_WRITEAS:
+               WriteAs(owner->view(), owner->buffer(), argument);
                break;
                
        case LFUN_MENURELOAD:
@@ -862,22 +919,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;
        }       
 
@@ -902,14 +964,8 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_MENUSEARCH:
-       {
-               // Ok this is one _very_ bad solution, but I think that some
-               // of this will be rewritten as part of GUI indep anyway.
-               // Lgb
-               static LyXFindReplace FR_;
-               FR_.StartSearch(owner->view());
-       }
-       break;
+               owner->getDialogs()->showSearch();
+               break;
                
        case LFUN_REMOVEERRORS:
                if (owner->view()->removeAutoInsets()) {
@@ -917,33 +973,7 @@ string const LyXFunc::Dispatch(int ac,
                        owner->view()->fitCursor(TEXT());
                }
                break;
-               
-#ifndef NEW_INSETS
-       case LFUN_OPENSTUFF:
-               owner->view()->openStuff();
-               break;
-#endif
-               
-       case LFUN_HYPHENATION:
-               owner->view()->hyphenationPoint();
-               break;
-               
-       case LFUN_LDOTS:
-               owner->view()->ldots();
-               break;
-               
-       case LFUN_END_OF_SENTENCE:
-               owner->view()->endOfSentenceDot();
-               break;
 
-       case LFUN_MENU_SEPARATOR:
-               owner->view()->menuSeparator();
-               break;
-               
-       case LFUN_HFILL:
-               owner->view()->hfill();
-               break;
-               
        case LFUN_DEPTH:
                changeDepth(owner->view(), TEXT(false), 0);
                break;
@@ -965,43 +995,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);
@@ -1013,7 +1012,9 @@ string const LyXFunc::Dispatch(int ac,
                        owner->view()->allFloats(0,1);
                break;
 #else
+#ifdef WITH_WARNINGS
 #warning Find another implementation here (or another lyxfunc)!
+#endif
 #endif
        case LFUN_HELP_COPYRIGHT:
                owner->getDialogs()->showCopyright();
@@ -1023,22 +1024,25 @@ string const LyXFunc::Dispatch(int ac,
                owner->getDialogs()->showCredits();
                break;
 
-        case LFUN_HELP_OPEN: {
-               string arg = argument;
+        case LFUN_HELP_OPEN:
+       {
+               string const arg = argument;
                if (arg.empty()) {
                        setErrorMessage(N_("Missing argument"));
                        break;
                }
                ProhibitInput(owner->view());
-               string fname = i18nLibFileSearch("doc", arg, "lyx");
+               string const fname = i18nLibFileSearch("doc", arg, "lyx");
                if (fname.empty()) {
                        lyxerr << "LyX: unable to find documentation file `"
                               << arg << "'. Bad installation?" << endl;
                        AllowInput(owner->view());
                        break;
                }
-               owner->getMiniBuffer()->Set(_("Opening help file"),
-                                           MakeDisplayPath(fname),"...");
+               string const str = _("Opening help file") + ' '
+                       + MakeDisplayPath(fname) + "...";
+               
+               owner->message(str);
                owner->view()->buffer(bufferlist.loadLyXFile(fname,false));
                AllowInput(owner->view());
                break;
@@ -1117,7 +1121,7 @@ string const LyXFunc::Dispatch(int ac,
        break;
                        
        case LFUN_FILE_OPEN:
-               owner->view()->buffer(bufferlist.loadLyXFile(argument));
+               Open(argument);
                break;
 
        case LFUN_LATEX_LOG:
@@ -1149,11 +1153,7 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_LAYOUT_PARAGRAPH:
-#ifdef USE_OLD_PARAGRAPH_LAYOUT
-               MenuLayoutParagraph();
-#else
                owner->getDialogs()->showLayoutParagraph();
-#endif
                break;
                
        case LFUN_LAYOUT_CHARACTER:
@@ -1245,6 +1245,8 @@ string const LyXFunc::Dispatch(int ac,
                int id;
                istr >> id;
                LyXParagraph * par = TEXT()->GetParFromID(id);
+               if (par == 0)
+                       break;
 
                // Set the cursor
                TEXT()->SetCursor(owner->view(), par, 0);
@@ -1321,19 +1323,17 @@ 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;
 
        case LFUN_MATH_PANEL:
-       {
-               show_symbols_form(this);
-       }
-       break;
+               owner->getDialogs()->showMathPanel();
+               break;
        
        case LFUN_CITATION_CREATE:
        {
@@ -1356,22 +1356,6 @@ string const LyXFunc::Dispatch(int ac,
        }
        break;
                    
-       case LFUN_CHILD_CREATE:
-       {
-               InsetCommandParams p("include");
-               if (!argument.empty()) {
-                       if (contains(argument, "|")) {
-                               p.setContents(token(argument, '|', 0));
-                               p.setOptions(token(argument, '|', 1));
-                       } else
-                               p.setContents(argument);
-                       Dispatch(LFUN_CHILD_INSERT, p.getAsString());
-               } else
-                       owner->getDialogs()->createInclude(p.getAsString());
-       }
-       break;
-
        case LFUN_CHILDOPEN:
        {
                string const filename =
@@ -1387,35 +1371,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;
@@ -1498,10 +1453,23 @@ string const LyXFunc::Dispatch(int ac,
                break;
        }
 
+       case LFUN_MESSAGE:
+               owner->message(argument);
+               break;
+
+       case LFUN_MESSAGE_PUSH:
+               owner->messagePush(argument);
+               break;
+
+       case LFUN_MESSAGE_POP:
+               owner->messagePop();
+               break;
+
        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
 
@@ -1511,19 +1479,11 @@ exit_with_message:
 
        if (res.empty()) {
                if (!commandshortcut.empty()) {
-                       string const newbuf =
-                               owner->getMiniBuffer()->GetText();
-                       if (newbuf != commandshortcut) {
-                               owner->getMiniBuffer()->Set(newbuf
-                                                           + " " +
-                                                           commandshortcut);
-                       }
+                       owner->getMiniBuffer()->addSet(commandshortcut);
                }
        } else {
-               string msg(_(res));
-               msg += " ";
-               msg += commandshortcut;
-               owner->getMiniBuffer()->Set(msg);
+               string const msg(_(res) + ' ' + commandshortcut);
+               owner->message(msg);
        }
 
        return res;
@@ -1532,15 +1492,14 @@ exit_with_message:
 
 void LyXFunc::setupLocalKeymap()
 {
-       keyseq.stdmap = keyseq.curmap = toplevel_keymap;
-       cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
+       keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
+       cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
 }
 
 
 void LyXFunc::MenuNew(bool fromTemplate)
 {
        string initpath = lyxrc.document_path;
-       LyXFileDlg fileDlg;
 
        if (owner->view()->available()) {
                string const trypath = owner->buffer()->filepath;
@@ -1553,31 +1512,36 @@ void LyXFunc::MenuNew(bool fromTemplate)
        string s;
        
        if (lyxrc.new_ask_filename) {
-               ProhibitInput(owner->view());
-               fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-               fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
-               string fname = fileDlg.Select(_("Enter Filename for new document"), 
-                                      initpath, "*.lyx", _("newfile"));
-               AllowInput(owner->view());
+               FileDialog fileDlg(owner, _("Enter filename for new document"),
+                                  LFUN_SELECT_FILE_SYNC,
+                       make_pair(string(_("Documents")),
+                                 string(lyxrc.document_path)),
+                       make_pair(string(_("Templates")),
+                                 string(lyxrc.template_path)));
+
+               FileDialog::Result result =
+                       fileDlg.Select(initpath,
+                                      _("*.lyx|LyX Documents (*.lyx)"),
+                                      _("newfile"));
        
-               if (fname.empty()) {
-                       owner->getMiniBuffer()->Set(_("Canceled."));
+               if (result.second.empty()) {
+                       owner->message(_("Canceled."));
                        lyxerr.debug() << "New Document Cancelled." << endl;
                        return;
                }
        
                // get absolute path of file and make sure the filename ends
                // with .lyx
-               s = MakeAbsPath(fname);
+               s = MakeAbsPath(result.second);
                if (!IsLyXFilename(s))
                        s += ".lyx";
 
                // Check if the document already is open
                if (bufferlist.exists(s)) {
-                       switch (AskConfirmation(_("Document is already open:"), 
-                                              MakeDisplayPath(s, 50),
-                                              _("Do you want to close that document now?\n"
-                                                "('No' will just switch to the open version)")))
+                       switch (AskConfirmation(_("Document is already open:"),
+                                               MakeDisplayPath(s, 50),
+                                               _("Do you want to close that document now?\n"
+                                                 "('No' will just switch to the open version)")))
                        {
                        case 1: // Yes: close the document
                                if (!bufferlist.close(bufferlist.getBuffer(s)))
@@ -1588,7 +1552,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                owner->view()->buffer(bufferlist.getBuffer(s));
                                return;
                        case 3: // Cancel: Do nothing
-                               owner->getMiniBuffer()->Set(_("Canceled."));
+                               owner->message(_("Canceled."));
                                return;
                        }
                }
@@ -1600,14 +1564,14 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                        MakeDisplayPath(s, 50),
                                        _("Do you want to open the document?"))) {
                                // loads document
-                               owner->getMiniBuffer()->Set(_("Opening document"), 
-                                                           MakeDisplayPath(s), "...");
+                               owner->message(_("Opening document") + ' '
+                                              + MakeDisplayPath(s) + "...");
                                XFlush(fl_get_display());
                                owner->view()->buffer(
                                        bufferlist.loadLyXFile(s));
-                               owner->getMiniBuffer()->Set(_("Document"),
-                                                           MakeDisplayPath(s),
-                                                           _("opened."));
+                               owner->message(_("Document") + ' '
+                                              + MakeDisplayPath(s) + ' '
+                                              + _("opened."));
                                return;
                        }
                }
@@ -1627,12 +1591,24 @@ void LyXFunc::MenuNew(bool fromTemplate)
        // The template stuff
        string templname;
        if (fromTemplate) {
-               ProhibitInput(owner->view());
-               string const fname = fileDlg.Select(_("Choose template"),
-                                                   lyxrc.template_path,
-                                                   "*.lyx");
-               AllowInput(owner->view());
-               if (fname.empty()) return;
+               FileDialog fileDlg(owner, _("Select template file"),
+                       LFUN_SELECT_FILE_SYNC,
+                       make_pair(string(_("Documents")),
+                                 string(lyxrc.document_path)),
+                       make_pair(string(_("Templates")),
+                                 string(lyxrc.template_path)));
+
+               FileDialog::Result result =
+                       fileDlg.Select(initpath,
+                                      _("*.lyx|LyX Documents (*.lyx)"));
+       
+               if (result.first == FileDialog::Later)
+                       return;
+
+               string const fname = result.second;
+
+               if (fname.empty()) 
+                       return;
                 templname = fname;
        }
   
@@ -1642,10 +1618,9 @@ void LyXFunc::MenuNew(bool fromTemplate)
 }
 
 
-void LyXFunc::MenuOpen()
+void LyXFunc::Open(string const & fname)
 {
        string initpath = lyxrc.document_path;
-       LyXFileDlg fileDlg;
   
        if (owner->view()->available()) {
                string const trypath = owner->buffer()->filepath;
@@ -1654,20 +1629,32 @@ void LyXFunc::MenuOpen()
                        initpath = trypath;
        }
 
-       // launches dialog
-       ProhibitInput(owner->view());
-       fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-       fileDlg.SetButton(1, _("Examples"), 
-                         AddPath(system_lyxdir, "examples"));
-       string filename = fileDlg.Select(_("Select Document to Open"),
-                                        initpath, "*.lyx");
-       AllowInput(owner->view());
+       string filename;
  
-       // check selected filename
-       if (filename.empty()) {
-               owner->getMiniBuffer()->Set(_("Canceled."));
-               return;
-       }
+       if (fname.empty()) {
+               FileDialog fileDlg(owner, _("Select document to open"),
+                       LFUN_FILE_OPEN,
+                       make_pair(string(_("Documents")),
+                                 string(lyxrc.document_path)),
+                       make_pair(string(_("Examples")),
+                                 string(AddPath(system_lyxdir, "examples"))));
+
+               FileDialog::Result result =
+                       fileDlg.Select(initpath,
+                                      "*.lyx|LyX Documents (*.lyx)");
+       
+               if (result.first == FileDialog::Later)
+                       return;
+
+               filename = result.second;
+               // check selected filename
+               if (filename.empty()) {
+                       owner->message(_("Canceled."));
+                       return;
+               }
+       } else
+               filename = fname;
 
        // get absolute path of file and make sure the filename ends
        // with .lyx
@@ -1676,17 +1663,17 @@ void LyXFunc::MenuOpen()
                filename += ".lyx";
 
        // loads document
-       owner->getMiniBuffer()->Set(_("Opening document"),
-                                   MakeDisplayPath(filename), "...");
+       owner->message(_("Opening document") + ' '
+                      + MakeDisplayPath(filename) + "...");
        Buffer * openbuf = bufferlist.loadLyXFile(filename);
        if (openbuf) {
                owner->view()->buffer(openbuf);
-               owner->getMiniBuffer()->Set(_("Document"),
-                                           MakeDisplayPath(filename),
-                                           _("opened."));
+               owner->message(_("Document") + ' '
+                              + MakeDisplayPath(filename)
+                              + ' ' + _("opened."));
        } else {
-               owner->getMiniBuffer()->Set(_("Could not open document"),
-                                           MakeDisplayPath(filename));
+               owner->message(_("Could not open document") + ' '
+                              + MakeDisplayPath(filename));
        }
 }
 
@@ -1701,7 +1688,6 @@ void LyXFunc::doImport(string const & argument)
 
        if (filename.empty()) { // need user interaction
                string initpath = lyxrc.document_path;
-               LyXFileDlg fileDlg;
                
                if (owner->view()->available()) {
                        string const trypath = owner->buffer()->filepath;
@@ -1710,20 +1696,31 @@ void LyXFunc::doImport(string const & argument)
                                initpath = trypath;
                }
 
-               // launches dialog
-               ProhibitInput(owner->view());
-               fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-               fileDlg.SetButton(1, _("Examples"), 
-                                       AddPath(system_lyxdir, "examples"));
                string const text = _("Select ") + formats.PrettyName(format)
                        + _(" file to import");
-               string const extension = "*." + formats.Extension(format);
-               filename = fileDlg.Select(text, initpath, extension);
-               AllowInput(owner->view());
+
+               FileDialog fileDlg(owner, text, 
+                       LFUN_IMPORT,
+                       make_pair(string(_("Documents")),
+                                 string(lyxrc.document_path)),
+                       make_pair(string(_("Examples")),
+                                 string(AddPath(system_lyxdir, "examples"))));
+                       
+               string const extension = "*." + formats.Extension(format)
+                       + "| " + formats.PrettyName(format)
+                       + " (*." + formats.Extension(format) + ")";
+
+               FileDialog::Result result = fileDlg.Select(initpath,
+                                                          extension);
+
+               if (result.first == FileDialog::Later)
+                       return;
+
+               filename = result.second;
  
                // check selected filename
-               if (filename.empty()) 
-                       owner->getMiniBuffer()->Set(_("Canceled."));
+               if (filename.empty())
+                       owner->message(_("Canceled."));
        }
 
        // still no filename? abort
@@ -1738,9 +1735,9 @@ void LyXFunc::doImport(string const & argument)
        // Check if the document already is open
        if (bufferlist.exists(lyxfile)) {
                switch (AskConfirmation(_("Document is already open:"), 
-                                      MakeDisplayPath(lyxfile, 50),
-                                      _("Do you want to close that document now?\n"
-                                        "('No' will just switch to the open version)")))
+                                       MakeDisplayPath(lyxfile, 50),
+                                       _("Do you want to close that document now?\n"
+                                         "('No' will just switch to the open version)")))
                        {
                        case 1: // Yes: close the document
                                if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
@@ -1751,7 +1748,7 @@ void LyXFunc::doImport(string const & argument)
                                owner->view()->buffer(bufferlist.getBuffer(lyxfile));
                                return;
                        case 3: // Cancel: Do nothing
-                               owner->getMiniBuffer()->Set(_("Canceled."));
+                               owner->message(_("Canceled."));
                                return;
                        }
        }
@@ -1761,11 +1758,11 @@ void LyXFunc::doImport(string const & argument)
        if (f.exist() && !AskQuestion(_("A document by the name"), 
                                      MakeDisplayPath(lyxfile),
                                      _("already exists. Overwrite?"))) {
-               owner->getMiniBuffer()->Set(_("Canceled."));
+               owner->message(_("Canceled"));
                return;
        }
        // filename should be valid now
-
+       
        Importer::Import(owner, filename, format);
 }
 
@@ -1810,3 +1807,50 @@ void LyXFunc::setMessage(string const & m)
 {
        dispatch_buffer = m;
 }
+
+
+void LyXFunc::initMiniBuffer() 
+{
+       string text = _("Welcome to LyX!");
+       
+       // When meta-fake key is pressed, show the key sequence so far + "M-".
+       if (wasMetaKey()) {
+               keyseqStr();
+               text += "M-";
+       }
+
+       // Else, when a non-complete key sequence is pressed,
+       // show the available options.
+       else if (keyseqUncomplete()) 
+               text = keyseqOptions();
+   
+       // Else, show the buffer state.
+       else if (owner->view()->available()) {
+               Buffer * tmpbuf = owner->buffer();
+               
+               string const nicename = 
+                       MakeDisplayPath(tmpbuf->fileName());
+               // Should we do this instead? (kindo like emacs)
+               // leaves more room for other information
+               text = "LyX: ";
+               text += nicename;
+               if (tmpbuf->lyxvc.inUse()) {
+                       text += " [";
+                       text += tmpbuf->lyxvc.version();
+                       text += ' ';
+                       text += tmpbuf->lyxvc.locker();
+                       if (tmpbuf->isReadonly())
+                               text += " (RO)";
+                       text += ']';
+               } else if (tmpbuf->isReadonly())
+                       text += " [RO]";
+               if (!tmpbuf->isLyxClean())
+                       text += _(" (Changed)");
+       } else {
+               if (text != _("Welcome to LyX!")) // this is a hack
+                       text = _("* No document open *");
+       }
+       
+       owner->message(text);
+}
+