+void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
+{
+ BOOST_ASSERT(lyx_view_);
+ if (!LyX::ref().session().bookmarks().isValid(idx))
+ return;
+ 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(file)) {
+ if (openFile)
+ dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+ else
+ return;
+ }
+ // open may fail, so we need to test it again
+ if (theBufferList().exists(file)) {
+ // if the current buffer is not that one, switch to it.
+ if (lyx_view_->buffer()->fileName() != file) {
+ if (switchToBuffer)
+ dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+ else
+ return;
+ }
+ // moveToPosition use par_id, and par_pit and return new par_id.
+ pit_type new_pit;
+ 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
+ // 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);
+ }
+}
+
+