]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
do not create invalid .lyx files when importing \i{}, \j{}, \l{} or \L{}.
[lyx.git] / src / lyxfunc.C
index e8c7676382c33a09ec6fa2eda405503902092552..1ece1addda7cd565d9c24aee084a518f9ffe4c68 100644 (file)
@@ -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;
@@ -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(FileName(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: {
@@ -1669,8 +1657,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: {
@@ -1716,15 +1706,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();
 
@@ -1812,7 +1800,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) +
@@ -2105,10 +2094,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: