forked from qt-creator/qt-creator
BaseFileFind: Get rid of getAdditionalParameters()
Remove recheckEnabled() and introduce setupSearch() virtual method. The latter is called just once per SearchResult instance (on first search), so we may store the additional parameter (current project file path) in lambda capture. Change-Id: I7683e818bec8f1d787bdb33c573248b252b47c78 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -83,16 +83,20 @@ void CurrentProjectFind::handleProjectChanged()
|
|||||||
emit displayNameChanged();
|
emit displayNameChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurrentProjectFind::recheckEnabled(Core::SearchResult *search)
|
void CurrentProjectFind::setupSearch(Core::SearchResult *search)
|
||||||
{
|
{
|
||||||
const FilePath projectFile = FilePath::fromVariant(getAdditionalParameters(search));
|
Project *project = ProjectTree::currentProject();
|
||||||
for (Project *project : ProjectManager::projects()) {
|
const FilePath projectFile = project ? project->projectFilePath() : FilePath();
|
||||||
|
connect(this, &IFindFilter::enabledChanged, search, [search, projectFile] {
|
||||||
|
const QList<Project *> projects = ProjectManager::projects();
|
||||||
|
for (Project *project : projects) {
|
||||||
if (projectFile == project->projectFilePath()) {
|
if (projectFile == project->projectFilePath()) {
|
||||||
search->setSearchAgainEnabled(true);
|
search->setSearchAgainEnabled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
search->setSearchAgainEnabled(false);
|
search->setSearchAgainEnabled(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurrentProjectFind::writeSettings(QSettings *settings)
|
void CurrentProjectFind::writeSettings(QSettings *settings)
|
||||||
|
@@ -35,7 +35,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void handleProjectChanged();
|
void handleProjectChanged();
|
||||||
void recheckEnabled(Core::SearchResult *search) override;
|
void setupSearch(Core::SearchResult *search) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -313,6 +313,7 @@ void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
|||||||
tooltip.arg(IFindFilter::descriptionForFindFlags(findFlags)),
|
tooltip.arg(IFindFilter::descriptionForFindFlags(findFlags)),
|
||||||
txt, searchMode, SearchResultWindow::PreserveCaseEnabled,
|
txt, searchMode, SearchResultWindow::PreserveCaseEnabled,
|
||||||
QString::fromLatin1("TextEditor"));
|
QString::fromLatin1("TextEditor"));
|
||||||
|
setupSearch(search);
|
||||||
search->setTextToReplace(txt);
|
search->setTextToReplace(txt);
|
||||||
search->setSearchAgainSupported(true);
|
search->setSearchAgainSupported(true);
|
||||||
FileFindParameters parameters;
|
FileFindParameters parameters;
|
||||||
@@ -333,9 +334,6 @@ void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
|||||||
connect(search, &SearchResult::searchAgainRequested, this, [this, search] {
|
connect(search, &SearchResult::searchAgainRequested, this, [this, search] {
|
||||||
searchAgain(search);
|
searchAgain(search);
|
||||||
});
|
});
|
||||||
connect(this, &BaseFileFind::enabledChanged, search, [this, search] {
|
|
||||||
recheckEnabled(search);
|
|
||||||
});
|
|
||||||
|
|
||||||
runSearch(search);
|
runSearch(search);
|
||||||
}
|
}
|
||||||
@@ -525,11 +523,11 @@ void BaseFileFind::searchAgain(SearchResult *search)
|
|||||||
runSearch(search);
|
runSearch(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFileFind::recheckEnabled(SearchResult *search)
|
void BaseFileFind::setupSearch(SearchResult *search)
|
||||||
{
|
{
|
||||||
if (!search)
|
connect(this, &IFindFilter::enabledChanged, search, [this, search] {
|
||||||
return;
|
|
||||||
search->setSearchAgainEnabled(isEnabled());
|
search->setSearchAgainEnabled(isEnabled());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems &items,
|
FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems &items,
|
||||||
@@ -600,11 +598,6 @@ FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems
|
|||||||
return changes.keys();
|
return changes.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BaseFileFind::getAdditionalParameters(SearchResult *search)
|
|
||||||
{
|
|
||||||
return search->userData().value<FileFindParameters>().additionalParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<SearchResultItems> BaseFileFind::executeSearch(const FileFindParameters ¶meters)
|
QFuture<SearchResultItems> BaseFileFind::executeSearch(const FileFindParameters ¶meters)
|
||||||
{
|
{
|
||||||
return d->m_searchEngines[parameters.searchEngineIndex]->executeSearch(parameters, this);
|
return d->m_searchEngines[parameters.searchEngineIndex]->executeSearch(parameters, this);
|
||||||
|
@@ -101,7 +101,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QVariant additionalParameters() const = 0;
|
virtual QVariant additionalParameters() const = 0;
|
||||||
static QVariant getAdditionalParameters(Core::SearchResult *search);
|
|
||||||
virtual QString label() const = 0; // see Core::SearchResultWindow::startNewSearch
|
virtual QString label() const = 0; // see Core::SearchResultWindow::startNewSearch
|
||||||
virtual QString toolTip() const = 0; // see Core::SearchResultWindow::startNewSearch,
|
virtual QString toolTip() const = 0; // see Core::SearchResultWindow::startNewSearch,
|
||||||
// add %1 placeholder where the find flags should be put
|
// add %1 placeholder where the find flags should be put
|
||||||
@@ -126,7 +125,7 @@ private:
|
|||||||
void doReplace(const QString &txt, const Utils::SearchResultItems &items, bool preserveCase);
|
void doReplace(const QString &txt, const Utils::SearchResultItems &items, bool preserveCase);
|
||||||
void hideHighlightAll(bool visible);
|
void hideHighlightAll(bool visible);
|
||||||
void searchAgain(Core::SearchResult *search);
|
void searchAgain(Core::SearchResult *search);
|
||||||
virtual void recheckEnabled(Core::SearchResult *search);
|
virtual void setupSearch(Core::SearchResult *search);
|
||||||
|
|
||||||
void runNewSearch(const QString &txt, Utils::FindFlags findFlags,
|
void runNewSearch(const QString &txt, Utils::FindFlags findFlags,
|
||||||
Core::SearchResultWindow::SearchMode searchMode);
|
Core::SearchResultWindow::SearchMode searchMode);
|
||||||
|
Reference in New Issue
Block a user