forked from qt-creator/qt-creator
CMake: Report special utility targets in BuildDirManager::buildTargets
Report special utility targets like "all", "clean" and "install" from the BuildDirManager and update UI accordingly. Change-Id: I01d0dcfa23d5bddc124c8f9ee1040475184c9c1e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "builddirmanager.h"
|
||||
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakebuildstep.h"
|
||||
#include "cmakekitinformation.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
#include "cmaketool.h"
|
||||
@@ -311,14 +312,30 @@ void BuildDirManager::clearCache()
|
||||
forceReparse();
|
||||
}
|
||||
|
||||
static CMakeBuildTarget utilityTarget(const QString &title, const BuildDirManager *bdm)
|
||||
{
|
||||
CMakeBuildTarget target;
|
||||
|
||||
target.title = title;
|
||||
target.targetType = UtilityType;
|
||||
target.workingDirectory = bdm->buildConfiguration()->buildDirectory();
|
||||
target.sourceDirectory = bdm->buildConfiguration()->target()->project()->projectDirectory();
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
QList<CMakeBuildTarget> BuildDirManager::buildTargets() const
|
||||
{
|
||||
QTC_ASSERT(!m_isHandlingError, return {});
|
||||
|
||||
if (!m_reader)
|
||||
return QList<CMakeBuildTarget>();
|
||||
if (m_buildTargets.isEmpty())
|
||||
m_buildTargets = m_reader->buildTargets();
|
||||
if (m_buildTargets.isEmpty()) {
|
||||
m_buildTargets.append(utilityTarget(CMakeBuildStep::allTarget(), this));
|
||||
m_buildTargets.append(utilityTarget(CMakeBuildStep::cleanTarget(), this));
|
||||
m_buildTargets.append(utilityTarget(CMakeBuildStep::installTarget(), this));
|
||||
m_buildTargets.append(m_reader->buildTargets());
|
||||
}
|
||||
return m_buildTargets;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ public:
|
||||
static CMakeConfig parseConfiguration(const Utils::FileName &cacheFile,
|
||||
QString *errorMessage);
|
||||
|
||||
CMakeBuildConfiguration *buildConfiguration() const { return m_buildConfiguration; }
|
||||
|
||||
signals:
|
||||
void configurationStarted() const;
|
||||
void dataAvailable() const;
|
||||
|
||||
@@ -461,29 +461,21 @@ QString CMakeBuildStepConfigWidget::displayName() const
|
||||
return tr("Build", "CMakeProjectManager::CMakeBuildStepConfigWidget display name.");
|
||||
}
|
||||
|
||||
static void createSpecialItem(const QString &text, const QString &data, QListWidget *parent)
|
||||
{
|
||||
auto item = new QListWidgetItem(text, parent);
|
||||
|
||||
item->setData(Qt::UserRole, data);
|
||||
QFont f;
|
||||
f.setItalic(true);
|
||||
item->setFont(f);
|
||||
}
|
||||
|
||||
void CMakeBuildStepConfigWidget::buildTargetsChanged()
|
||||
{
|
||||
const bool wasBlocked = m_buildTargetsList->blockSignals(true);
|
||||
m_buildTargetsList->clear();
|
||||
|
||||
createSpecialItem(tr(ADD_RUNCONFIGURATION_TEXT), ADD_RUNCONFIGURATION_TEXT, m_buildTargetsList);
|
||||
createSpecialItem(tr("all"), "all", m_buildTargetsList);
|
||||
createSpecialItem(tr("clean"), "clean", m_buildTargetsList);
|
||||
|
||||
auto pro = static_cast<CMakeProject *>(m_buildStep->project());
|
||||
QStringList targetList = pro->buildTargetTitles();
|
||||
targetList.sort();
|
||||
|
||||
QFont italics;
|
||||
italics.setItalic(true);
|
||||
|
||||
auto exeItem = new QListWidgetItem(tr(ADD_RUNCONFIGURATION_TEXT), m_buildTargetsList);
|
||||
exeItem->setData(Qt::UserRole, ADD_RUNCONFIGURATION_TEXT);
|
||||
|
||||
foreach (const QString &buildTarget, targetList) {
|
||||
auto item = new QListWidgetItem(buildTarget, m_buildTargetsList);
|
||||
item->setData(Qt::UserRole, buildTarget);
|
||||
@@ -491,9 +483,14 @@ void CMakeBuildStepConfigWidget::buildTargetsChanged()
|
||||
|
||||
for (int i = 0; i < m_buildTargetsList->count(); ++i) {
|
||||
QListWidgetItem *item = m_buildTargetsList->item(i);
|
||||
const QString title = item->data(Qt::UserRole).toString();
|
||||
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(m_buildStep->buildsBuildTarget(item->data(Qt::UserRole).toString())
|
||||
? Qt::Checked : Qt::Unchecked);
|
||||
item->setCheckState(m_buildStep->buildsBuildTarget(title) ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
// Print utility targets in italics:
|
||||
if (CMakeBuildStep::specialTargets().contains(title) || title == ADD_RUNCONFIGURATION_TEXT)
|
||||
item->setFont(italics);
|
||||
}
|
||||
m_buildTargetsList->blockSignals(wasBlocked);
|
||||
updateSummary();
|
||||
|
||||
Reference in New Issue
Block a user