| 231 | } |
| 232 | |
| 233 | void GrepOutputModel::activate( const QModelIndex &idx ) |
| 234 | { |
| 235 | QStandardItem *stditem = itemFromIndex(idx); |
| 236 | auto *grepitem = dynamic_cast<GrepOutputItem*>(stditem); |
| 237 | if( !grepitem || !grepitem->isText() ) |
| 238 | return; |
| 239 | |
| 240 | QUrl url = QUrl::fromLocalFile(grepitem->filename()); |
| 241 | |
| 242 | int line = grepitem->lineNumber() - 1; |
| 243 | KTextEditor::Range range( line, 0, line+1, 0); |
| 244 | |
| 245 | // Try to find the actual text range we found during the grep |
| 246 | IDocument* doc = ICore::self()->documentController()->documentForUrl( url ); |
| 247 | if(!doc) |
| 248 | doc = ICore::self()->documentController()->openDocument( url, range ); |
| 249 | if(!doc) |
| 250 | return; |
| 251 | if (KTextEditor::Document* tdoc = doc->textDocument()) { |
| 252 | KTextEditor::Range matchRange = grepitem->change()->m_range; |
| 253 | QString actualText = tdoc->text(matchRange); |
| 254 | QString expectedText = grepitem->change()->m_oldText; |
| 255 | if (actualText == expectedText) { |
| 256 | range = matchRange; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | ICore::self()->documentController()->activateDocument( doc, range ); |
| 261 | } |
| 262 | |
| 263 | QModelIndex GrepOutputModel::previousItemIndex(const QModelIndex ¤tIdx) const |
| 264 | { |
no test coverage detected