Commit 616a9b13 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Enable restoring the default names of project configuration items

 * Enable support for this in all ProjectConfiguration items
   (Targets, projects, BCs, DCs, RCs, etc.). This is nicer
   than having custom code in individual configuraiton items.

Reviewed-by: dt
parent b6f1dbee
......@@ -108,7 +108,7 @@ CMakeRunConfiguration::~CMakeRunConfiguration()
void CMakeRunConfiguration::ctor()
{
setDisplayName(m_title);
setDefaultDisplayName(defaultDisplayName());
}
CMakeTarget *CMakeRunConfiguration::cmakeTarget() const
......@@ -205,6 +205,13 @@ bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
return RunConfiguration::fromMap(map);
}
QString CMakeRunConfiguration::defaultDisplayName() const
{
if (m_title.isEmpty())
return tr("Run CMake target");
return m_title + (m_enabled ? "" : tr(" (disabled)"));
}
QWidget *CMakeRunConfiguration::createConfigurationWidget()
{
return new CMakeRunConfigurationWidget(this);
......@@ -302,7 +309,7 @@ void CMakeRunConfiguration::setEnabled(bool b)
return;
m_enabled = b;
emit isEnabledChanged(isEnabled());
setDisplayName(m_title + (m_enabled ? "" : tr(" (disabled)")));
setDefaultDisplayName(defaultDisplayName());
}
bool CMakeRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *bc) const
......
......@@ -97,6 +97,7 @@ private slots:
protected:
CMakeRunConfiguration(CMakeTarget *parent, CMakeRunConfiguration *source);
virtual bool fromMap(const QVariantMap &map);
QString defaultDisplayName() const;
private:
void ctor();
......
......@@ -64,7 +64,7 @@ CMakeTarget::CMakeTarget(CMakeProject *parent) :
m_buildConfigurationFactory(new CMakeBuildConfigurationFactory(this)),
m_deployConfigurationFactory(new ProjectExplorer::DeployConfigurationFactory(this))
{
setDisplayName(displayNameForId(id()));
setDefaultDisplayName(displayNameForId(id()));
setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
connect(parent, SIGNAL(buildTargetsChanged()), SLOT(updateRunConfigurations()));
}
......@@ -100,11 +100,7 @@ QString CMakeTarget::defaultBuildDirectory() const
bool CMakeTarget::fromMap(const QVariantMap &map)
{
if (!Target::fromMap(map))
return false;
setDisplayName(displayNameForId(id()));
return true;
return Target::fromMap(map);
}
void CMakeTarget::updateRunConfigurations()
......@@ -194,7 +190,7 @@ CMakeTarget *CMakeTargetFactory::create(ProjectExplorer::Project *parent, const
// Add default build configuration:
CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t));
bc->setDisplayName("all");
bc->setDefaultDisplayName("all");
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
......
......@@ -85,7 +85,8 @@ MakeStep::MakeStep(BuildStepList *bsl, MakeStep *bs) :
void MakeStep::ctor()
{
m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]");
setDisplayName(tr("Make", "CMakeProjectManager::MakeStep display name."));
//: Default display name for the cmake make step.
setDefaultDisplayName(tr("Make"));
}
MakeStep::~MakeStep()
......
......@@ -52,7 +52,6 @@ const char * const BUILD_DIRECTORY_KEY("GenericProjectManager.GenericBuildConfig
GenericBuildConfiguration::GenericBuildConfiguration(GenericTarget *parent)
: BuildConfiguration(parent, QLatin1String(GENERIC_BC_ID))
{
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericTarget *parent, const QString &id)
......
......@@ -84,8 +84,8 @@ GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildStepList *parent, Generic
void GenericMakeStep::ctor()
{
setDisplayName(QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep",
GENERIC_MS_DISPLAY_NAME));
setDefaultDisplayName(QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep",
GENERIC_MS_DISPLAY_NAME));
}
GenericMakeStep::~GenericMakeStep()
......
......@@ -57,9 +57,8 @@ GenericTarget::GenericTarget(GenericProject *parent) :
m_buildConfigurationFactory(new GenericBuildConfigurationFactory(this)),
m_deployConfigurationFactory(new ProjectExplorer::DeployConfigurationFactory(this))
{
setDisplayName(QApplication::translate("GenericProjectManager::GenericTarget",
GENERIC_DESKTOP_TARGET_DISPLAY_NAME,
"Generic desktop target display name"));
setDefaultDisplayName(QApplication::translate("GenericProjectManager::GenericTarget",
GENERIC_DESKTOP_TARGET_DISPLAY_NAME));
setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
}
......@@ -92,9 +91,6 @@ bool GenericTarget::fromMap(const QVariantMap &map)
if (!Target::fromMap(map))
return false;
setDisplayName(QApplication::translate("GenericProjectManager::GenericTarget",
GENERIC_DESKTOP_TARGET_DISPLAY_NAME,
"Generic desktop target display name"));
return true;
}
......
......@@ -55,11 +55,11 @@ BuildConfiguration::BuildConfiguration(Target *target, const QString &id) :
Q_ASSERT(target);
BuildStepList *bsl = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_BUILD));
//: Display name of the build build step list. Used as part of the labels in the project window.
bsl->setDisplayName(tr("Build"));
bsl->setDefaultDisplayName(tr("Build"));
m_stepLists.append(bsl);
bsl = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_CLEAN));
//: Display name of the clean build step list. Used as part of the labels in the project window.
bsl->setDisplayName(tr("Clean"));
bsl->setDefaultDisplayName(tr("Clean"));
m_stepLists.append(bsl);
}
......@@ -108,9 +108,6 @@ QVariantMap BuildConfiguration::toMap() const
bool BuildConfiguration::fromMap(const QVariantMap &map)
{
if (!ProjectConfiguration::fromMap(map))
return false;
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
m_userEnvironmentChanges = EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
......@@ -133,11 +130,11 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
m_stepLists.append(list);
}
// TODO: We currently assume there to be at least a clean, build and deploy list!
// TODO: We currently assume there to be at least a clean and build list!
Q_ASSERT(knownStepLists().contains(QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_BUILD)));
Q_ASSERT(knownStepLists().contains(QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_CLEAN)));
return true;
return ProjectConfiguration::fromMap(map);
}
Target *BuildConfiguration::target() const
......
......@@ -327,16 +327,18 @@ void BuildSettingsWidget::renameConfiguration()
arg(m_buildConfiguration->displayName()),
QLineEdit::Normal,
m_buildConfiguration->displayName(), &ok);
if (!ok || !this || name.isEmpty())
if (!ok || !this)
return;
QStringList bcNames;
foreach (BuildConfiguration *bc, m_target->buildConfigurations()) {
if (bc == m_buildConfiguration)
continue;
bcNames.append(bc->displayName());
if (!name.isEmpty()) {
QStringList bcNames;
foreach (BuildConfiguration *bc, m_target->buildConfigurations()) {
if (bc == m_buildConfiguration)
continue;
bcNames.append(bc->displayName());
}
name = Project::makeUnique(name, bcNames);
}
name = Project::makeUnique(name, bcNames);
m_buildConfiguration->setDisplayName(name);
}
......@@ -347,15 +349,11 @@ void BuildSettingsWidget::cloneConfiguration(BuildConfiguration *sourceConfigura
!m_target->buildConfigurationFactory())
return;
//: Title of a the cloned BuildConfiguration window, text of the window
QString newDisplayName(QInputDialog::getText(this, tr("Clone configuration"), tr("New Configuration Name:")));
if (newDisplayName.isEmpty())
return;
QStringList buildConfigurationDisplayNames;
foreach(BuildConfiguration *bc, m_target->buildConfigurations())
buildConfigurationDisplayNames << bc->displayName();
newDisplayName = Project::makeUnique(newDisplayName, buildConfigurationDisplayNames);
BuildConfiguration * bc(m_target->buildConfigurationFactory()->clone(m_target, sourceConfiguration));
if (!bc)
return;
......
......@@ -83,7 +83,7 @@ BuildStepList::BuildStepList(QObject *parent, BuildStepList *source) :
}
BuildStepList::BuildStepList(QObject *parent, const QVariantMap &data) :
ProjectConfiguration(parent, QLatin1String("UNKNOWN"))
ProjectConfiguration(parent, QLatin1String("UNKNOWN ID"))
{
Q_ASSERT(parent);
m_isNull = !fromMap(data);
......@@ -144,9 +144,6 @@ void BuildStepList::cloneSteps(BuildStepList *source)
bool BuildStepList::fromMap(const QVariantMap &map)
{
if (!ProjectConfiguration::fromMap(map))
return false;
int maxSteps = map.value(QString::fromLatin1(STEPS_COUNT_KEY), 0).toInt();
for (int i = 0; i < maxSteps; ++i) {
QVariantMap bsData(map.value(QString::fromLatin1(STEPS_PREFIX) + QString::number(i)).toMap());
......@@ -166,7 +163,6 @@ bool BuildStepList::fromMap(const QVariantMap &map)
}
insertStep(m_steps.count(), bs);
}
return ProjectConfiguration::fromMap(map);
}
......@@ -216,6 +212,5 @@ Target *BuildStepList::target() const
DeployConfiguration *dc = qobject_cast<DeployConfiguration *>(parent());
if (dc)
return dc->target();
Q_ASSERT(false);
return 0;
}
......@@ -245,7 +245,8 @@ void CustomExecutableConfigurationWidget::changed()
void CustomExecutableRunConfiguration::ctor()
{
setDisplayName(tr("Run %1").arg(m_executable));
setDefaultDisplayName(defaultDisplayName());
connect(target(), SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(activeBuildConfigurationChanged()));
......@@ -435,6 +436,14 @@ void CustomExecutableRunConfiguration::setUserEnvironmentChanges(const QList<Pro
}
}
QString CustomExecutableRunConfiguration::defaultDisplayName() const
{
if (m_executable.isEmpty())
return tr("Custom Executable");
else
return tr("Run %1").arg(QDir::toNativeSeparators(m_executable));
}
QVariantMap CustomExecutableRunConfiguration::toMap() const
{
QVariantMap map(LocalApplicationRunConfiguration::toMap());
......@@ -456,15 +465,16 @@ bool CustomExecutableRunConfiguration::fromMap(const QVariantMap &map)
m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CustomExecutableRunConfiguration::BuildEnvironmentBase)).toInt());
setDefaultDisplayName(defaultDisplayName());
return RunConfiguration::fromMap(map);
}
void CustomExecutableRunConfiguration::setExecutable(const QString &executable)
{
bool hasUserName = (displayName() != tr("Run %1").arg(m_executable));
if (executable == m_executable)
return;
m_executable = executable;
if (!hasUserName)
setDisplayName(tr("Run %1").arg(m_executable));
setDefaultDisplayName(defaultDisplayName());
emit changed();
}
......
......@@ -87,11 +87,6 @@ public:
*/
QString baseExecutable() const;
/**
* Returns the name the user has set, if he has set one
*/
QString userName() const;
LocalApplicationRunConfiguration::RunMode runMode() const;
QString workingDirectory() const;
QString baseWorkingDirectory() const;
......@@ -118,6 +113,7 @@ private slots:
protected:
CustomExecutableRunConfiguration(Target *parent, CustomExecutableRunConfiguration *source);
virtual bool fromMap(const QVariantMap &map);
QString defaultDisplayName() const;
private:
void ctor();
......
......@@ -52,8 +52,9 @@ DeployConfiguration::DeployConfiguration(Target *target, const QString &id) :
Q_ASSERT(target);
m_stepList = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_DEPLOY));
//: Display name of the deploy build step list. Used as part of the labels in the project window.
m_stepList->setDisplayName(tr("Deploy"));
setDisplayName(tr("No deployment"));
m_stepList->setDefaultDisplayName(tr("Deploy"));
//: Default DeployConfiguration display name
setDefaultDisplayName(tr("No deployment"));
}
DeployConfiguration::DeployConfiguration(Target *target, DeployConfiguration *source) :
......@@ -80,7 +81,6 @@ QVariantMap DeployConfiguration::toMap() const
QVariantMap map(ProjectConfiguration::toMap());
map.insert(QLatin1String(BUILD_STEP_LIST_COUNT), 1);
map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1String("0"), m_stepList->toMap());
return map;
}
......@@ -95,7 +95,8 @@ bool DeployConfiguration::fromMap(const QVariantMap &map)
return false;
int maxI = map.value(QLatin1String(BUILD_STEP_LIST_COUNT), 0).toInt();
Q_ASSERT(maxI == 1);
if (maxI != 1)
return false;
QVariantMap data = map.value(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1String("0")).toMap();
if (!data.isEmpty()) {
m_stepList = new BuildStepList(this, data);
......@@ -105,11 +106,13 @@ bool DeployConfiguration::fromMap(const QVariantMap &map)
m_stepList = 0;
return false;
}
m_stepList->setDefaultDisplayName(tr("Deploy"));
} else {
qWarning() << "No data for deploy step list found!";
return false;
}
// TODO: We assume that we have hold the deploy list
// TODO: We assume that we hold the deploy list
Q_ASSERT(m_stepList && m_stepList->id() == QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY));
return true;
......
......@@ -64,7 +64,6 @@ ProcessStep::ProcessStep(BuildStepList *bsl, const QString &id) :
ProcessStep::ProcessStep(BuildStepList *bsl, ProcessStep *bs) :
AbstractProcessStep(bsl, bs),
m_name(bs->m_name),
m_command(bs->m_command),
m_arguments(bs->m_arguments),
m_workingDirectory(bs->m_workingDirectory),
......@@ -76,7 +75,8 @@ ProcessStep::ProcessStep(BuildStepList *bsl, ProcessStep *bs) :
void ProcessStep::ctor()
{
setDisplayName(tr("Custom Process Step", "item in combobox"));
//: Default ProcessStep display name
setDefaultDisplayName(tr("Custom Process Step"));
}
ProcessStep::~ProcessStep()
......@@ -255,8 +255,6 @@ ProcessStepConfigWidget::ProcessStepConfigWidget(ProcessStep *step)
connect(m_ui.workingDirectory, SIGNAL(changed(QString)),
this, SLOT(workingDirectoryLineEditTextEdited()));
connect(m_ui.nameLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(nameLineEditTextEdited()));
connect(m_ui.commandArgumentsLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(commandArgumentsLineEditTextEdited()));
connect(m_ui.enabledCheckBox, SIGNAL(clicked(bool)),
......@@ -293,7 +291,6 @@ void ProcessStepConfigWidget::init()
m_ui.commandArgumentsLineEdit->setText(m_step->arguments().join(QString(QLatin1Char(' '))));
m_ui.enabledCheckBox->setChecked(m_step->enabled());
m_ui.nameLineEdit->setText(m_step->displayName());
updateDetails();
}
......@@ -302,12 +299,6 @@ QString ProcessStepConfigWidget::summaryText() const
return m_summaryText;
}
void ProcessStepConfigWidget::nameLineEditTextEdited()
{
m_step->setDisplayName(m_ui.nameLineEdit->text());
emit updateDetails();
}
void ProcessStepConfigWidget::commandLineEditTextEdited()
{
m_step->setCommand(m_ui.command->path());
......
......@@ -93,7 +93,6 @@ protected:
private:
void ctor();
QString m_name;
QString m_command;
QStringList m_arguments;
QString m_workingDirectory;
......@@ -110,7 +109,6 @@ public:
virtual void init();
virtual QString summaryText() const;
private slots:
void nameLineEditTextEdited();
void commandLineEditTextEdited();
void workingDirectoryLineEditTextEdited();
void commandArgumentsLineEditTextEdited();
......
......@@ -6,11 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>299</width>
<height>154</height>
<width>290</width>
<height>95</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
......@@ -26,43 +29,33 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="commandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="Utils::PathChooser" name="command" native="true"/>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="workingDirecoryLabel">
<property name="text">
<string>Working directory:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="Utils::PathChooser" name="workingDirectory" native="true"/>
</item>
<item row="4" column="0">
<item row="3" column="0">
<widget class="QLabel" name="commandArgumentsLabel">
<property name="text">
<string>Command arguments:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="commandArgumentsLineEdit"/>
</item>
</layout>
......
......@@ -133,7 +133,7 @@ void Project::addTarget(Target *t)
foreach (const Target *target, m_targets)
displayNames << target->displayName();
targetDisplayName = makeUnique(targetDisplayName, displayNames);
t->setDisplayName(targetDisplayName);
t->setDefaultDisplayName(targetDisplayName);
// add it
m_targets.push_back(t);
......
......@@ -34,6 +34,7 @@ using namespace ProjectExplorer;
namespace {
const char * const CONFIGURATION_ID_KEY("ProjectExplorer.ProjectConfiguration.Id");
const char * const DISPLAY_NAME_KEY("ProjectExplorer.ProjectConfiguration.DisplayName");
const char * const DEFAULT_DISPLAY_NAME_KEY("ProjectExplorer.ProjectConfiguration.DefaultDisplayName");
}
ProjectConfiguration::ProjectConfiguration(QObject *parent, const QString &id) :
......@@ -44,10 +45,11 @@ ProjectConfiguration::ProjectConfiguration(QObject *parent, const QString &id) :
}
ProjectConfiguration::ProjectConfiguration(QObject *parent, const ProjectConfiguration *source) :
QObject(parent)
QObject(parent),
m_id(source->m_id),
m_defaultDisplayName(source->m_defaultDisplayName)
{
Q_ASSERT(source);
m_id = source->m_id;
m_displayName = tr("Clone of %1").arg(source->displayName());
}
......@@ -61,22 +63,35 @@ QString ProjectConfiguration::id() const
QString ProjectConfiguration::displayName() const
{
return m_displayName;
if (!m_displayName.isEmpty())
return m_displayName;
return m_defaultDisplayName;
}
void ProjectConfiguration::setDisplayName(const QString &name)
{
if (name == m_displayName)
if (displayName() == name)
return;
m_displayName = name;
emit displayNameChanged();
}
void ProjectConfiguration::setDefaultDisplayName(const QString &name)
{
if (m_defaultDisplayName == name)
return;
const QString originalName = displayName();
m_defaultDisplayName = name;
if (originalName != displayName())
emit displayNameChanged();
}
QVariantMap ProjectConfiguration::toMap() const
{
QVariantMap map;
map.insert(QLatin1String(CONFIGURATION_ID_KEY), m_id);
map.insert(QLatin1String(DISPLAY_NAME_KEY), m_displayName);
map.insert(QLatin1String(DEFAULT_DISPLAY_NAME_KEY), m_defaultDisplayName);
return map;
}
......@@ -84,6 +99,7 @@ bool ProjectConfiguration::fromMap(const QVariantMap &map)
{
m_id = map.value(QLatin1String(CONFIGURATION_ID_KEY), QString()).toString();
m_displayName = map.value(QLatin1String(DISPLAY_NAME_KEY), QString()).toString();
m_defaultDisplayName = map.value(QLatin1String(DEFAULT_DISPLAY_NAME_KEY), m_displayName).toString();
return !m_id.isEmpty();
}
......
......@@ -51,6 +51,7 @@ public:
QString id() const;
QString displayName() const;
void setDisplayName(const QString &name);
void setDefaultDisplayName(const QString &name);
// Note: Make sure subclasses call the superclasses toMap() method!
virtual QVariantMap toMap() const;
......@@ -70,6 +71,7 @@ private:
QString m_id;
QString m_displayName;
QString m_defaultDisplayName;
};
// helper functions:
......
......@@ -281,16 +281,18 @@ void RunSettingsWidget::renameRunConfiguration()
arg(m_target->activeRunConfiguration()->displayName()),
QLineEdit::Normal,
m_target->activeRunConfiguration()->displayName(), &ok);
if (!ok || !this || name.isEmpty())
if (!ok || !this)
return;
QStringList rcNames;
foreach (RunConfiguration *rc, m_target->runConfigurations()) {
if (rc == m_target->activeRunConfiguration())
continue;
rcNames.append(rc->displayName());
if (!name.isEmpty()) {
QStringList rcNames;
foreach (RunConfiguration *rc, m_target->runConfigurations()) {
if (rc == m_target->activeRunConfiguration())
continue;
rcNames.append(rc->displayName());
}
name = Project::makeUnique(name, rcNames);
}
name = Project::makeUnique(name, rcNames);
m_target->activeRunConfiguration()->setDisplayName(name);