]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
convert author names and status messages to docstring
[lyx.git] / src / lyxfunc.C
index ae40bd2894d0d8fd2b2870b03ccc66e86f7e7513..f8fe702f076bdc9281e0902e06f0808f2ed4c64f 100644 (file)
@@ -293,7 +293,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
                lyxerr << BOOST_CURRENT_FUNCTION
                       << " Key [action="
                       << func.action << "]["
-                      << keyseq->print() << ']'
+                      << to_utf8(keyseq->print()) << ']'
                       << endl;
        }
 
@@ -302,7 +302,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
        // num_bytes == 0? (Lgb)
 
        if (keyseq->length() > 1) {
-               lyx_view_->message(from_utf8(keyseq->print()));
+               lyx_view_->message(keyseq->print());
        }
 
 
@@ -764,12 +764,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_WORD_FIND_FORWARD:
                case LFUN_WORD_FIND_BACKWARD: {
                        BOOST_ASSERT(lyx_view_ && lyx_view_->view());
-                       static string last_search;
-                       string searched_string;
+                       static docstring last_search;
+                       docstring searched_string;
 
-                       if (!argument.empty()) {
-                               last_search = argument;
-                               searched_string = argument;
+                       if (!cmd.argument().empty()) {
+                               last_search = cmd.argument();
+                               searched_string = cmd.argument();
                        } else {
                                searched_string = last_search;
                        }
@@ -778,7 +778,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                break;
 
                        bool const fw = action == LFUN_WORD_FIND_FORWARD;
-                       string const data =
+                       docstring const data =
                                find2string(searched_string, true, false, fw);
                        find(view(), FuncRequest(LFUN_WORD_FIND, data));
                        break;
@@ -786,7 +786,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_COMMAND_PREFIX:
                        BOOST_ASSERT(lyx_view_);
-                       lyx_view_->message(from_utf8(keyseq->printOptions()));
+                       lyx_view_->message(keyseq->printOptions());
                        break;
 
                case LFUN_COMMAND_EXECUTE:
@@ -807,7 +807,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_META_PREFIX:
                        meta_fake_bit = key_modifier::alt;
-                       setMessage(from_utf8(keyseq->print()));
+                       setMessage(keyseq->print());
                        break;
 
                case LFUN_BUFFER_TOGGLE_READ_ONLY:
@@ -1034,22 +1034,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_LYX_QUIT:
-                       if (argument == "closeOnly") {
-                               if (!theApp()->gui().closeAll())
-                                       break;
-                               lyx_view_ = 0;
-                       }
-
-                       // FIXME: this code needs to be transfered somewhere else
-                       // as lyx_view_ will most certainly be null and a same buffer
-                       // might be visible in more than one LyXView.
-                       if (lyx_view_ && lyx_view_->view()->buffer()) {
-                               // save cursor Position for opened files to .lyx/session
-                               LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
-                                       boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
-                       }
-
-                       LyX::ref().quit();
+                       // quitting is triggered by the gui code
+                       // (leaving the event loop).
+                       if (theBufferList().quitWriteAll())
+                               theApp()->gui().closeAllViews();
                        break;
 
                case LFUN_TOC_VIEW: {
@@ -1076,14 +1064,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                setErrorMessage(_("Missing argument"));
                                break;
                        }
-                       string const fname = i18nLibFileSearch("doc", arg, "lyx").absFilename();
+                       FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
                        if (fname.empty()) {
                                lyxerr << "LyX: unable to find documentation file `"
                                                         << arg << "'. Bad installation?" << endl;
                                break;
                        }
                        lyx_view_->message(bformat(_("Opening help file %1$s..."),
-                               makeDisplayPath(fname)));
+                               makeDisplayPath(fname.absFilename())));
                        lyx_view_->loadLyXFile(fname, false);
                        break;
                }
@@ -1179,7 +1167,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_SERVER_NOTIFY:
-                       dispatch_buffer = from_utf8(keyseq->print());
+                       dispatch_buffer = keyseq->print();
                        theLyXServer().notifyClient(to_utf8(dispatch_buffer));
                        break;
 
@@ -1196,10 +1184,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        } else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
-                               string const s = changeExtension(file_name, ".lyx");
+                               FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
                                // Either change buffer or load the file
-                               if (theBufferList().exists(s)) {
-                                       lyx_view_->setBuffer(theBufferList().getBuffer(s));
+                               if (theBufferList().exists(s.absFilename())) {
+                                       lyx_view_->setBuffer(theBufferList().getBuffer(s.absFilename()));
                                } else {
                                        lyx_view_->loadLyXFile(s);
                                }
@@ -1258,6 +1246,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                InsetCommandParams p(name);
                                data = InsetCommandMailer::params2string(name, p);
                        } else if (name == "include") {
+                               // data is the include type: one of "include",
+                               // "input", "verbatiminput" or "verbatiminput*"
+                               if (data.empty())
+                                       // default type is requested
+                                       data = "include";
                                InsetCommandParams p(data);
                                data = InsetIncludeMailer::params2string(p);
                        } else if (name == "box") {
@@ -1359,7 +1352,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (theBufferList().exists(filename))
                                lyx_view_->setBuffer(theBufferList().getBuffer(filename));
                        else
-                               lyx_view_->loadLyXFile(filename);
+                               lyx_view_->loadLyXFile(FileName(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.
@@ -1669,8 +1662,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_WINDOW_CLOSE:
                        BOOST_ASSERT(lyx_view_);
                        BOOST_ASSERT(theApp());
+                       // ask the user for saving changes or cancel quit
+                       if (!theBufferList().quitWriteAll())
+                               break;
                        lyx_view_->close();
-                       // We return here because lyx_view does not exists anymore.
                        return;
 
                case LFUN_BOOKMARK_GOTO: {
@@ -1678,15 +1673,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        unsigned int idx = convert<unsigned int>(to_utf8(cmd.argument()));
                        BookmarksSection::Bookmark const bm = LyX::ref().session().bookmarks().bookmark(idx);
                        BOOST_ASSERT(!bm.filename.empty());
+                       string const file = bm.filename.absFilename();
                        // if the file is not opened, open it.
-                       if (!theBufferList().exists(bm.filename))
-                               dispatch(FuncRequest(LFUN_FILE_OPEN, bm.filename));
+                       if (!theBufferList().exists(file))
+                               dispatch(FuncRequest(LFUN_FILE_OPEN, file));
                        // open may fail, so we need to test it again
-                       if (theBufferList().exists(bm.filename)) {
+                       if (theBufferList().exists(file)) {
                                // if the current buffer is not that one, switch to it.
-                               if (lyx_view_->buffer()->fileName() != bm.filename)
-                                       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, bm.filename));
-                               // BOOST_ASSERT(lyx_view_->buffer()->fileName() != bm.filename);
+                               if (lyx_view_->buffer()->fileName() != file)
+                                       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+                               // BOOST_ASSERT(lyx_view_->buffer()->fileName() != file);
                                view()->moveToPosition(bm.par_id, bm.par_pos);
                        } 
                        break;
@@ -1715,15 +1711,13 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // BufferView::update() updates the ViewMetricsInfo and
                        // also initializes the position cache for all insets in
                        // (at least partially) visible top-level paragraphs.
-                       std::pair<bool, bool> needSecondUpdate 
-                               = view()->update(updateFlags);
-
-                       // Redraw screen unless explicitly told otherwise.
-                       if (needSecondUpdate.first)
+                       // We will redraw the screen only if needed.
+                       if (view()->update(updateFlags)) {
                                // Buffer::changed() signals that a repaint is needed.
                                // The frontend (WorkArea) knows which area to repaint
                                // thanks to the ViewMetricsInfo updated above.
                                view()->buffer()->changed();
+                       }
 
                        lyx_view_->updateStatusBar();
 
@@ -1774,7 +1768,7 @@ void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd
                }
        }
 
-       string const shortcuts = theTopLevelKeymap().printbindings(cmd);
+       string const shortcuts = to_utf8(theTopLevelKeymap().printbindings(cmd));
 
        if (!shortcuts.empty())
                comname += ": " + shortcuts;
@@ -1795,6 +1789,7 @@ void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd
 
 void LyXFunc::menuNew(string const & name, bool fromTemplate)
 {
+       // FIXME: initpath is not used. What to do?
        string initpath = lyxrc.document_path;
        string filename(name);
 
@@ -1810,7 +1805,8 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
        if (filename.empty()) {
                filename = addName(lyxrc.document_path,
                            "newfile" + convert<string>(++newfile_number) + ".lyx");
-               while (theBufferList().exists(filename) || fs::is_readable(filename)) {
+               while (theBufferList().exists(filename) ||
+                      fs::is_readable(FileName(filename).toFilesystemEncoding())) {
                        ++newfile_number;
                        filename = addName(lyxrc.document_path,
                                           "newfile" +  convert<string>(newfile_number) +
@@ -1884,10 +1880,8 @@ void LyXFunc::open(string const & fname)
        // get absolute path of file and add ".lyx" to the filename if
        // necessary
        FileName const fullname = fileSearch(string(), filename, "lyx");
-       BOOST_ASSERT(!fullname.empty());
-       filename = fullname.absFilename();
-
-       docstring const disp_fn = makeDisplayPath(filename);
+       if (!fullname.empty())
+               filename = fullname.absFilename();
 
        // if the file doesn't exist, let the user create one
        if (!fs::exists(fullname.toFilesystemEncoding())) {
@@ -1898,10 +1892,11 @@ void LyXFunc::open(string const & fname)
                return;
        }
 
+       docstring const disp_fn = makeDisplayPath(filename);
        lyx_view_->message(bformat(_("Opening document %1$s..."), disp_fn));
 
        docstring str2;
-       if (lyx_view_->loadLyXFile(filename)) {
+       if (lyx_view_->loadLyXFile(fullname)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
                str2 = bformat(_("Could not open document %1$s"), disp_fn);
@@ -1963,13 +1958,13 @@ void LyXFunc::doImport(string const & argument)
                return;
 
        // get absolute path of file
-       filename = makeAbsPath(filename);
+       FileName const fullname(makeAbsPath(filename));
 
-       string const lyxfile = changeExtension(filename, ".lyx");
+       FileName const lyxfile(changeExtension(fullname.absFilename(), ".lyx"));
 
        // Check if the document already is open
-       if (use_gui && theBufferList().exists(lyxfile)) {
-               if (!theBufferList().close(theBufferList().getBuffer(lyxfile), true)) {
+       if (use_gui && theBufferList().exists(lyxfile.absFilename())) {
+               if (!theBufferList().close(theBufferList().getBuffer(lyxfile.absFilename()), true)) {
                        lyx_view_->message(_("Canceled."));
                        return;
                }
@@ -1977,8 +1972,8 @@ 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) {
-               docstring const file = makeDisplayPath(lyxfile, 30);
+       if (fs::exists(lyxfile.toFilesystemEncoding()) && fullname != lyxfile) {
+               docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
 
                docstring text = bformat(_("The document %1$s already exists.\n\n"
                                                     "Do you want to over-write that document?"), file);
@@ -1992,7 +1987,7 @@ void LyXFunc::doImport(string const & argument)
        }
 
        ErrorList errorList;
-       Importer::Import(lyx_view_, filename, format, errorList);
+       Importer::Import(lyx_view_, fullname, format, errorList);
        // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
 }
 
@@ -2000,7 +1995,7 @@ void LyXFunc::doImport(string const & argument)
 void LyXFunc::closeBuffer()
 {
        // save current cursor position
-       LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
+       LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()),
                boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
        if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) {
                if (theBufferList().empty()) {
@@ -2034,7 +2029,7 @@ void LyXFunc::setMessage(docstring const & m) const
 }
 
 
-string const LyXFunc::viewStatusMessage()
+docstring const LyXFunc::viewStatusMessage()
 {
        // When meta-fake key is pressed, show the key sequence so far + "M-".
        if (wasMetaKey())
@@ -2046,7 +2041,7 @@ string const LyXFunc::viewStatusMessage()
                return keyseq->printOptions();
 
        if (!view()->buffer())
-               return to_utf8(_("Welcome to LyX!"));
+               return _("Welcome to LyX!");
 
        return view()->cursor().currentState();
 }
@@ -2104,10 +2099,10 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_DISPLAY_GRAPHICS:
        case LyXRC::RC_DOCUMENTPATH:
                if (lyxrc_orig.document_path != lyxrc_new.document_path) {
-                       if (fs::exists(lyxrc_new.document_path) &&
-                           fs::is_directory(lyxrc_new.document_path)) {
+                       string const encoded = FileName(
+                               lyxrc_new.document_path).toFilesystemEncoding();
+                       if (fs::exists(encoded) && fs::is_directory(encoded))
                                support::package().document_dir() = lyxrc.document_path;
-                       }
                }
        case LyXRC::RC_ESC_CHARS:
        case LyXRC::RC_FONT_ENCODING: