CMake: Polish cmakelocatorfilter

Change-Id: I02566f27c57c2531c4c6085dc9c703f379a194f1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2016-09-30 14:23:08 +02:00
parent 87f7ec4ec9
commit a223e59d85
2 changed files with 18 additions and 32 deletions

View File

@@ -35,7 +35,6 @@
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fileutils.h>
using namespace CMakeProjectManager; using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal; using namespace CMakeProjectManager::Internal;
@@ -50,12 +49,12 @@ CMakeLocatorFilter::CMakeLocatorFilter()
setPriority(High); setPriority(High);
connect(SessionManager::instance(), &SessionManager::projectAdded, connect(SessionManager::instance(), &SessionManager::projectAdded,
this, &CMakeLocatorFilter::slotProjectListUpdated); this, &CMakeLocatorFilter::projectListUpdated);
connect(SessionManager::instance(), &SessionManager::projectRemoved, connect(SessionManager::instance(), &SessionManager::projectRemoved,
this, &CMakeLocatorFilter::slotProjectListUpdated); this, &CMakeLocatorFilter::projectListUpdated);
// Initialize the filter // Initialize the filter
slotProjectListUpdated(); projectListUpdated();
} }
void CMakeLocatorFilter::prepareSearch(const QString &entry) void CMakeLocatorFilter::prepareSearch(const QString &entry)
@@ -63,13 +62,13 @@ void CMakeLocatorFilter::prepareSearch(const QString &entry)
m_result.clear(); m_result.clear();
foreach (Project *p, SessionManager::projects()) { foreach (Project *p, SessionManager::projects()) {
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p); CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p);
if (cmakeProject) { if (!cmakeProject)
foreach (const CMakeBuildTarget &ct, cmakeProject->buildTargets()) { continue;
if (ct.title.contains(entry)) { foreach (const CMakeBuildTarget &ct, cmakeProject->buildTargets()) {
Core::LocatorFilterEntry entry(this, ct.title, cmakeProject->projectFilePath().toString()); if (ct.title.contains(entry)) {
entry.extraInfo = FileUtils::shortNativePath(cmakeProject->projectFilePath()); Core::LocatorFilterEntry entry(this, ct.title, cmakeProject->projectFilePath().toString());
m_result.append(entry); entry.extraInfo = FileUtils::shortNativePath(cmakeProject->projectFilePath());
} m_result.append(entry);
} }
} }
} }
@@ -85,18 +84,15 @@ QList<Core::LocatorFilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<
void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection) const void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection) const
{ {
// Get the project containing the target selected // Get the project containing the target selected
CMakeProject *cmakeProject = nullptr; const auto cmakeProject = qobject_cast<CMakeProject *>(
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {
foreach (Project *p, SessionManager::projects()) { return p->projectFilePath().toString() == selection.internalData.toString();
cmakeProject = qobject_cast<CMakeProject *>(p); }));
if (cmakeProject && cmakeProject->projectFilePath().toString() == selection.internalData.toString())
break;
}
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration()) if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
return; return;
// Find the make step // Find the make step
ProjectExplorer::BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration() BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()
->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD); ->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>(); auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
if (!buildStep) if (!buildStep)
@@ -117,16 +113,8 @@ void CMakeLocatorFilter::refresh(QFutureInterface<void> &future)
Q_UNUSED(future) Q_UNUSED(future)
} }
void CMakeLocatorFilter::slotProjectListUpdated() void CMakeLocatorFilter::projectListUpdated()
{ {
CMakeProject *cmakeProject = 0;
foreach (Project *p, SessionManager::projects()) {
cmakeProject = qobject_cast<CMakeProject *>(p);
if (cmakeProject)
break;
}
// Enable the filter if there's at least one CMake project // Enable the filter if there's at least one CMake project
setEnabled(cmakeProject); setEnabled(Utils::contains(SessionManager::projects(), [](Project *p) { return qobject_cast<CMakeProject *>(p); }));
} }

View File

@@ -27,8 +27,6 @@
#include <coreplugin/locator/ilocatorfilter.h> #include <coreplugin/locator/ilocatorfilter.h>
#include <QIcon>
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
@@ -46,7 +44,7 @@ public:
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private: private:
void slotProjectListUpdated(); void projectListUpdated();
QList<Core::LocatorFilterEntry> m_result; QList<Core::LocatorFilterEntry> m_result;
}; };