]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / lyxfunc.C
index 71aabfa5185684149f92ae702df4c00b4d63671b..89c92637b88bfea81ab21001faa877d049e94dbe 100644 (file)
 
 using bv_funcs::freefont2string;
 
+using lyx::docstring;
+
 using lyx::support::absolutePath;
 using lyx::support::addName;
 using lyx::support::addPath;
@@ -116,7 +118,6 @@ using lyx::support::isStrInt;
 using lyx::support::makeAbsPath;
 using lyx::support::makeDisplayPath;
 using lyx::support::package;
-using lyx::support::Path;
 using lyx::support::quoteName;
 using lyx::support::rtrim;
 using lyx::support::split;
@@ -183,7 +184,7 @@ bool getStatus(LCursor cursor,
  * footnote is deleted).
  * When \param outer is true, the top slice is not looked at.
  */
-Change::Type lookupChange(DocIterator const & dit, bool outer = false)
+Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
 {
        size_t const depth = dit.depth() - (outer ? 1 : 0);
 
@@ -191,7 +192,7 @@ Change::Type lookupChange(DocIterator const & dit, bool outer = false)
                CursorSlice const & slice = dit[i];
                if (!slice.inset().inMathed()
                    && slice.pos() < slice.paragraph().size()) {
-                       Change::Type const ch = slice.paragraph().lookupChange(slice.pos());
+                       Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
                        if (ch != Change::UNCHANGED)
                                return ch;
                }
@@ -248,7 +249,8 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 
        Encoding const * encoding = view()->cursor().getEncoding();
 
-       encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
+       //encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
+       size_t encoded_last_key = keysym->getUCSEncoded();
 
        // Do a one-deep top-level lookup for
        // cancel and meta-fake keys. RVDK_PATCH_5
@@ -262,7 +264,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
        // When not cancel or meta-fake, do the normal lookup.
        // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
        // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
-       if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
+       if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
                // remove Caps Lock and Mod2 as a modifiers
                func = keyseq.addkey(keysym, (state | meta_fake_bit));
                lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION
@@ -275,7 +277,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 
        // Can this happen now ?
        if (func.action == LFUN_NOACTION) {
-               func = FuncRequest(LFUN_PREFIX);
+               func = FuncRequest(LFUN_COMMAND_PREFIX);
        }
 
        if (lyxerr.debugging(Debug::KEY)) {
@@ -291,7 +293,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
        // num_bytes == 0? (Lgb)
 
        if (keyseq.length() > 1) {
-               owner->message(keyseq.print());
+               owner->message(lyx::from_utf8(keyseq.print()));
        }
 
 
@@ -310,7 +312,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
                // by a binding
                if (keysym->isText() && keyseq.length() == 1) {
                        lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
-                       func = FuncRequest(LFUN_SELFINSERT,
+                       func = FuncRequest(LFUN_SELF_INSERT,
                                           FuncRequest::KEYBOARD);
                } else {
                        lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
@@ -319,13 +321,13 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
                }
        }
 
-       if (func.action == LFUN_SELFINSERT) {
+       if (func.action == LFUN_SELF_INSERT) {
                if (encoded_last_key != 0) {
-                       string const arg(1, encoded_last_key);
-                       dispatch(FuncRequest(LFUN_SELFINSERT, arg,
+                       docstring const arg(1, encoded_last_key);
+                       dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
                                             FuncRequest::KEYBOARD));
                        lyxerr[Debug::KEY]
-                               << "SelfInsert arg[`" << arg << "']" << endl;
+                               << "SelfInsert arg[`" << lyx::to_utf8(arg) << "']" << endl;
                }
        } else {
                dispatch(func);
@@ -354,7 +356,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                buf = owner->buffer();
 
        if (cmd.action == LFUN_NOACTION) {
-               flag.message(N_("Nothing to do"));
+               flag.message(lyx::from_utf8(N_("Nothing to do")));
                flag.enabled(false);
                return flag;
        }
@@ -372,21 +374,21 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        }
 
        if (flag.unknown()) {
-               flag.message(N_("Unknown action"));
+               flag.message(lyx::from_utf8(N_("Unknown action")));
                return flag;
        }
 
        if (!flag.enabled()) {
                if (flag.message().empty())
-                       flag.message(N_("Command disabled"));
+                       flag.message(lyx::from_utf8(N_("Command disabled")));
                return flag;
        }
 
        // Check whether we need a buffer
        if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
                // no, exit directly
-               flag.message(N_("Command not allowed with"
-                                   "out any document open"));
+               flag.message(lyx::from_utf8(N_("Command not allowed with"
+                                   "out any document open")));
                flag.enabled(false);
                return flag;
        }
@@ -401,27 +403,27 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                flag.setOnOff(owner->getDialogs().tooltipsEnabled());
                break;
 
-       case LFUN_READ_ONLY_TOGGLE:
+       case LFUN_BUFFER_TOGGLE_READ_ONLY:
                flag.setOnOff(buf->isReadonly());
                break;
 
-       case LFUN_SWITCHBUFFER:
+       case LFUN_BUFFER_SWITCH:
                // toggle on the current buffer, but do not toggle off
                // the other ones (is that a good idea?)
-               if (cmd.argument == buf->fileName())
+               if (lyx::to_utf8(cmd.argument()) == buf->fileName())
                        flag.setOnOff(true);
                break;
 
-       case LFUN_EXPORT:
-               enable = cmd.argument == "custom"
-                       || Exporter::isExportable(*buf, cmd.argument);
+       case LFUN_BUFFER_EXPORT:
+               enable = cmd.argument() == "custom"
+                       || Exporter::isExportable(*buf, lyx::to_utf8(cmd.argument()));
                break;
 
-       case LFUN_RUNCHKTEX:
+       case LFUN_BUFFER_CHKTEX:
                enable = buf->isLatex() && lyxrc.chktex_command != "none";
                break;
 
-       case LFUN_BUILDPROG:
+       case LFUN_BUILD_PROGRAM:
                enable = Exporter::isExportable(*buf, "program");
                break;
 
@@ -437,17 +439,17 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_VC_REGISTER:
                enable = !buf->lyxvc().inUse();
                break;
-       case LFUN_VC_CHECKIN:
+       case LFUN_VC_CHECK_IN:
                enable = buf->lyxvc().inUse() && !buf->isReadonly();
                break;
-       case LFUN_VC_CHECKOUT:
+       case LFUN_VC_CHECK_OUT:
                enable = buf->lyxvc().inUse() && buf->isReadonly();
                break;
        case LFUN_VC_REVERT:
-       case LFUN_VC_UNDO:
+       case LFUN_VC_UNDO_LAST:
                enable = buf->lyxvc().inUse();
                break;
-       case LFUN_MENURELOAD:
+       case LFUN_BUFFER_RELOAD:
                enable = !buf->isUnnamed() && !buf->isClean();
                break;
 
@@ -458,25 +460,25 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                InsetBase::Code code = cur.inset().lyxCode();
                switch (code) {
                        case InsetBase::TABULAR_CODE:
-                               enable = cmd.argument == "tabular";
+                               enable = cmd.argument() == "tabular";
                                break;
                        case InsetBase::ERT_CODE:
-                               enable = cmd.argument == "ert";
+                               enable = cmd.argument() == "ert";
                                break;
                        case InsetBase::FLOAT_CODE:
-                               enable = cmd.argument == "float";
+                               enable = cmd.argument() == "float";
                                break;
                        case InsetBase::WRAP_CODE:
-                               enable = cmd.argument == "wrap";
+                               enable = cmd.argument() == "wrap";
                                break;
                        case InsetBase::NOTE_CODE:
-                               enable = cmd.argument == "note";
+                               enable = cmd.argument() == "note";
                                break;
                        case InsetBase::BRANCH_CODE:
-                               enable = cmd.argument == "branch";
+                               enable = cmd.argument() == "branch";
                                break;
                        case InsetBase::BOX_CODE:
-                               enable = cmd.argument == "box";
+                               enable = cmd.argument() == "box";
                                break;
                        default:
                                break;
@@ -488,14 +490,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                string const name = cmd.getArg(0);
                InsetBase * inset = owner->getDialogs().getOpenInset(name);
                if (inset) {
-                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
+                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
                        FuncStatus fs;
                        bool const success = inset->getStatus(cur, fr, fs);
                        // Every inset is supposed to handle this
                        BOOST_ASSERT(success);
                        flag |= fs;
                } else {
-                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
+                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
                        flag |= getStatus(fr);
                }
                enable = flag.enabled();
@@ -539,13 +541,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
-       case LFUN_INSERT_CITATION: {
+       case LFUN_CITATION_INSERT: {
                FuncRequest fr(LFUN_INSET_INSERT, "citation");
                enable = getStatus(fr).enabled();
                break;
        }
 
-       case LFUN_MENUWRITE: {
+       case LFUN_BUFFER_WRITE: {
                enable = view()->buffer()->isUnnamed()
                        || !view()->buffer()->isClean();
                break;
@@ -553,66 +555,65 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 
        // this one is difficult to get right. As a half-baked
        // solution, we consider only the first action of the sequence
-       case LFUN_SEQUENCE: {
+       case LFUN_COMMAND_SEQUENCE: {
                // argument contains ';'-terminated commands
-               string const firstcmd = token(cmd.argument, ';', 0);
+               string const firstcmd = token(lyx::to_utf8(cmd.argument()), ';', 0);
                FuncRequest func(lyxaction.lookupFunc(firstcmd));
                func.origin = cmd.origin;
                flag = getStatus(func);
        }
 
-       case LFUN_MENUNEW:
-       case LFUN_MENUNEWTMPLT:
-       case LFUN_WORDFINDFORWARD:
-       case LFUN_WORDFINDBACKWARD:
-       case LFUN_PREFIX:
-       case LFUN_EXEC_COMMAND:
+       case LFUN_BUFFER_NEW:
+       case LFUN_BUFFER_NEW_TEMPLATE:
+       case LFUN_WORD_FIND_FORWARD:
+       case LFUN_WORD_FIND_BACKWARD:
+       case LFUN_COMMAND_PREFIX:
+       case LFUN_COMMAND_EXECUTE:
        case LFUN_CANCEL:
-       case LFUN_META_FAKE:
-       case LFUN_CLOSEBUFFER:
-       case LFUN_WRITEAS:
-       case LFUN_UPDATE:
-       case LFUN_PREVIEW:
-       case LFUN_IMPORT:
-       case LFUN_QUIT:
-       case LFUN_TOCVIEW:
-       case LFUN_AUTOSAVE:
+       case LFUN_META_PREFIX:
+       case LFUN_BUFFER_CLOSE:
+       case LFUN_BUFFER_WRITE_AS:
+       case LFUN_BUFFER_UPDATE:
+       case LFUN_BUFFER_VIEW:
+       case LFUN_BUFFER_IMPORT:
+       case LFUN_LYX_QUIT:
+       case LFUN_TOC_VIEW:
+       case LFUN_BUFFER_AUTO_SAVE:
        case LFUN_RECONFIGURE:
        case LFUN_HELP_OPEN:
        case LFUN_FILE_NEW:
        case LFUN_FILE_OPEN:
        case LFUN_DROP_LAYOUTS_CHOICE:
-       case LFUN_MENU_OPEN_BY_NAME:
-       case LFUN_GETNAME:
-       case LFUN_NOTIFY:
-       case LFUN_GOTOFILEROW:
-       case LFUN_DIALOG_SHOW_NEXT_INSET:
+       case LFUN_MENU_OPEN:
+       case LFUN_SERVER_GET_NAME:
+       case LFUN_SERVER_NOTIFY:
+       case LFUN_SERVER_GOTO_FILE_ROW:
        case LFUN_DIALOG_HIDE:
        case LFUN_DIALOG_DISCONNECT_INSET:
-       case LFUN_CHILDOPEN:
-       case LFUN_TOGGLECURSORFOLLOW:
-       case LFUN_KMAP_OFF:
-       case LFUN_KMAP_PRIM:
-       case LFUN_KMAP_SEC:
-       case LFUN_KMAP_TOGGLE:
+       case LFUN_BUFFER_CHILD_OPEN:
+       case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
+       case LFUN_KEYMAP_OFF:
+       case LFUN_KEYMAP_PRIMARY:
+       case LFUN_KEYMAP_SECONDARY:
+       case LFUN_KEYMAP_TOGGLE:
        case LFUN_REPEAT:
-       case LFUN_EXPORT_CUSTOM:
-       case LFUN_PRINT:
-       case LFUN_SAVEPREFERENCES:
+       case LFUN_BUFFER_EXPORT_CUSTOM:
+       case LFUN_BUFFER_PRINT:
+       case LFUN_PREFERENCES_SAVE:
        case LFUN_SCREEN_FONT_UPDATE:
        case LFUN_SET_COLOR:
        case LFUN_MESSAGE:
        case LFUN_EXTERNAL_EDIT:
        case LFUN_GRAPHICS_EDIT:
        case LFUN_ALL_INSETS_TOGGLE:
-       case LFUN_LANGUAGE_BUFFER:
+       case LFUN_BUFFER_LANGUAGE:
        case LFUN_TEXTCLASS_APPLY:
        case LFUN_TEXTCLASS_LOAD:
-       case LFUN_SAVE_AS_DEFAULT:
-       case LFUN_BUFFERPARAMS_APPLY:
+       case LFUN_BUFFER_SAVE_AS_DEFAULT:
+       case LFUN_BUFFER_PARAMS_APPLY:
        case LFUN_LYXRC_APPLY:
-       case LFUN_NEXTBUFFER:
-       case LFUN_PREVIOUSBUFFER:
+       case LFUN_BUFFER_NEXT:
+       case LFUN_BUFFER_PREVIOUS:
                // these are handled in our dispatch()
                break;
 
@@ -629,22 +630,22 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        if (buf && buf->isReadonly()
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
-               flag.message(N_("Document is read-only"));
+               flag.message(lyx::from_utf8(N_("Document is read-only")));
                flag.enabled(false);
        }
 
        // Are we in a DELETED change-tracking region?
        if (buf && buf->params().tracking_changes
-           && lookupChange(cur, true) == Change::DELETED
+           && lookupChangeType(cur, true) == Change::DELETED
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
-               flag.message(N_("This portion of the document is deleted."));
+               flag.message(lyx::from_utf8(N_("This portion of the document is deleted.")));
                flag.enabled(false);
        }
 
        // the default error message if we disable the command
        if (!flag.enabled() && flag.message().empty())
-               flag.message(N_("Command disabled"));
+               flag.message(lyx::from_utf8(N_("Command disabled")));
 
        return flag;
 }
@@ -658,16 +659,16 @@ bool ensureBufferClean(BufferView * bv)
        if (buf.isClean())
                return true;
 
-       string const file = makeDisplayPath(buf.fileName(), 30);
-       string text = bformat(_("The document %1$s has unsaved "
-                               "changes.\n\nDo you want to save "
-                               "the document?"), file);
+       docstring const file = makeDisplayPath(buf.fileName(), 30);
+       docstring text = bformat(_("The document %1$s has unsaved "
+                                            "changes.\n\nDo you want to save "
+                                            "the document?"), file);
        int const ret = Alert::prompt(_("Save changed document?"),
                                      text, 0, 1, _("&Save"),
                                      _("&Cancel"));
 
        if (ret == 0)
-               bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
+               bv->owner()->dispatch(FuncRequest(LFUN_BUFFER_WRITE));
 
        return buf.isClean();
 }
@@ -675,8 +676,8 @@ bool ensureBufferClean(BufferView * bv)
 
 void showPrintError(string const & name)
 {
-       string str = bformat(_("Could not print the document %1$s.\n"
-                              "Check that your printer is set up correctly."),
+       docstring str = bformat(_("Could not print the document %1$s.\n"
+                                           "Check that your printer is set up correctly."),
                             makeDisplayPath(name, 50));
        Alert::error(_("Print document failed"), str);
 }
@@ -697,9 +698,9 @@ void loadTextclass(string const & name)
        lyx::textclass_type const tc = tc_pair.second;
 
        if (!textclasslist[tc].load()) {
-               string s = bformat(_("The document could not be converted\n"
-                                    "into the document class %1$s."),
-                                  textclasslist[tc].name());
+               docstring s = bformat(_("The document could not be converted\n"
+                                                 "into the document class %1$s."),
+                                  lyx::from_utf8(textclasslist[tc].name()));
                Alert::error(_("Could not change class"), s);
        }
 }
@@ -713,7 +714,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
 void LyXFunc::dispatch(FuncRequest const & cmd)
 {
        BOOST_ASSERT(view());
-       string const argument = cmd.argument;
+       string const argument = lyx::to_utf8(cmd.argument());
        kb_action const action = cmd.action;
 
        lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
@@ -724,7 +725,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
        dispatch_buffer.erase();
 
        // redraw the screen at the end (first of the two drawing steps).
-       //This is done unless explicitely requested otherwise 
+       //This is done unless explicitely requested otherwise
        bool update = true;
        // also do the second redrawing step. Only done if requested.
        bool updateforce = false;
@@ -738,14 +739,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                       << endl;
                setErrorMessage(flag.message());
        } else {
-
-               if (view()->available())
-                       view()->hideCursor();
-
                switch (action) {
 
-               case LFUN_WORDFINDFORWARD:
-               case LFUN_WORDFINDBACKWARD: {
+               case LFUN_WORD_FIND_FORWARD:
+               case LFUN_WORD_FIND_BACKWARD: {
                        static string last_search;
                        string searched_string;
 
@@ -759,18 +756,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (searched_string.empty())
                                break;
 
-                       bool const fw = action == LFUN_WORDFINDFORWARD;
+                       bool const fw = action == LFUN_WORD_FIND_FORWARD;
                        string const data =
                                lyx::find::find2string(searched_string, true, false, fw);
                        lyx::find::find(view(), FuncRequest(LFUN_WORD_FIND, data));
                        break;
                }
 
-               case LFUN_PREFIX:
-                       owner->message(keyseq.printOptions());
+               case LFUN_COMMAND_PREFIX:
+                       owner->message(lyx::from_utf8(keyseq.printOptions()));
                        break;
 
-               case LFUN_EXEC_COMMAND:
+               case LFUN_COMMAND_EXECUTE:
                        owner->getToolbars().display("minibuffer", true);
                        owner->focus_command_buffer();
                        break;
@@ -778,18 +775,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_CANCEL:
                        keyseq.reset();
                        meta_fake_bit = key_modifier::none;
-                       if (view()->available())
+                       if (view()->buffer())
                                // cancel any selection
                                dispatch(FuncRequest(LFUN_MARK_OFF));
-                       setMessage(N_("Cancel"));
+                       setMessage(_("Cancel"));
                        break;
 
-               case LFUN_META_FAKE:
+               case LFUN_META_PREFIX:
                        meta_fake_bit = key_modifier::alt;
-                       setMessage(keyseq.print());
+                       setMessage(lyx::from_utf8(keyseq.print()));
                        break;
 
-               case LFUN_READ_ONLY_TOGGLE:
+               case LFUN_BUFFER_TOGGLE_READ_ONLY:
                        if (owner->buffer()->lyxvc().inUse())
                                owner->buffer()->lyxvc().toggleReadOnly();
                        else
@@ -798,21 +795,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                // --- Menus -----------------------------------------------
-               case LFUN_MENUNEW:
+               case LFUN_BUFFER_NEW:
                        menuNew(argument, false);
                        break;
 
-               case LFUN_MENUNEWTMPLT:
+               case LFUN_BUFFER_NEW_TEMPLATE:
                        menuNew(argument, true);
                        break;
 
-               case LFUN_CLOSEBUFFER:
+               case LFUN_BUFFER_CLOSE:
                        closeBuffer();
                        break;
 
-               case LFUN_MENUWRITE:
+               case LFUN_BUFFER_WRITE:
                        if (!owner->buffer()->isUnnamed()) {
-                               string const str = bformat(_("Saving document %1$s..."),
+                               docstring const str = bformat(_("Saving document %1$s..."),
                                         makeDisplayPath(owner->buffer()->fileName()));
                                owner->message(str);
                                menuWrite(owner->buffer());
@@ -822,15 +819,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        update = false;
                        break;
 
-               case LFUN_WRITEAS:
+               case LFUN_BUFFER_WRITE_AS:
                        writeAs(owner->buffer(), argument);
                        update = false;
                        break;
 
-               case LFUN_MENURELOAD: {
-                       string const file = makeDisplayPath(view()->buffer()->fileName(), 20);
-                       string text = bformat(_("Any changes will be lost. Are you sure "
-                               "you want to revert to the saved version of the document %1$s?"), file);
+               case LFUN_BUFFER_RELOAD: {
+                       docstring const file = makeDisplayPath(view()->buffer()->fileName(), 20);
+                       docstring text = bformat(_("Any changes will be lost. Are you sure "
+                                                            "you want to revert to the saved version of the document %1$s?"), file);
                        int const ret = Alert::prompt(_("Revert to saved document?"),
                                text, 0, 1, _("&Revert"), _("&Cancel"));
 
@@ -839,36 +836,31 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_UPDATE:
+               case LFUN_BUFFER_UPDATE:
                        Exporter::Export(owner->buffer(), argument, true);
-                       view()->showErrorList(bufferFormat(*owner->buffer()));
                        break;
 
-               case LFUN_PREVIEW:
+               case LFUN_BUFFER_VIEW:
                        Exporter::preview(owner->buffer(), argument);
-                       view()->showErrorList(bufferFormat(*owner->buffer()));
                        break;
 
-               case LFUN_BUILDPROG:
+               case LFUN_BUILD_PROGRAM:
                        Exporter::Export(owner->buffer(), "program", true);
-                       view()->showErrorList(_("Build"));
                        break;
 
-               case LFUN_RUNCHKTEX:
+               case LFUN_BUFFER_CHKTEX:
                        owner->buffer()->runChktex();
-                       view()->showErrorList(_("ChkTeX"));
                        break;
 
-               case LFUN_EXPORT:
+               case LFUN_BUFFER_EXPORT:
                        if (argument == "custom")
                                owner->getDialogs().show("sendto");
                        else {
                                Exporter::Export(owner->buffer(), argument, false);
-                               view()->showErrorList(bufferFormat(*owner->buffer()));
                        }
                        break;
 
-               case LFUN_EXPORT_CUSTOM: {
+               case LFUN_BUFFER_EXPORT_CUSTOM: {
                        string format_name;
                        string command = split(argument, format_name, ' ');
                        Format const * format = formats.getFormat(format_name);
@@ -896,8 +888,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        break;
 
                        } else {
-                               Exporter::Export(buffer, format_name, true,
-                                                filename);
+                               Exporter::Export(buffer, format_name, true, filename);
                        }
 
                        // Substitute $$FName for filename
@@ -911,7 +902,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_PRINT: {
+               case LFUN_BUFFER_PRINT: {
                        string target;
                        string target_name;
                        string command = split(split(argument, target, ' '),
@@ -939,7 +930,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        // Push directory path.
                        string const path = buffer->temppath();
-                       Path p(path);
+                       lyx::support::Path p(path);
 
                        // there are three cases here:
                        // 1. we print to a file
@@ -1002,12 +993,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_IMPORT:
+               case LFUN_BUFFER_IMPORT:
                        doImport(argument);
                        break;
 
-               case LFUN_QUIT:
-                       if (view()->available()) {
+               case LFUN_LYX_QUIT:
+                       if (view()->buffer()) {
                                // save cursor Position for opened files to .lyx/session
                                LyX::ref().session().saveFilePosition(owner->buffer()->fileName(),
                                        boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
@@ -1017,14 +1008,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        quitLyX(argument == "force");
                        break;
 
-               case LFUN_TOCVIEW: {
+               case LFUN_TOC_VIEW: {
                        InsetCommandParams p("tableofcontents");
                        string const data = InsetCommandMailer::params2string("toc", p);
                        owner->getDialogs().show("toc", data, 0);
                        break;
                }
 
-               case LFUN_AUTOSAVE:
+               case LFUN_BUFFER_AUTO_SAVE:
                        autoSave(view());
                        break;
 
@@ -1035,7 +1026,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_HELP_OPEN: {
                        string const arg = argument;
                        if (arg.empty()) {
-                               setErrorMessage(N_("Missing argument"));
+                               setErrorMessage(_("Missing argument"));
                                break;
                        }
                        string const fname = i18nLibFileSearch("doc", arg, "lyx");
@@ -1046,7 +1037,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        owner->message(bformat(_("Opening help file %1$s..."),
                                makeDisplayPath(fname)));
-                       view()->loadLyXFile(fname, false);
+                       owner->loadLyXFile(fname, false);
                        break;
                }
 
@@ -1060,7 +1051,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        break;
 
-               case LFUN_VC_CHECKIN:
+               case LFUN_VC_CHECK_IN:
                        if (!ensureBufferClean(view()))
                                break;
                        if (owner->buffer()->lyxvc().inUse()
@@ -1070,7 +1061,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        break;
 
-               case LFUN_VC_CHECKOUT:
+               case LFUN_VC_CHECK_OUT:
                        if (!ensureBufferClean(view()))
                                break;
                        if (owner->buffer()->lyxvc().inUse()
@@ -1085,22 +1076,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        view()->reload();
                        break;
 
-               case LFUN_VC_UNDO:
+               case LFUN_VC_UNDO_LAST:
                        owner->buffer()->lyxvc().undoLast();
                        view()->reload();
                        break;
 
                // --- buffers ----------------------------------------
-               case LFUN_SWITCHBUFFER:
-                       view()->setBuffer(bufferlist.getBuffer(argument));
+               case LFUN_BUFFER_SWITCH:
+                       owner->setBuffer(bufferlist.getBuffer(argument));
                        break;
 
-               case LFUN_NEXTBUFFER:
-                       view()->setBuffer(bufferlist.next(view()->buffer()));
+               case LFUN_BUFFER_NEXT:
+                       owner->setBuffer(bufferlist.next(view()->buffer()));
                        break;
 
-               case LFUN_PREVIOUSBUFFER:
-                       view()->setBuffer(bufferlist.previous(view()->buffer()));
+               case LFUN_BUFFER_PREVIOUS:
+                       owner->setBuffer(bufferlist.previous(view()->buffer()));
                        break;
 
                case LFUN_FILE_NEW:
@@ -1115,24 +1106,24 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        owner->getToolbars().openLayoutList();
                        break;
 
-               case LFUN_MENU_OPEN_BY_NAME:
-                       owner->getMenubar().openByName(argument);
+               case LFUN_MENU_OPEN:
+                       owner->getMenubar().openByName(lyx::from_utf8(argument));
                        break;
 
                // --- lyxserver commands ----------------------------
-               case LFUN_GETNAME:
-                       setMessage(owner->buffer()->fileName());
+               case LFUN_SERVER_GET_NAME:
+                       setMessage(lyx::from_utf8(owner->buffer()->fileName()));
                        lyxerr[Debug::INFO] << "FNAME["
                                                         << owner->buffer()->fileName()
                                                         << "] " << endl;
                        break;
 
-               case LFUN_NOTIFY:
-                       dispatch_buffer = keyseq.print();
-                       lyxserver->notifyClient(dispatch_buffer);
+               case LFUN_SERVER_NOTIFY:
+                       dispatch_buffer = lyx::from_utf8(keyseq.print());
+                       lyxserver->notifyClient(lyx::to_utf8(dispatch_buffer));
                        break;
 
-               case LFUN_GOTOFILEROW: {
+               case LFUN_SERVER_GOTO_FILE_ROW: {
                        string file_name;
                        int row;
                        istringstream is(argument);
@@ -1140,30 +1131,29 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (prefixIs(file_name, package().temp_dir())) {
                                // Needed by inverse dvi search. If it is a file
                                // in tmpdir, call the apropriated function
-                               view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
+                               owner->setBuffer(bufferlist.getBufferFromTmp(file_name));
                        } else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
                                string const s = changeExtension(file_name, ".lyx");
                                // Either change buffer or load the file
                                if (bufferlist.exists(s)) {
-                                       view()->setBuffer(bufferlist.getBuffer(s));
+                                       owner->setBuffer(bufferlist.getBuffer(s));
                                } else {
-                                       view()->loadLyXFile(s);
+                                       owner->loadLyXFile(s);
                                }
                        }
 
                        view()->setCursorFromRow(row);
 
                        view()->center();
-                       // see BufferView_pimpl::center()
-                       view()->updateScrollbar();
+                       // see BufferView::center()
                        break;
                }
 
                case LFUN_DIALOG_SHOW: {
                        string const name = cmd.getArg(0);
-                       string data = trim(cmd.argument.substr(name.size()));
+                       string data = trim(lyx::to_utf8(cmd.argument()).substr(name.size()));
 
                        if (name == "character") {
                                data = freefont2string();
@@ -1180,11 +1170,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        data = "literate ";
                                        break;
                                }
-                               data += logfile.second;
+                               data += LyXLex::quoteString(logfile.second);
                                owner->getDialogs().show("log", data);
                        } else if (name == "vclog") {
                                string const data = "vc " +
-                                       owner->buffer()->lyxvc().getLogFile();
+                                       LyXLex::quoteString(owner->buffer()->lyxvc().getLogFile());
                                owner->getDialogs().show("log", data);
                        } else
                                owner->getDialogs().show(name, data);
@@ -1193,7 +1183,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_DIALOG_SHOW_NEW_INSET: {
                        string const name = cmd.getArg(0);
-                       string data = trim(cmd.argument.substr(name.size()));
+                       string data = trim(lyx::to_utf8(cmd.argument()).substr(name.size()));
                        if (name == "bibitem" ||
                            name == "bibtex" ||
                            name == "index" ||
@@ -1243,15 +1233,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_DIALOG_SHOW_NEXT_INSET:
-                       break;
-
                case LFUN_DIALOG_UPDATE: {
                        string const & name = argument;
                        // Can only update a dialog connected to an existing inset
                        InsetBase * inset = owner->getDialogs().getOpenInset(name);
                        if (inset) {
-                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument);
+                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
                                inset->dispatch(view()->cursor(), fr);
                        } else if (name == "paragraph") {
                                dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@@ -1270,7 +1257,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
 
-               case LFUN_INSERT_CITATION: {
+               case LFUN_CITATION_INSERT: {
                        if (!argument.empty()) {
                                // we can have one optional argument, delimited by '|'
                                // citation-insert <key>|<text_before>
@@ -1293,17 +1280,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_CHILDOPEN: {
+               case LFUN_BUFFER_CHILD_OPEN: {
                        string const filename =
                                makeAbsPath(argument, owner->buffer()->filePath());
-                       setMessage(N_("Opening child document ") +
-                                        makeDisplayPath(filename) + "...");
+                       // FIXME Should use bformat
+                       setMessage(_("Opening child document ") +
+                                        makeDisplayPath(filename) + lyx::from_ascii("..."));
                        view()->savePosition(0);
                        string const parentfilename = owner->buffer()->fileName();
                        if (bufferlist.exists(filename))
-                               view()->setBuffer(bufferlist.getBuffer(filename));
+                               owner->setBuffer(bufferlist.getBuffer(filename));
                        else
-                               view()->loadLyXFile(filename);
+                               owner->loadLyXFile(filename);
                        // Set the parent name of the child document.
                        // This makes insertion of citations and references in the child work,
                        // when the target is in the parent or another child document.
@@ -1311,23 +1299,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_TOGGLECURSORFOLLOW:
+               case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
                        lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
                        break;
 
-               case LFUN_KMAP_OFF:
+               case LFUN_KEYMAP_OFF:
                        owner->getIntl().keyMapOn(false);
                        break;
 
-               case LFUN_KMAP_PRIM:
+               case LFUN_KEYMAP_PRIMARY:
                        owner->getIntl().keyMapPrim();
                        break;
 
-               case LFUN_KMAP_SEC:
+               case LFUN_KEYMAP_SECONDARY:
                        owner->getIntl().keyMapSec();
                        break;
 
-               case LFUN_KMAP_TOGGLE:
+               case LFUN_KEYMAP_TOGGLE:
                        owner->getIntl().toggleKeyMap();
                        break;
 
@@ -1344,7 +1332,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_SEQUENCE: {
+               case LFUN_COMMAND_SEQUENCE: {
                        // argument contains ';'-terminated commands
                        string arg = argument;
                        while (!arg.empty()) {
@@ -1357,8 +1345,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_SAVEPREFERENCES: {
-                       Path p(package().user_support());
+               case LFUN_PREFERENCES_SAVE: {
+                       lyx::support::Path p(package().user_support());
                        lyxrc.write("preferences", false);
                        break;
                }
@@ -1375,7 +1363,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        string lyx_name;
                        string const x11_name = split(argument, lyx_name, ' ');
                        if (lyx_name.empty() || x11_name.empty()) {
-                               setErrorMessage(N_("Syntax: set-color <lyx_name>"
+                               setErrorMessage(_("Syntax: set-color <lyx_name>"
                                                        " <x11_name>"));
                                break;
                        }
@@ -1386,9 +1374,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        if (!lcolor.setColor(lyx_name, x11_name)) {
                                setErrorMessage(
-                                       bformat(_("Set-color \"%1$s\" failed "
-                                                               "- color is undefined or "
-                                                               "may not be redefined"), lyx_name));
+                                               bformat(_("Set-color \"%1$s\" failed "
+                                                                      "- color is undefined or "
+                                                                      "may not be redefined"),
+                                                                          lyx::from_utf8(lyx_name)));
                                break;
                        }
 
@@ -1406,7 +1395,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_MESSAGE:
-                       owner->message(argument);
+                       owner->message(lyx::from_utf8(argument));
                        break;
 
                case LFUN_TOOLTIPS_TOGGLE:
@@ -1465,7 +1454,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_LANGUAGE_BUFFER: {
+               case LFUN_BUFFER_LANGUAGE: {
                        Buffer & buffer = *owner->buffer();
                        Language const * oldL = buffer.params().language;
                        Language const * newL = languages.getLanguage(argument);
@@ -1480,7 +1469,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_SAVE_AS_DEFAULT: {
+               case LFUN_BUFFER_SAVE_AS_DEFAULT: {
                        string const fname =
                                addName(addPath(package().user_support(), "templates/"),
                                        "defaults.lyx");
@@ -1492,13 +1481,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        int const unknown_tokens = defaults.readHeader(lex);
 
                        if (unknown_tokens != 0) {
-                               lyxerr << "Warning in LFUN_SAVE_AS_DEFAULT!\n"
+                               lyxerr << "Warning in LFUN_BUFFER_SAVE_AS_DEFAULT!\n"
                                       << unknown_tokens << " unknown token"
                                       << (unknown_tokens == 1 ? "" : "s")
                                       << endl;
                        }
 
                        if (defaults.writeFile(defaults.fileName()))
+                               // FIXME Should use bformat
                                setMessage(_("Document defaults saved in ")
                                           + makeDisplayPath(fname));
                        else
@@ -1506,7 +1496,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_BUFFERPARAMS_APPLY: {
+               case LFUN_BUFFER_PARAMS_APPLY: {
                        biblio::CiteEngine const engine =
                                owner->buffer()->params().cite_engine;
 
@@ -1517,7 +1507,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                owner->buffer()->readHeader(lex);
 
                        if (unknown_tokens != 0) {
-                               lyxerr << "Warning in LFUN_BUFFERPARAMS_APPLY!\n"
+                               lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
                                       << unknown_tokens << " unknown token"
                                       << (unknown_tokens == 1 ? "" : "s")
                                       << endl;
@@ -1560,14 +1550,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        recordUndoFullDocument(view());
                        buffer->params().textclass = new_class;
                        StableDocIterator backcur(view()->cursor());
-                       ErrorList el;
+                       ErrorList & el = buffer->errorList("Class Switch");
                        lyx::cap::switchBetweenClasses(
                                old_class, new_class,
-                               buffer->paragraphs(), el);
+                               static_cast<InsetText &>(buffer->inset()), el);
 
                        view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
-                       bufferErrors(*buffer, el);
-                       view()->showErrorList(_("Class switch"));
+
+                       buffer->errors("Class Switch");
                        updateLabels(*buffer);
                        updateforce = true;
                        break;
@@ -1603,7 +1593,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
                }
 
-               if (view()->available()) {
+               if (view()->buffer()) {
                        // Redraw screen unless explicitly told otherwise.
                        // This also initializes the position cache for all insets
                        // in (at least partially) visible top-level paragraphs.
@@ -1612,22 +1602,27 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        else if (update)
                                view()->update(Update::FitCursor);
 
+                       owner->redrawWorkArea();
+
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (flag.enabled()
                            && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
                            && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
                                view()->buffer()->markDirty();
-               }
 
-               if (view()->cursor().inTexted()) {
-                       view()->owner()->updateLayoutChoice();
+                       if (view()->cursor().inTexted()) {
+                               view()->owner()->updateLayoutChoice();
+                       }
                }
        }
-       sendDispatchMessage(_(getMessage()), cmd);
+       if (!quitting)
+               // FIXME UNICODE: _() does not support anything but ascii.
+               // Do we need a lyx::to_ascii() method?
+               sendDispatchMessage(getMessage(), cmd);
 }
 
 
-void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
+void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
 {
        /* When an action did not originate from the UI/kbd, it makes
         * sense to avoid updating the GUI. It turns out that this
@@ -1642,14 +1637,14 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
        const bool verbose = (cmd.origin == FuncRequest::UI
                              || cmd.origin == FuncRequest::COMMANDBUFFER);
 
-       if (cmd.action == LFUN_SELFINSERT || !verbose) {
-               lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
+       if (cmd.action == LFUN_SELF_INSERT || !verbose) {
+               lyxerr[Debug::ACTION] << "dispatch msg is " << lyx::to_utf8(msg) << endl;
                if (!msg.empty())
                        owner->message(msg);
                return;
        }
 
-       string dispatch_msg = msg;
+       docstring dispatch_msg = msg;
        if (!dispatch_msg.empty())
                dispatch_msg += ' ';
 
@@ -1657,9 +1652,9 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
 
        bool argsadded = false;
 
-       if (!cmd.argument.empty()) {
+       if (!cmd.argument().empty()) {
                if (cmd.action != LFUN_UNKNOWN_ACTION) {
-                       comname += ' ' + cmd.argument;
+                       comname += ' ' + lyx::to_utf8(cmd.argument());
                        argsadded = true;
                }
        }
@@ -1668,15 +1663,16 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
 
        if (!shortcuts.empty())
                comname += ": " + shortcuts;
-       else if (!argsadded && !cmd.argument.empty())
-               comname += ' ' + cmd.argument;
+       else if (!argsadded && !cmd.argument().empty())
+               comname += ' ' + lyx::to_utf8(cmd.argument());
 
        if (!comname.empty()) {
                comname = rtrim(comname);
-               dispatch_msg += '(' + rtrim(comname) + ')';
+               dispatch_msg += lyx::from_utf8('(' + rtrim(comname) + ')');
        }
 
-       lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
+       lyxerr[Debug::ACTION] << "verbose dispatch msg "
+               << lyx::to_utf8(dispatch_msg) << endl;
        if (!dispatch_msg.empty())
                owner->message(dispatch_msg);
 }
@@ -1696,7 +1692,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
        string initpath = lyxrc.document_path;
        string filename(name);
 
-       if (view()->available()) {
+       if (view()->buffer()) {
                string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (isDirWriteable(trypath))
@@ -1719,16 +1715,16 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
        // The template stuff
        string templname;
        if (fromTemplate) {
-               FileDialog fileDlg(_("Select template file"),
+               FileDialog fileDlg(lyx::to_utf8(_("Select template file")),
                        LFUN_SELECT_FILE_SYNC,
-                       make_pair(string(_("Documents|#o#O")),
+                       make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
                                  string(lyxrc.document_path)),
-                       make_pair(string(_("Templates|#T#t")),
+                       make_pair(string(lyx::to_utf8(_("Templates|#T#t"))),
                                  string(lyxrc.template_path)));
 
                FileDialog::Result result =
                        fileDlg.open(lyxrc.template_path,
-                                    FileFilterList(_("LyX Documents (*.lyx)")),
+                                    FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
                                     string());
 
                if (result.first == FileDialog::Later)
@@ -1738,7 +1734,9 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
                templname = result.second;
        }
 
-       view()->newFile(filename, templname, !name.empty());
+       Buffer * const b = newFile(filename, templname, !name.empty());
+       if (b)
+               owner->setBuffer(b);
 }
 
 
@@ -1746,7 +1744,7 @@ void LyXFunc::open(string const & fname)
 {
        string initpath = lyxrc.document_path;
 
-       if (view()->available()) {
+       if (view()->buffer()) {
                string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (isDirWriteable(trypath))
@@ -1756,16 +1754,16 @@ void LyXFunc::open(string const & fname)
        string filename;
 
        if (fname.empty()) {
-               FileDialog fileDlg(_("Select document to open"),
+               FileDialog fileDlg(lyx::to_utf8(_("Select document to open")),
                        LFUN_FILE_OPEN,
-                       make_pair(string(_("Documents|#o#O")),
+                       make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
                                  string(lyxrc.document_path)),
-                       make_pair(string(_("Examples|#E#e")),
+                       make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
                                  string(addPath(package().system_support(), "examples"))));
 
                FileDialog::Result result =
                        fileDlg.open(initpath,
-                                    FileFilterList(_("LyX Documents (*.lyx)")),
+                                    FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
                                     string());
 
                if (result.first == FileDialog::Later)
@@ -1788,19 +1786,21 @@ void LyXFunc::open(string const & fname)
                filename = fullpath;
        }
 
-       string const disp_fn(makeDisplayPath(filename));
+       docstring const disp_fn = makeDisplayPath(filename);
 
        // if the file doesn't exist, let the user create one
        if (!fs::exists(filename)) {
-               // the user specifically chose this name. Believe them.
-               view()->newFile(filename, "", true);
+               // the user specifically chose this name. Believe him.
+               Buffer * const b = newFile(filename, string(), true);
+               if (b)
+                       owner->setBuffer(b);
                return;
        }
 
        owner->message(bformat(_("Opening document %1$s..."), disp_fn));
 
-       string str2;
-       if (view()->loadLyXFile(filename)) {
+       docstring str2;
+       if (owner->loadLyXFile(filename)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
                str2 = bformat(_("Could not open document %1$s"), disp_fn);
@@ -1821,24 +1821,24 @@ void LyXFunc::doImport(string const & argument)
        if (filename.empty()) {
                string initpath = lyxrc.document_path;
 
-               if (view()->available()) {
+               if (view()->buffer()) {
                        string const trypath = owner->buffer()->filePath();
                        // If directory is writeable, use this as default.
                        if (isDirWriteable(trypath))
                                initpath = trypath;
                }
 
-               string const text = bformat(_("Select %1$s file to import"),
+               docstring const text = bformat(_("Select %1$s file to import"),
                        formats.prettyName(format));
 
-               FileDialog fileDlg(text,
-                       LFUN_IMPORT,
-                       make_pair(string(_("Documents|#o#O")),
+               FileDialog fileDlg(lyx::to_utf8(text),
+                       LFUN_BUFFER_IMPORT,
+                       make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
                                  string(lyxrc.document_path)),
-                       make_pair(string(_("Examples|#E#e")),
+                       make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
                                  string(addPath(package().system_support(), "examples"))));
 
-               string const filter = formats.prettyName(format)
+               string const filter = lyx::to_utf8(formats.prettyName(format))
                        + " (*." + formats.extension(format) + ')';
 
                FileDialog::Result result =
@@ -1875,10 +1875,10 @@ void LyXFunc::doImport(string const & argument)
        // if the file exists already, and we didn't do
        // -i lyx thefile.lyx, warn
        if (fs::exists(lyxfile) && filename != lyxfile) {
-               string const file = makeDisplayPath(lyxfile, 30);
+               docstring const file = makeDisplayPath(lyxfile, 30);
 
-               string text = bformat(_("The document %1$s already exists.\n\n"
-                       "Do you want to over-write that document?"), file);
+               docstring text = bformat(_("The document %1$s already exists.\n\n"
+                                                    "Do you want to over-write that document?"), file);
                int const ret = Alert::prompt(_("Over-write document?"),
                        text, 0, 1, _("&Over-write"), _("&Cancel"));
 
@@ -1888,7 +1888,9 @@ void LyXFunc::doImport(string const & argument)
                }
        }
 
-       Importer::Import(owner, filename, format);
+       ErrorList errorList;
+       Importer::Import(owner, filename, format, errorList);
+       // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
 }
 
 
@@ -1904,7 +1906,7 @@ void LyXFunc::closeBuffer()
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       view()->setBuffer(bufferlist.first());
+                       owner->setBuffer(bufferlist.first());
                }
        }
 }
@@ -1916,14 +1918,14 @@ void LyXFunc::closeBuffer()
 // This function is bit problematic when it comes to NLS, to make the
 // lyx servers client be language indepenent we must not translate
 // strings sent to this func.
-void LyXFunc::setErrorMessage(string const & m) const
+void LyXFunc::setErrorMessage(docstring const & m) const
 {
        dispatch_buffer = m;
        errorstat = true;
 }
 
 
-void LyXFunc::setMessage(string const & m) const
+void LyXFunc::setMessage(docstring const & m) const
 {
        dispatch_buffer = m;
 }
@@ -1940,8 +1942,8 @@ string const LyXFunc::viewStatusMessage()
        if (keyseq.length() > 0 && !keyseq.deleted())
                return keyseq.printOptions();
 
-       if (!view()->available())
-               return _("Welcome to LyX!");
+       if (!view()->buffer())
+               return lyx::to_utf8(_("Welcome to LyX!"));
 
        return view()->cursor().currentState();
 }
@@ -1950,7 +1952,7 @@ string const LyXFunc::viewStatusMessage()
 BufferView * LyXFunc::view() const
 {
        BOOST_ASSERT(owner);
-       return owner->view().get();
+       return owner->view();
 }
 
 
@@ -1991,11 +1993,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
        case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
        case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
-       case LyXRC::RC_CYGWIN_PATH_FIX:
-               if (lyxrc_orig.cygwin_path_fix != lyxrc_new.cygwin_path_fix) {
-                       namespace os = lyx::support::os;
-                       os::cygwin_path_fix(lyxrc_new.cygwin_path_fix);
-               }
        case LyXRC::RC_DATE_INSERT_FORMAT:
        case LyXRC::RC_DEFAULT_LANGUAGE:
        case LyXRC::RC_DEFAULT_PAPERSIZE:
@@ -2081,6 +2078,11 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_TEMPDIRPATH:
        case LyXRC::RC_TEMPLATEPATH:
        case LyXRC::RC_TEX_ALLOWS_SPACES:
+       case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
+               if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
+                       namespace os = lyx::support::os;
+                       os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
+               }
        case LyXRC::RC_UIFILE:
        case LyXRC::RC_USER_EMAIL:
        case LyXRC::RC_USER_NAME:
@@ -2092,7 +2094,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_USE_SPELL_LIB:
        case LyXRC::RC_VIEWDVI_PAPEROPTION:
        case LyXRC::RC_VIEWER:
-       case LyXRC::RC_WHEEL_JUMP:
        case LyXRC::RC_LAST:
                break;
        }