]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
remove LFUN_TOOLTIPS_TOGGLE and associated Dialog::tooltipsEnabled() method.
[lyx.git] / src / lyxfunc.C
index fbce9de95a40bb0991510cf8fd3ea21bb9d04b7c..44855227549b8c53c85657df3ca6e50cd58d2bfd 100644 (file)
 #include "insets/insetvspace.h"
 #include "insets/insetwrap.h"
 
+#include "frontends/Application.h"
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
+#include "frontends/FontLoader.h"
 #include "frontends/lyx_gui.h"
 #include "frontends/LyXKeySym.h"
 #include "frontends/LyXView.h"
 
 using bv_funcs::freefont2string;
 
+using lyx::docstring;
+
 using lyx::support::absolutePath;
 using lyx::support::addName;
 using lyx::support::addPath;
@@ -116,7 +120,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;
@@ -137,9 +140,6 @@ namespace biblio = lyx::biblio;
 namespace fs = boost::filesystem;
 
 
-extern BufferList bufferlist;
-extern LyXServer * lyxserver;
-
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 // (alkis)
@@ -219,7 +219,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
                c = 0;
        }
 
-       owner->getIntl().getTransManager()
+       owner->view()->getIntl().getTransManager()
                .deadkey(c, get_accent(action).accent, view()->getLyXText());
        // Need to clear, in case the minibuffer calls these
        // actions
@@ -248,7 +248,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
@@ -291,7 +292,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()));
        }
 
 
@@ -321,11 +322,11 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 
        if (func.action == LFUN_SELF_INSERT) {
                if (encoded_last_key != 0) {
-                       string const arg(1, encoded_last_key);
+                       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 +355,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;
        }
@@ -367,26 +368,27 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                flag.unknown(true);
                flag.enabled(false);
                break;
+
        default:
-               flag |= lyx_gui::getStatus(cmd);
+               break;
        }
 
        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;
        }
@@ -397,10 +399,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        // to handle (Andre')
        bool enable = true;
        switch (cmd.action) {
-       case LFUN_TOOLTIPS_TOGGLE:
-               flag.setOnOff(owner->getDialogs().tooltipsEnabled());
-               break;
-
        case LFUN_BUFFER_TOGGLE_READ_ONLY:
                flag.setOnOff(buf->isReadonly());
                break;
@@ -408,17 +406,17 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        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_BUFFER_EXPORT:
-               enable = cmd.argument == "custom"
-                       || Exporter::isExportable(*buf, cmd.argument);
+               enable = cmd.argument() == "custom"
+                       || Exporter::isExportable(*buf, lyx::to_utf8(cmd.argument()));
                break;
 
        case LFUN_BUFFER_CHKTEX:
-               enable = buf->isLatex() && lyxrc.chktex_command != "none";
+               enable = buf->isLatex() && !lyxrc.chktex_command.empty();
                break;
 
        case LFUN_BUILD_PROGRAM:
@@ -458,25 +456,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 +486,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();
@@ -555,7 +553,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        // solution, we consider only the first action of the 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);
@@ -586,7 +584,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_SERVER_GET_NAME:
        case LFUN_SERVER_NOTIFY:
        case LFUN_SERVER_GOTO_FILE_ROW:
-       case LFUN_DIALOG_SHOW_NEXT_INSET:
        case LFUN_DIALOG_HIDE:
        case LFUN_DIALOG_DISCONNECT_INSET:
        case LFUN_BUFFER_CHILD_OPEN:
@@ -629,54 +626,53 @@ 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
-           && lookupChangeType(cur, true) == Change::DELETED
+       if (buf && 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;
 }
 
 
-namespace {
-
-bool ensureBufferClean(BufferView * bv)
+bool LyXFunc::ensureBufferClean(BufferView * bv)
 {
        Buffer & buf = *bv->buffer();
        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_BUFFER_WRITE));
+               dispatch(FuncRequest(LFUN_BUFFER_WRITE));
 
        return buf.isClean();
 }
 
 
+namespace {
+
 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 +693,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 +709,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;
@@ -763,7 +759,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_COMMAND_PREFIX:
-                       owner->message(keyseq.printOptions());
+                       owner->message(lyx::from_utf8(keyseq.printOptions()));
                        break;
 
                case LFUN_COMMAND_EXECUTE:
@@ -774,15 +770,15 @@ 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_PREFIX:
                        meta_fake_bit = key_modifier::alt;
-                       setMessage(keyseq.print());
+                       setMessage(lyx::from_utf8(keyseq.print()));
                        break;
 
                case LFUN_BUFFER_TOGGLE_READ_ONLY:
@@ -808,7 +804,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                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());
@@ -824,9 +820,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_BUFFER_RELOAD: {
-                       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);
+                       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"));
 
@@ -929,7 +925,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
@@ -997,7 +993,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_LYX_QUIT:
-                       if (view()->available()) {
+                       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()) );
@@ -1025,7 +1021,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");
@@ -1082,15 +1078,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                // --- buffers ----------------------------------------
                case LFUN_BUFFER_SWITCH:
-                       owner->setBuffer(bufferlist.getBuffer(argument));
+                       owner->setBuffer(theApp->bufferList().getBuffer(argument));
                        break;
 
                case LFUN_BUFFER_NEXT:
-                       owner->setBuffer(bufferlist.next(view()->buffer()));
+                       owner->setBuffer(theApp->bufferList().next(view()->buffer()));
                        break;
 
                case LFUN_BUFFER_PREVIOUS:
-                       owner->setBuffer(bufferlist.previous(view()->buffer()));
+                       owner->setBuffer(theApp->bufferList().previous(view()->buffer()));
                        break;
 
                case LFUN_FILE_NEW:
@@ -1106,20 +1102,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_MENU_OPEN:
-                       owner->getMenubar().openByName(argument);
+                       owner->getMenubar().openByName(lyx::from_utf8(argument));
                        break;
 
                // --- lyxserver commands ----------------------------
                case LFUN_SERVER_GET_NAME:
-                       setMessage(owner->buffer()->fileName());
+                       setMessage(lyx::from_utf8(owner->buffer()->fileName()));
                        lyxerr[Debug::INFO] << "FNAME["
                                                         << owner->buffer()->fileName()
                                                         << "] " << endl;
                        break;
 
                case LFUN_SERVER_NOTIFY:
-                       dispatch_buffer = keyseq.print();
-                       lyxserver->notifyClient(dispatch_buffer);
+                       dispatch_buffer = lyx::from_utf8(keyseq.print());
+                       theApp->server().notifyClient(lyx::to_utf8(dispatch_buffer));
                        break;
 
                case LFUN_SERVER_GOTO_FILE_ROW: {
@@ -1130,14 +1126,14 @@ 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
-                               owner->setBuffer(bufferlist.getBufferFromTmp(file_name));
+                               owner->setBuffer(theApp->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)) {
-                                       owner->setBuffer(bufferlist.getBuffer(s));
+                               if (theApp->bufferList().exists(s)) {
+                                       owner->setBuffer(theApp->bufferList().getBuffer(s));
                                } else {
                                        owner->loadLyXFile(s);
                                }
@@ -1146,13 +1142,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        view()->setCursorFromRow(row);
 
                        view()->center();
-                       // see BufferView_pimpl::center()
+                       // 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();
@@ -1182,7 +1178,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" ||
@@ -1232,15 +1228,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));
@@ -1285,12 +1278,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                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))
-                               owner->setBuffer(bufferlist.getBuffer(filename));
+                       if (theApp->bufferList().exists(filename))
+                               owner->setBuffer(theApp->bufferList().getBuffer(filename));
                        else
                                owner->loadLyXFile(filename);
                        // Set the parent name of the child document.
@@ -1305,19 +1299,19 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_KEYMAP_OFF:
-                       owner->getIntl().keyMapOn(false);
+                       owner->view()->getIntl().keyMapOn(false);
                        break;
 
                case LFUN_KEYMAP_PRIMARY:
-                       owner->getIntl().keyMapPrim();
+                       owner->view()->getIntl().keyMapPrim();
                        break;
 
                case LFUN_KEYMAP_SECONDARY:
-                       owner->getIntl().keyMapSec();
+                       owner->view()->getIntl().keyMapSec();
                        break;
 
                case LFUN_KEYMAP_TOGGLE:
-                       owner->getIntl().toggleKeyMap();
+                       owner->view()->getIntl().toggleKeyMap();
                        break;
 
                case LFUN_REPEAT: {
@@ -1347,7 +1341,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_PREFERENCES_SAVE: {
-                       Path p(package().user_support());
+                       lyx::support::Path p(package().user_support());
                        lyxrc.write("preferences", false);
                        break;
                }
@@ -1355,7 +1349,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_SCREEN_FONT_UPDATE:
                        // handle the screen font changes.
                        lyxrc.set_font_norm_type();
-                       lyx_gui::update_fonts();
+                       theApp->fontLoader().update();
                        // All visible buffers will need resize
                        view()->resize();
                        break;
@@ -1364,7 +1358,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;
                        }
@@ -1375,9 +1369,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;
                        }
 
@@ -1395,11 +1390,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_MESSAGE:
-                       owner->message(argument);
-                       break;
-
-               case LFUN_TOOLTIPS_TOGGLE:
-                       owner->getDialogs().toggleTooltips();
+                       owner->message(lyx::from_utf8(argument));
                        break;
 
                case LFUN_EXTERNAL_EDIT: {
@@ -1488,6 +1479,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
 
                        if (defaults.writeFile(defaults.fileName()))
+                               // FIXME Should use bformat
                                setMessage(_("Document defaults saved in ")
                                           + makeDisplayPath(fname));
                        else
@@ -1592,7 +1584,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.
@@ -1608,17 +1600,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                            && !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()) {
+                               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
@@ -1634,13 +1629,13 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
                              || cmd.origin == FuncRequest::COMMANDBUFFER);
 
        if (cmd.action == LFUN_SELF_INSERT || !verbose) {
-               lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
+               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 += ' ';
 
@@ -1648,9 +1643,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;
                }
        }
@@ -1659,15 +1654,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);
 }
@@ -1687,7 +1683,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))
@@ -1699,7 +1695,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
        if (filename.empty()) {
                filename = addName(lyxrc.document_path,
                            "newfile" + convert<string>(++newfile_number) + ".lyx");
-               while (bufferlist.exists(filename) || fs::is_readable(filename)) {
+               while (theApp->bufferList().exists(filename) || fs::is_readable(filename)) {
                        ++newfile_number;
                        filename = addName(lyxrc.document_path,
                                           "newfile" +  convert<string>(newfile_number) +
@@ -1710,16 +1706,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)
@@ -1739,7 +1735,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))
@@ -1749,16 +1745,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)
@@ -1781,7 +1777,7 @@ 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)) {
@@ -1794,7 +1790,7 @@ void LyXFunc::open(string const & fname)
 
        owner->message(bformat(_("Opening document %1$s..."), disp_fn));
 
-       string str2;
+       docstring str2;
        if (owner->loadLyXFile(filename)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
@@ -1816,24 +1812,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,
+               FileDialog fileDlg(lyx::to_utf8(text),
                        LFUN_BUFFER_IMPORT,
-                       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"))));
 
-               string const filter = formats.prettyName(format)
+               string const filter = lyx::to_utf8(formats.prettyName(format))
                        + " (*." + formats.extension(format) + ')';
 
                FileDialog::Result result =
@@ -1860,8 +1856,8 @@ void LyXFunc::doImport(string const & argument)
        string const lyxfile = changeExtension(filename, ".lyx");
 
        // Check if the document already is open
-       if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
-               if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
+       if (lyx_gui::use_gui && theApp->bufferList().exists(lyxfile)) {
+               if (!theApp->bufferList().close(theApp->bufferList().getBuffer(lyxfile), true)) {
                        owner->message(_("Canceled."));
                        return;
                }
@@ -1870,10 +1866,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"));
 
@@ -1894,14 +1890,14 @@ void LyXFunc::closeBuffer()
        // save current cursor position
        LyX::ref().session().saveFilePosition(owner->buffer()->fileName(),
                boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
-       if (bufferlist.close(owner->buffer(), true) && !quitting) {
-               if (bufferlist.empty()) {
+       if (theApp->bufferList().close(owner->buffer(), true) && !quitting) {
+               if (theApp->bufferList().empty()) {
                        // need this otherwise SEGV may occur while
                        // trying to set variables that don't exist
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       owner->setBuffer(bufferlist.first());
+                       owner->setBuffer(theApp->bufferList().first());
                }
        }
 }
@@ -1913,14 +1909,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;
 }
@@ -1937,8 +1933,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();
 }