diff --git a/kdevplatform/shell/textdocument.h b/kdevplatform/shell/textdocument.h --- a/kdevplatform/shell/textdocument.h +++ b/kdevplatform/shell/textdocument.h @@ -110,8 +110,9 @@ KTextEditor::View *textView() const; QString viewStatus() const override; - QString viewState() const override; - void setState(const QString& state) override; + + void readSessionConfig(KConfigGroup & config) override; + void writeSessionConfig(KConfigGroup & config) override; void setInitialRange(const KTextEditor::Range& range); KTextEditor::Range initialRange() const; diff --git a/kdevplatform/shell/textdocument.cpp b/kdevplatform/shell/textdocument.cpp --- a/kdevplatform/shell/textdocument.cpp +++ b/kdevplatform/shell/textdocument.cpp @@ -583,29 +583,6 @@ return widget; } -QString KDevelop::TextView::viewState() const -{ - if (d->view) { - if (d->view->selection()) { - KTextEditor::Range selection = d->view->selectionRange(); - return QStringLiteral("Selection=%1,%2,%3,%4").arg(selection.start().line()) - .arg(selection.start().column()) - .arg(selection.end().line()) - .arg(selection.end().column()); - } else { - KTextEditor::Cursor cursor = d->view->cursorPosition(); - return QStringLiteral("Cursor=%1,%2").arg(cursor.line()).arg(cursor.column()); - } - } - else { - KTextEditor::Range selection = d->initialRange; - return QStringLiteral("Selection=%1,%2,%3,%4").arg(selection.start().line()) - .arg(selection.start().column()) - .arg(selection.end().line()) - .arg(selection.end().column()); - } -} - void KDevelop::TextView::setInitialRange(const KTextEditor::Range& range) { if (d->view) { @@ -620,16 +597,20 @@ return d->initialRange; } -void KDevelop::TextView::setState(const QString & state) +void KDevelop::TextView::readSessionConfig(KConfigGroup& config) { - static QRegExp reCursor(QStringLiteral("Cursor=([\\d]+),([\\d]+)")); - static QRegExp reSelection(QStringLiteral("Selection=([\\d]+),([\\d]+),([\\d]+),([\\d]+)")); - if (reCursor.exactMatch(state)) { - setInitialRange(KTextEditor::Range(KTextEditor::Cursor(reCursor.cap(1).toInt(), reCursor.cap(2).toInt()), 0)); - } else if (reSelection.exactMatch(state)) { - KTextEditor::Range range(reSelection.cap(1).toInt(), reSelection.cap(2).toInt(), reSelection.cap(3).toInt(), reSelection.cap(4).toInt()); - setInitialRange(range); + if (!d->view) { + return; + } + d->view->readSessionConfig(config); +} + +void KDevelop::TextView::writeSessionConfig(KConfigGroup& config) +{ + if (!d->view) { + return; } + d->view->writeSessionConfig(config); } QString KDevelop::TextDocument::documentType() const diff --git a/kdevplatform/shell/workingsets/workingset.cpp b/kdevplatform/shell/workingsets/workingset.cpp --- a/kdevplatform/shell/workingsets/workingset.cpp +++ b/kdevplatform/shell/workingsets/workingset.cpp @@ -147,7 +147,8 @@ setGroup.writeEntry(QStringLiteral("View %1").arg(index), docSpec); //The area specific config stores the working set documents in order along with their state areaGroup.writeEntry(QStringLiteral("View %1").arg(index), docSpec); - areaGroup.writeEntry(QStringLiteral("View %1 State").arg(index), view->viewState()); + KConfigGroup viewGroup(&areaGroup, QStringLiteral("View %1 Config").arg(index)); + view->writeSessionConfig(viewGroup); ++index; } } @@ -339,9 +340,9 @@ //Load state for (int i = 0; i < viewCount; ++i) { - QString state = areaGroup.readEntry(QStringLiteral("View %1 State").arg(i)); - if (!state.isEmpty() && createdViews.contains(i)) - createdViews[i]->setState(state); + KConfigGroup viewGroup(&areaGroup, QStringLiteral("View %1 Config").arg(i)); + if (viewGroup.exists() && createdViews.contains(i)) + createdViews[i]->readSessionConfig(viewGroup); } } } diff --git a/kdevplatform/sublime/view.h b/kdevplatform/sublime/view.h --- a/kdevplatform/sublime/view.h +++ b/kdevplatform/sublime/view.h @@ -24,6 +24,8 @@ #include "sublimeexport.h" +class KConfigGroup; + class QAction; namespace Sublime { @@ -68,10 +70,22 @@ /// Retrieve information to be placed in the status bar. virtual QString viewStatus() const; - /// Retrieve view state for saving into configuration. - virtual QString viewState() const; - /// Restore view state from configuration - virtual void setState(const QString& state); + /** + * Read session settings from the given \p config. + * + * The default implementation is a no-op + * + * @see KTextEditor::View::readSessionConfig() + */ + virtual void readSessionConfig(KConfigGroup &config); + /** + * Write session settings to the \p config. + * + * The default implementation is a no-op + * + * @see KTextEditor::View::writeSessionConfig() + */ + virtual void writeSessionConfig(KConfigGroup &config); void notifyPositionChanged(int newPositionInArea); diff --git a/kdevplatform/sublime/view.cpp b/kdevplatform/sublime/view.cpp --- a/kdevplatform/sublime/view.cpp +++ b/kdevplatform/sublime/view.cpp @@ -94,14 +94,14 @@ emit raise(this); } -QString View::viewState() const +void View::readSessionConfig(KConfigGroup& config) { - return QString(); + Q_UNUSED(config); } -void View::setState(const QString & state) +void View::writeSessionConfig(KConfigGroup& config) { - Q_UNUSED(state); + Q_UNUSED(config); } QList View::toolBarActions() const