Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/shell/textdocument.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | 142 | if(document && document->url().isValid()) { | |||
---|---|---|---|---|---|
151 | while(documents.size() >= MAX_DOC_SETTINGS) { | 151 | while(documents.size() >= MAX_DOC_SETTINGS) { | ||
152 | katePartSettings.group(documents.takeFirst()).deleteGroup(); | 152 | katePartSettings.group(documents.takeFirst()).deleteGroup(); | ||
153 | } | 153 | } | ||
154 | // update order | 154 | // update order | ||
155 | katePartSettings.writeEntry("documents", documents); | 155 | katePartSettings.writeEntry("documents", documents); | ||
156 | 156 | | |||
157 | // actually save session config | 157 | // actually save session config | ||
158 | KConfigGroup group = docConfigGroup(); | 158 | KConfigGroup group = docConfigGroup(); | ||
159 | document->writeSessionConfig(group); | 159 | document->writeSessionConfig(group); | ||
mwolff: what about this code? | |||||
160 | } | 160 | } | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | void loadSessionConfig() | 163 | void loadSessionConfig() | ||
164 | { | 164 | { | ||
165 | if (!document || !katePartSettingsGroup().hasGroup(docConfigGroupName())) { | 165 | if (!document || !katePartSettingsGroup().hasGroup(docConfigGroupName())) { | ||
166 | return; | 166 | return; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | document->readSessionConfig(docConfigGroup(), {QStringLiteral("SkipUrl")}); | 169 | document->readSessionConfig(docConfigGroup(), {QStringLiteral("SkipUrl")}); | ||
mwolff: dito | |||||
170 | } | 170 | } | ||
171 | 171 | | |||
172 | // Determines whether the current contents of this document in the editor | 172 | // Determines whether the current contents of this document in the editor | ||
173 | // could be retrieved from the VCS if they were dismissed. | 173 | // could be retrieved from the VCS if they were dismissed. | ||
174 | void queryCanRecreateFromVcs(KTextEditor::Document* document) const { | 174 | void queryCanRecreateFromVcs(KTextEditor::Document* document) const { | ||
175 | IProject* project = nullptr; | 175 | IProject* project = nullptr; | ||
176 | // Find projects by checking which one contains the file's parent directory, | 176 | // Find projects by checking which one contains the file's parent directory, | ||
177 | // to avoid issues with the cmake manager temporarily removing files from a project | 177 | // to avoid issues with the cmake manager temporarily removing files from a project | ||
▲ Show 20 Lines • Show All 400 Lines • ▼ Show 20 Line(s) | 576 | { | |||
578 | Q_ASSERT(textDocument); | 578 | Q_ASSERT(textDocument); | ||
579 | QWidget* widget = textDocument->createViewWidget(parent); | 579 | QWidget* widget = textDocument->createViewWidget(parent); | ||
580 | d->view = qobject_cast<KTextEditor::View*>(widget); | 580 | d->view = qobject_cast<KTextEditor::View*>(widget); | ||
581 | Q_ASSERT(d->view); | 581 | Q_ASSERT(d->view); | ||
582 | connect(d->view.data(), &KTextEditor::View::cursorPositionChanged, this, &KDevelop::TextView::sendStatusChanged); | 582 | connect(d->view.data(), &KTextEditor::View::cursorPositionChanged, this, &KDevelop::TextView::sendStatusChanged); | ||
583 | return widget; | 583 | return widget; | ||
584 | } | 584 | } | ||
585 | 585 | | |||
586 | QString KDevelop::TextView::viewState() const | | |||
587 | { | | |||
588 | if (d->view) { | | |||
589 | if (d->view->selection()) { | | |||
590 | KTextEditor::Range selection = d->view->selectionRange(); | | |||
591 | return QStringLiteral("Selection=%1,%2,%3,%4").arg(selection.start().line()) | | |||
592 | .arg(selection.start().column()) | | |||
593 | .arg(selection.end().line()) | | |||
594 | .arg(selection.end().column()); | | |||
595 | } else { | | |||
596 | KTextEditor::Cursor cursor = d->view->cursorPosition(); | | |||
597 | return QStringLiteral("Cursor=%1,%2").arg(cursor.line()).arg(cursor.column()); | | |||
598 | } | | |||
599 | } | | |||
600 | else { | | |||
601 | KTextEditor::Range selection = d->initialRange; | | |||
602 | return QStringLiteral("Selection=%1,%2,%3,%4").arg(selection.start().line()) | | |||
603 | .arg(selection.start().column()) | | |||
604 | .arg(selection.end().line()) | | |||
605 | .arg(selection.end().column()); | | |||
606 | } | | |||
607 | } | | |||
608 | | ||||
609 | void KDevelop::TextView::setInitialRange(const KTextEditor::Range& range) | 586 | void KDevelop::TextView::setInitialRange(const KTextEditor::Range& range) | ||
610 | { | 587 | { | ||
611 | if (d->view) { | 588 | if (d->view) { | ||
612 | selectAndReveal(d->view, range); | 589 | selectAndReveal(d->view, range); | ||
613 | } else { | 590 | } else { | ||
614 | d->initialRange = range; | 591 | d->initialRange = range; | ||
615 | } | 592 | } | ||
616 | } | 593 | } | ||
617 | 594 | | |||
618 | KTextEditor::Range KDevelop::TextView::initialRange() const | 595 | KTextEditor::Range KDevelop::TextView::initialRange() const | ||
619 | { | 596 | { | ||
620 | return d->initialRange; | 597 | return d->initialRange; | ||
621 | } | 598 | } | ||
622 | 599 | | |||
623 | void KDevelop::TextView::setState(const QString & state) | 600 | void KDevelop::TextView::readSessionConfig(KConfigGroup& config) | ||
624 | { | 601 | { | ||
625 | static QRegExp reCursor(QStringLiteral("Cursor=([\\d]+),([\\d]+)")); | 602 | if (!d->view) { | ||
626 | static QRegExp reSelection(QStringLiteral("Selection=([\\d]+),([\\d]+),([\\d]+),([\\d]+)")); | 603 | return; | ||
627 | if (reCursor.exactMatch(state)) { | 604 | } | ||
628 | setInitialRange(KTextEditor::Range(KTextEditor::Cursor(reCursor.cap(1).toInt(), reCursor.cap(2).toInt()), 0)); | 605 | d->view->readSessionConfig(config); | ||
629 | } else if (reSelection.exactMatch(state)) { | 606 | } | ||
630 | KTextEditor::Range range(reSelection.cap(1).toInt(), reSelection.cap(2).toInt(), reSelection.cap(3).toInt(), reSelection.cap(4).toInt()); | 607 | | ||
631 | setInitialRange(range); | 608 | void KDevelop::TextView::writeSessionConfig(KConfigGroup& config) | ||
609 | { | ||||
610 | if (!d->view) { | ||||
611 | return; | ||||
632 | } | 612 | } | ||
613 | d->view->writeSessionConfig(config); | ||||
633 | } | 614 | } | ||
634 | 615 | | |||
635 | QString KDevelop::TextDocument::documentType() const | 616 | QString KDevelop::TextDocument::documentType() const | ||
636 | { | 617 | { | ||
637 | return QStringLiteral("Text"); | 618 | return QStringLiteral("Text"); | ||
638 | } | 619 | } | ||
639 | 620 | | |||
640 | QIcon KDevelop::TextDocument::defaultIcon() const | 621 | QIcon KDevelop::TextDocument::defaultIcon() const | ||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |
what about this code?