]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Fix loop when opening TOC widget in an empty document, basically by Richard Heck.
[lyx.git] / src / lyxfunc.C
index 33d3ef2cb45d228a258ea510c5424be469629b0b..c61681ed4aaba67be61bca1ac284c82652fd8d21 100644 (file)
@@ -264,12 +264,13 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
                }
                // moveToPosition use par_id, and par_pit and return new par_id.
                pit_type new_pit;
+               pos_type new_pos;
                int new_id;
-               boost::tie(new_pit, new_id) = view()->moveToPosition(bm.par_pit, bm.par_id, bm.par_pos);
-               // if par_id or pit has been changed, reset par_pit and par_id
+               boost::tie(new_pit, new_pos, new_id) = view()->moveToPosition(bm.bottom_pit, bm.bottom_pos, bm.top_id, bm.top_pos);
+               // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
                // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
-               if (bm.par_pit != new_pit || bm.par_id != new_id)
-                       const_cast<BookmarksSection::Bookmark &>(bm).setPos(new_pit, new_id);
+               if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos || bm.top_id != new_id )
+                       const_cast<BookmarksSection::Bookmark &>(bm).updatePos(new_pit, new_pos, new_id);
        } 
 }
 
@@ -1004,8 +1005,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
 
                        // Push directory path.
-                       string const path = buffer->temppath();
-                       support::Path p(path);
+                       string const path(buffer->temppath());
+                       // Prevent the compiler from optimizing away p
+                       FileName pp(path);
+                       support::Path p(pp);
 
                        // there are three cases here:
                        // 1. we print to a file
@@ -1227,7 +1230,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        int row;
                        istringstream is(argument);
                        is >> file_name >> row;
-                       if (prefixIs(file_name, package().temp_dir())) {
+                       if (prefixIs(file_name, package().temp_dir().absFilename())) {
                                // Needed by inverse dvi search. If it is a file
                                // in tmpdir, call the apropriated function
                                lyx_view_->setBuffer(theBufferList().getBufferFromTmp(file_name));
@@ -1376,16 +1379,17 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                string opt1;
                                if (contains(argument, "|")) {
                                        arg = token(argument, '|', 0);
-                                       opt1 = '[' + token(argument, '|', 1) + ']';
+                                       opt1 = token(argument, '|', 1);
                                }
-                               std::ostringstream os;
-                               os << "citation LatexCommand\n"
-                                  << "\\cite" << opt1 << "{" << arg << "}\n"
-                                  << "\\end_inset";
-                               FuncRequest fr(LFUN_INSET_INSERT, os.str());
+                               InsetCommandParams icp("cite");
+                               icp["key"] = from_utf8(arg);
+                               if (!opt1.empty())
+                                       icp["before"] = from_utf8(opt1);
+                               string icstr = InsetCommandMailer::params2string("citation", icp);
+                               FuncRequest fr(LFUN_INSET_INSERT, icstr);
                                dispatch(fr);
                        } else
-                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, "citation"));
+                               dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
                        break;
                }
 
@@ -1461,7 +1465,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_PREFERENCES_SAVE: {
                        lyxrc.write(makeAbsPath("preferences",
-                                               package().user_support()),
+                                               package().user_support().absFilename()),
                                    false);
                        break;
                }
@@ -1560,8 +1564,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        InsetIterator it  = inset_iterator_begin(inset);
                        InsetIterator const end = inset_iterator_end(inset);
                        for (; it != end; ++it) {
-                               if (inset_code == InsetBase::NO_CODE
-                                   || inset_code == it->lyxCode()) {
+                               if (!it->asInsetMath()
+                                   && (inset_code == InsetBase::NO_CODE
+                                   || inset_code == it->lyxCode())) {
                                        LCursor tmpcur = cur;
                                        tmpcur.pushLeft(*it);
                                        it->dispatch(tmpcur, fr);
@@ -1582,14 +1587,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (oldL->rightToLeft() == newL->rightToLeft()
                            && !buffer.isMultiLingual())
                                buffer.changeLanguage(oldL, newL);
-                       else
-                               buffer.updateDocLang(newL);
                        break;
                }
 
                case LFUN_BUFFER_SAVE_AS_DEFAULT: {
                        string const fname =
-                               addName(addPath(package().user_support(), "templates/"),
+                               addName(addPath(package().user_support().absFilename(), "templates/"),
                                        "defaults.lyx");
                        Buffer defaults(fname);
 
@@ -1901,7 +1904,7 @@ void LyXFunc::open(string const & fname)
                FileDialog fileDlg(_("Select document to open"),
                        LFUN_FILE_OPEN,
                        make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
-                       make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support(), "examples"))));
+                       make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support().absFilename(), "examples"))));
 
                FileDialog::Result result =
                        fileDlg.open(from_utf8(initpath),
@@ -1975,7 +1978,7 @@ void LyXFunc::doImport(string const & argument)
                        LFUN_BUFFER_IMPORT,
                        make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
                        make_pair(_("Examples|#E#e"),
-                                 from_utf8(addPath(package().system_support(), "examples"))));
+                                 from_utf8(addPath(package().system_support().absFilename(), "examples"))));
 
                docstring filter = formats.prettyName(format);
                filter += " (*.";
@@ -2038,9 +2041,6 @@ void LyXFunc::doImport(string const & argument)
 
 void LyXFunc::closeBuffer()
 {
-       // save current cursor position
-       LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()),
-               boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
        // goto bookmark to update bookmark pit.
        for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
                gotoBookmark(i+1, false, false);
@@ -2156,7 +2156,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
                        string const encoded = FileName(
                                lyxrc_new.document_path).toFilesystemEncoding();
                        if (fs::exists(encoded) && fs::is_directory(encoded))
-                               support::package().document_dir() = lyxrc.document_path;
+                               support::package().document_dir() = FileName(lyxrc.document_path);
                }
        case LyXRC::RC_ESC_CHARS:
        case LyXRC::RC_FONT_ENCODING: