Skip to content

Commit

Permalink
Added restoring scrollbar and cursor position when restoring session
Browse files Browse the repository at this point in the history
  • Loading branch information
mezomish committed Apr 19, 2008
1 parent ac625e1 commit ba6e4b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/DocHandler.cpp
Expand Up @@ -538,9 +538,19 @@ void DocHandler::openSession(const QString& session) {
if (sess.open(QIODevice::ReadOnly)) {
QString fileName("");
while (!sess.atEnd()) {
fileName = sess.readLine().simplified();
QString lineStr = sess.readLine().simplified();
fileName = lineStr.section(':', 0, 0);
int scrPos = lineStr.section(':', 1, 1).toInt();
int line = lineStr.section(':', 2, 2).toInt();
if (!fileName.isEmpty()) {
doc = newDocument(fileName);
if (doc != 0 && !doc->isNull()) {
TextDocView* tdView = qobject_cast<TextDocView*>(doc->view());
if (tdView != 0) {
tdView->setCursorPos(line, 0);
tdView->setScrollPos(scrPos);
}
}
}
}

Expand All @@ -565,9 +575,13 @@ void DocHandler::saveSession(const QString& name) {
QWidgetList wList;
hInt_->viewer_->getViewsOrder(wList);
foreach (QWidget* w, wList) {
DocView* view = qobject_cast<DocView*>(w);
TextDocView* view = qobject_cast<TextDocView*>(w);
if (view != 0) {
sess.write(view->document()->fileName().toLocal8Bit() + "\n");
int scrPos = view->scrollPos();
int line, col;
view->getCursorPos(line, col);
sess.write(QString("%1:%2:%3\n")
.arg(view->document()->fileName()).arg(scrPos).arg(line).toLocal8Bit());
}
}
sess.close();
Expand Down
18 changes: 18 additions & 0 deletions src/TextDocView.cpp
Expand Up @@ -234,6 +234,24 @@ void TextDocView::getCursorPos(int& row, int& col) const {
vInt_->edit_->getCursorPosition(&row, &col);
}

void TextDocView::setCursorPos(int row, int col) {
vInt_->edit_->setCursorPosition(row, col);
}

int TextDocView::scrollPos() const {
QScrollBar* scr = vInt_->edit_->verticalScrollBar();
if (scr != 0)
return scr->value();
else
return 0;
}

void TextDocView::setScrollPos(int pos) {
QScrollBar* scr = vInt_->edit_->verticalScrollBar();
if (scr != 0)
scr->setValue(pos);
}

void TextDocView::gotoLine(int line) const {
vInt_->edit_->setCursorPosition(line - 1, 0);
}
Expand Down
3 changes: 3 additions & 0 deletions src/TextDocView.h
Expand Up @@ -45,7 +45,10 @@ Q_OBJECT
void setModified(bool);
void getText(QString&) const;
void setText(const QString&);
int scrollPos() const;
void setScrollPos(int);
void getCursorPos(int&, int&) const;
void setCursorPos(int, int);
void gotoLine(int) const;
int lineCount() const;
void setSyntax(const QString&);
Expand Down

0 comments on commit ba6e4b4

Please sign in to comment.