| 567 | } |
| 568 | |
| 569 | void GrepDialog::startSearch() |
| 570 | { |
| 571 | // if m_show is false, all settings are fixed in m_settings |
| 572 | if (m_show) |
| 573 | updateSettings(); |
| 574 | |
| 575 | const QStringList include = GrepFindFilesThread::parseInclude(m_settings.files); |
| 576 | const QStringList exclude = GrepFindFilesThread::parseExclude(m_settings.exclude); |
| 577 | |
| 578 | // search for unsaved documents |
| 579 | QList<IDocument*> unsavedFiles; |
| 580 | const auto documents = ICore::self()->documentController()->openDocuments(); |
| 581 | for (IDocument* doc : documents) { |
| 582 | QUrl docUrl = doc->url(); |
| 583 | if (doc->state() != IDocument::Clean && |
| 584 | isPartOfChoice(docUrl) && |
| 585 | QDir::match(include, docUrl.fileName()) && |
| 586 | !WildcardHelpers::match(exclude, docUrl.toLocalFile()) |
| 587 | ) { |
| 588 | unsavedFiles << doc; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if(!ICore::self()->documentController()->saveSomeDocuments(unsavedFiles)) |
| 593 | { |
| 594 | close(); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | const QString descriptionOrUrl(m_settings.searchPaths); |
| 599 | QList<QUrl> choice = getDirectoryChoice(descriptionOrUrl); |
| 600 | QString description = descriptionOrUrl; |
| 601 | |
| 602 | // Shorten the description |
| 603 | if(descriptionOrUrl != allOpenFilesString() && descriptionOrUrl != allOpenProjectsString()) { |
| 604 | auto prettyFileName = [](const QUrl& url) { |
| 605 | return ICore::self()->projectController()->prettyFileName(url, KDevelop::IProjectController::FormatPlain); |
| 606 | }; |
| 607 | |
| 608 | if (choice.size() > 1) { |
| 609 | description = i18np("%2, and %1 more item", "%2, and %1 more items", choice.size() - 1, prettyFileName(choice[0])); |
| 610 | } else if (!choice.isEmpty()) { |
| 611 | description = prettyFileName(choice[0]); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | GrepOutputView* toolView = m_toolView; |
| 616 | if (!toolView) { |
| 617 | toolView = static_cast<GrepOutputView*>(ICore::self()->uiController()->findToolView( |
| 618 | i18nc("@title:window", "Find/Replace in Files"), m_plugin->toolViewFactory(), |
| 619 | m_settings.fromHistory ? IUiController::Create : IUiController::CreateAndRaise)); |
| 620 | Q_ASSERT_X(toolView, Q_FUNC_INFO, "This branch may be taken only after UiController::loadAllAreas() returns."); |
| 621 | } |
| 622 | |
| 623 | if (m_settings.fromHistory) { |
| 624 | // when restored from history, only display the parameters |
| 625 | toolView->renewModel(m_settings, i18nc("@item search result", "Search \"%1\" in %2", m_settings.pattern, description)); |
| 626 | emit m_plugin->grepJobFinished(true); |
nothing calls this directly
no test coverage detected