* 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
This commit is contained in:
Abdelrazak Younes 2009-09-23 13:45:58 +00:00
parent 94fb836258
commit 66dc054c6f
5 changed files with 58 additions and 56 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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:

View File

@ -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;

View File

@ -200,6 +200,9 @@ private:
bool event(QEvent * e);
bool focusNextPrevChild(bool);
///
bool goToFileRow(std::string const & argument);
///
struct GuiViewPrivate;
GuiViewPrivate & d;