| 273 | } |
| 274 | |
| 275 | QWidget *TextDocument::createViewWidget(QWidget *parent) |
| 276 | { |
| 277 | Q_D(TextDocument); |
| 278 | |
| 279 | KTextEditor::View* view = nullptr; |
| 280 | |
| 281 | if (!d->document) |
| 282 | { |
| 283 | d->document = Core::self()->partControllerInternal()->createTextPart(); |
| 284 | |
| 285 | // Connect to the first text changed signal, it occurs before the completed() signal |
| 286 | connect(d->document.data(), &KTextEditor::Document::textChanged, this, &TextDocument::slotDocumentLoaded); |
| 287 | // Also connect to the completed signal, sometimes the first text changed signal is missed because the part loads too quickly (? TODO - confirm this is necessary) |
| 288 | connect(d->document.data(), QOverload<>::of(&KTextEditor::Document::completed), |
| 289 | this, &TextDocument::slotDocumentLoaded); |
| 290 | |
| 291 | // force a reparse when a document gets reloaded |
| 292 | connect(d->document.data(), &KTextEditor::Document::reloaded, |
| 293 | this, [] (KTextEditor::Document* document) { |
| 294 | ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(document->url()), |
| 295 | TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::ForceUpdate, |
| 296 | BackgroundParser::BestPriority, nullptr); |
| 297 | }); |
| 298 | |
| 299 | // Set encoding passed via constructor |
| 300 | // Needs to be done before openUrl, else katepart won't use the encoding |
| 301 | // @see KTextEditor::Document::setEncoding |
| 302 | if (!d->encoding.isEmpty()) |
| 303 | d->document->setEncoding(d->encoding); |
| 304 | |
| 305 | if (!url().isEmpty() && !DocumentController::isEmptyDocumentUrl(url())) |
| 306 | d->document->openUrl( url() ); |
| 307 | |
| 308 | d->setStatus(d->document, false); |
| 309 | |
| 310 | /* It appears, that by default a part will be deleted the |
| 311 | first view containing it is deleted. Since we do want |
| 312 | to have several views, disable that behaviour. */ |
| 313 | d->document->setAutoDeletePart(false); |
| 314 | |
| 315 | Core::self()->partController()->addPart(d->document, false); |
| 316 | |
| 317 | d->loadSessionConfig(); |
| 318 | |
| 319 | connect(d->document.data(), &KTextEditor::Document::modifiedChanged, |
| 320 | this, &TextDocument::newDocumentStatus); |
| 321 | connect(d->document.data(), &KTextEditor::Document::textChanged, |
| 322 | this, &TextDocument::textChanged); |
| 323 | connect(d->document.data(), &KTextEditor::Document::documentUrlChanged, |
| 324 | this, &TextDocument::documentUrlChanged); |
| 325 | connect(d->document.data(), &KTextEditor::Document::documentSavedOrUploaded, |
| 326 | this, &TextDocument::documentSaved ); |
| 327 | |
| 328 | connect(d->document.data(), &KTextEditor::Document::marksChanged, this, [d] { |
| 329 | d->saveSessionConfig(); |
| 330 | }); |
| 331 | |
| 332 | d->document->setModifiedOnDiskWarning(true); |
no test coverage detected