From 66dc054c6f065b4ddec28a65983c89a367343eb8 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 23 Sep 2009 13:45:58 +0000 Subject: [PATCH] * Transfer LFUN_SERVER_GOTO_FILE_ROW to GuiView and clean it up a bit. * Add a recenter() call to BufferView::setCursorFromRow() in order to get the screen centered around the found position. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31455 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 1 + src/LyXFunc.cpp | 55 ----------------------------------- src/Text3.cpp | 1 - src/frontends/qt4/GuiView.cpp | 54 ++++++++++++++++++++++++++++++++++ src/frontends/qt4/GuiView.h | 3 ++ 5 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index bdfc1e5932..96094ea605 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -2058,6 +2058,7 @@ void BufferView::setCursorFromRow(int row) buffer_.text().setCursor(d->cursor_, 0, 0); else buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos); + recenter(); } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 4e6cdda3e9..19d2b086c4 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -458,7 +458,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_DROP_LAYOUTS_CHOICE: case LFUN_SERVER_GET_FILENAME: case LFUN_SERVER_NOTIFY: - case LFUN_SERVER_GOTO_FILE_ROW: case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE: case LFUN_REPEAT: case LFUN_PREFERENCES_SAVE: @@ -592,60 +591,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd) theServer().notifyClient(to_utf8(dispatch_buffer)); break; - case LFUN_SERVER_GOTO_FILE_ROW: { - LASSERT(lv, /**/); - string file_name; - int row; - istringstream is(argument); - is >> file_name >> row; - file_name = os::internal_path(file_name); - Buffer * buf = 0; - bool loaded = false; - string const abstmp = package().temp_dir().absFilename(); - string const realtmp = package().temp_dir().realPath(); - // We have to use os::path_prefix_is() here, instead of - // simply prefixIs(), because the file name comes from - // an external application and may need case adjustment. - if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED) - || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) { - // Needed by inverse dvi search. If it is a file - // in tmpdir, call the apropriated function. - // If tmpdir is a symlink, we may have the real - // path passed back, so we correct for that. - if (!prefixIs(file_name, abstmp)) - file_name = subst(file_name, realtmp, abstmp); - buf = theBufferList().getBufferFromTmp(file_name); - } else { - // Must replace extension of the file to be .lyx - // and get full path - FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx"); - // Either change buffer or load the file - if (theBufferList().exists(s)) - buf = theBufferList().getBuffer(s); - else if (s.exists()) { - buf = lv->loadDocument(s); - loaded = true; - } else - lv->message(bformat( - _("File does not exist: %1$s"), - makeDisplayPath(file_name))); - } - - if (!buf) { - updateFlags = Update::None; - break; - } - - buf->updateLabels(); - lv->setBuffer(buf); - lv->documentBufferView()->setCursorFromRow(row); - if (loaded) - buf->errors("Parse"); - updateFlags = Update::FitCursor; - break; - } - - case LFUN_DIALOG_SHOW_NEW_INSET: { LASSERT(lv, /**/); string const name = cmd.getArg(0); diff --git a/src/Text3.cpp b/src/Text3.cpp index c1e89abd6a..587f90333b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2743,7 +2743,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_NOACTION: case LFUN_NOTE_NEXT: case LFUN_REFERENCE_NEXT: - case LFUN_SERVER_GOTO_FILE_ROW: case LFUN_SERVER_NOTIFY: case LFUN_SERVER_SET_XY: case LFUN_TEXTSTYLE_APPLY: diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index b1bfd73d42..ceb5f8067c 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1424,6 +1424,9 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; } + case LFUN_SERVER_GOTO_FILE_ROW: + break; + default: return false; } @@ -2404,6 +2407,53 @@ void GuiView::openChildDocument(string const & fname) } +bool GuiView::goToFileRow(string const & argument) +{ + string file_name; + int row; + istringstream is(argument); + is >> file_name >> row; + file_name = os::internal_path(file_name); + Buffer * buf = 0; + string const abstmp = package().temp_dir().absFilename(); + string const realtmp = package().temp_dir().realPath(); + // We have to use os::path_prefix_is() here, instead of + // simply prefixIs(), because the file name comes from + // an external application and may need case adjustment. + if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED) + || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) { + // Needed by inverse dvi search. If it is a file + // in tmpdir, call the apropriated function. + // If tmpdir is a symlink, we may have the real + // path passed back, so we correct for that. + if (!prefixIs(file_name, abstmp)) + file_name = subst(file_name, realtmp, abstmp); + buf = theBufferList().getBufferFromTmp(file_name); + } else { + // Must replace extension of the file to be .lyx + // and get full path + FileName const s = fileSearch(string(), + support::changeExtension(file_name, ".lyx"), "lyx"); + // Either change buffer or load the file + if (theBufferList().exists(s)) + buf = theBufferList().getBuffer(s); + else if (s.exists()) { + buf = loadDocument(s); + buf->updateLabels(); + buf->errors("Parse"); + } else { + message(bformat( + _("File does not exist: %1$s"), + makeDisplayPath(file_name))); + return false; + } + } + setBuffer(buf); + documentBufferView()->setCursorFromRow(row); + return true; +} + + bool GuiView::dispatch(FuncRequest const & cmd) { BufferView * bv = currentBufferView(); @@ -2725,6 +2775,10 @@ bool GuiView::dispatch(FuncRequest const & cmd) dispatchVC(cmd); break; + case LFUN_SERVER_GOTO_FILE_ROW: + goToFileRow(to_utf8(cmd.argument())); + break; + default: dispatched = false; break; diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 06449a9174..8201850505 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -200,6 +200,9 @@ private: bool event(QEvent * e); bool focusNextPrevChild(bool); + /// + bool goToFileRow(std::string const & argument); + /// struct GuiViewPrivate; GuiViewPrivate & d;