| 339 | } |
| 340 | |
| 341 | QVariantList FileMentionItem::getOpenFiles(const QString &query) |
| 342 | { |
| 343 | QVariantList results; |
| 344 | const QString lowerQuery = query.toLower(); |
| 345 | const bool emptyQuery = query.isEmpty(); |
| 346 | QSet<QString> addedPaths; |
| 347 | |
| 348 | auto tryAddDocument = [&](Core::IDocument *document) { |
| 349 | if (!document) |
| 350 | return; |
| 351 | |
| 352 | const QString absolutePath = document->filePath().toFSPathString(); |
| 353 | if (absolutePath.isEmpty() || addedPaths.contains(absolutePath)) |
| 354 | return; |
| 355 | |
| 356 | const QFileInfo fileInfo(absolutePath); |
| 357 | const QString fileName = fileInfo.fileName(); |
| 358 | if (fileName.isEmpty()) |
| 359 | return; |
| 360 | |
| 361 | QString relativePath = absolutePath; |
| 362 | QString projectName; |
| 363 | |
| 364 | auto project = ProjectExplorer::ProjectManager::projectForFile(document->filePath()); |
| 365 | if (project) { |
| 366 | projectName = project->displayName(); |
| 367 | relativePath = QDir(project->projectDirectory().path()).relativeFilePath(absolutePath); |
| 368 | } |
| 369 | |
| 370 | if (!emptyQuery) { |
| 371 | const QString lowerFileName = fileName.toLower(); |
| 372 | const QString lowerRelativePath = relativePath.toLower(); |
| 373 | if (!lowerFileName.contains(lowerQuery) && !lowerRelativePath.contains(lowerQuery)) |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | addedPaths.insert(absolutePath); |
| 378 | |
| 379 | QVariantMap item; |
| 380 | item["absolutePath"] = absolutePath; |
| 381 | item["relativePath"] = relativePath; |
| 382 | item["projectName"] = projectName; |
| 383 | item["isProject"] = false; |
| 384 | item["isOpen"] = true; |
| 385 | results.append(item); |
| 386 | }; |
| 387 | |
| 388 | if (auto current = Core::EditorManager::currentEditor()) |
| 389 | tryAddDocument(current->document()); |
| 390 | |
| 391 | for (auto editor : Core::EditorManager::visibleEditors()) |
| 392 | if (editor) |
| 393 | tryAddDocument(editor->document()); |
| 394 | |
| 395 | for (auto document : Core::DocumentModel::openedDocuments()) |
| 396 | tryAddDocument(document); |
| 397 | |
| 398 | return results; |