| 357 | } |
| 358 | |
| 359 | void PatchReviewToolView::open( const QUrl& url, bool activate ) const |
| 360 | { |
| 361 | qCDebug(PLUGIN_PATCHREVIEW) << "activating url" << url; |
| 362 | // If the document is already open in this area, just re-activate it |
| 363 | if(KDevelop::IDocument* doc = ICore::self()->documentController()->documentForUrl(url)) { |
| 364 | const auto views = ICore::self()->uiController()->activeArea()->views(); |
| 365 | for (Sublime::View* view : views) { |
| 366 | if(view->document() == dynamic_cast<Sublime::Document*>(doc)) |
| 367 | { |
| 368 | if (activate) { |
| 369 | // use openDocument() for the activation so that the document is added to File/Open Recent. |
| 370 | ICore::self()->documentController()->openDocument(doc->url(), KTextEditor::Range::invalid()); |
| 371 | } |
| 372 | return; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | QStandardItem* item = m_fileModel->itemForUrl( url ); |
| 378 | |
| 379 | IDocument* buddyDoc = nullptr; |
| 380 | |
| 381 | if (m_plugin->patch() && item) { |
| 382 | for (int preRow = item->row() - 1; preRow >= 0; --preRow) { |
| 383 | QStandardItem* preItem = m_fileModel->item(preRow); |
| 384 | if (!m_fileModel->isCheckable() || preItem->checkState() == Qt::Checked) { |
| 385 | // found valid predecessor, take it as buddy |
| 386 | buddyDoc = ICore::self()->documentController()->documentForUrl(preItem->index().data(VcsFileChangesModel::UrlRole).toUrl()); |
| 387 | if (buddyDoc) { |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | if (!buddyDoc) { |
| 393 | buddyDoc = ICore::self()->documentController()->documentForUrl(m_plugin->patch()->file()); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // we simplify and assume that documents to be opened without activating them also need not be |
| 398 | // added to the Files/Open Recent menu. |
| 399 | IDocument* newDoc = ICore::self()->documentController()->openDocument(url, KTextEditor::Range::invalid(), |
| 400 | activate ? IDocumentController::DefaultMode : IDocumentController::DoNotActivate|IDocumentController::DoNotAddToRecentOpen, |
| 401 | QString(), buddyDoc); |
| 402 | |
| 403 | KTextEditor::View* view = nullptr; |
| 404 | if(newDoc) |
| 405 | view = newDoc->activeTextView(); |
| 406 | |
| 407 | if(view && view->cursorPosition().line() == 0) |
| 408 | m_plugin->seekHunk( true, url ); |
| 409 | } |
| 410 | |
| 411 | void PatchReviewToolView::fileItemChanged( QStandardItem* item ) |
| 412 | { |