Commit 4b807bb7 authored by Daniel Teske's avatar Daniel Teske Committed by David Schulz

CurrentProjectFind: Correct enabled/disable logic

Task-number: QTCREATORBUG-8556

Change-Id: Ic542ac518656e2edf9c3cb17b2960238aa467a9d
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent ea0d68f7
......@@ -116,6 +116,7 @@ signals:
void visibilityChanged(bool visible);
void countChanged(int count);
void searchAgainRequested();
void requestEnabledCheck();
private:
SearchResult(Internal::SearchResultWidget *widget);
......
......@@ -52,6 +52,10 @@ CurrentProjectFind::CurrentProjectFind(ProjectExplorerPlugin *plugin)
{
connect(m_plugin, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
connect(m_plugin->session(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
connect(m_plugin->session(), SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
}
QString CurrentProjectFind::id() const
......@@ -101,6 +105,22 @@ void CurrentProjectFind::handleProjectChanged()
emit enabledChanged(isEnabled());
}
void CurrentProjectFind::recheckEnabled()
{
SearchResult *search = qobject_cast<SearchResult *>(sender());
if (!search)
return;
QString projectFile = getAdditionalParameters(search).toString();
QList<Project *> allProjects = m_plugin->session()->projects();
foreach (Project *project, allProjects) {
if (project->document() && projectFile == project->document()->fileName()) {
search->setSearchAgainEnabled(true);
return;
}
}
search->setSearchAgainEnabled(false);
}
void CurrentProjectFind::writeSettings(QSettings *settings)
{
settings->beginGroup(QLatin1String("CurrentProjectFind"));
......
......@@ -66,6 +66,7 @@ protected:
private slots:
void handleProjectChanged();
void recheckEnabled();
private:
ProjectExplorerPlugin *m_plugin;
......
......@@ -137,7 +137,9 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags,
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool)));
connect(this, SIGNAL(enabledChanged(bool)), search, SIGNAL(requestEnabledCheck()));
connect(search, SIGNAL(requestEnabledCheck()), this, SLOT(recheckEnabled()));
runSearch(search);
}
......@@ -329,6 +331,14 @@ void BaseFileFind::searchAgain()
runSearch(search);
}
void BaseFileFind::recheckEnabled()
{
SearchResult *search = qobject_cast<SearchResult *>(sender());
if (!search)
return;
search->setSearchAgainEnabled(isEnabled());
}
QStringList BaseFileFind::replaceAll(const QString &text,
const QList<Find::SearchResultItem> &items,
bool preserveCase)
......@@ -380,6 +390,11 @@ QStringList BaseFileFind::replaceAll(const QString &text,
return changes.keys();
}
QVariant BaseFileFind::getAdditionalParameters(SearchResult *search)
{
return search->userData().value<FileFindParameters>().additionalParameters;
}
CountingLabel::CountingLabel()
{
setAlignment(Qt::AlignCenter);
......
......@@ -78,6 +78,7 @@ protected:
virtual Utils::FileIterator *files(const QStringList &nameFilters,
const QVariant &additionalParameters) const = 0;
virtual QVariant additionalParameters() const = 0;
QVariant getAdditionalParameters(Find::SearchResult *search);
virtual QString label() const = 0; // see Find::SearchResultWindow::startNewSearch
virtual QString toolTip() const = 0; // see Find::SearchResultWindow::startNewSearch,
// add %1 placeholder where the find flags should be put
......@@ -100,6 +101,7 @@ private slots:
bool preserveCase);
void hideHighlightAll(bool visible);
void searchAgain();
void recheckEnabled();
private:
void runNewSearch(const QString &txt, Find::FindFlags findFlags,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment