QmakeProjectManager: Use WorkingDirectoryAspect

Change-Id: Ia0359477bad1d40a2349e782b19600fa19547216
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
hjk
2015-12-18 14:57:23 +01:00
parent 05789c8da1
commit e0fdeaa624
2 changed files with 10 additions and 117 deletions

View File

@@ -70,7 +70,6 @@ const char QMAKE_RC_PREFIX[] = "Qt4ProjectManager.Qt4RunConfiguration:";
const char PRO_FILE_KEY[] = "Qt4ProjectManager.Qt4RunConfiguration.ProFile"; const char PRO_FILE_KEY[] = "Qt4ProjectManager.Qt4RunConfiguration.ProFile";
const char USE_DYLD_IMAGE_SUFFIX_KEY[] = "Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix"; const char USE_DYLD_IMAGE_SUFFIX_KEY[] = "Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix";
const char USE_LIBRARY_SEARCH_PATH[] = "QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath"; const char USE_LIBRARY_SEARCH_PATH[] = "QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath";
const char USER_WORKING_DIRECTORY_KEY[] = "Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory";
static Utils::FileName pathFromId(Core::Id id) static Utils::FileName pathFromId(Core::Id id)
{ {
@@ -88,6 +87,8 @@ DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *parent, Core:
addExtraAspect(new LocalEnvironmentAspect(this)); addExtraAspect(new LocalEnvironmentAspect(this));
addExtraAspect(new ArgumentsAspect(this, QStringLiteral("Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"))); addExtraAspect(new ArgumentsAspect(this, QStringLiteral("Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments")));
addExtraAspect(new TerminalAspect(this, QStringLiteral("Qt4ProjectManager.Qt4RunConfiguration.UseTerminal"))); addExtraAspect(new TerminalAspect(this, QStringLiteral("Qt4ProjectManager.Qt4RunConfiguration.UseTerminal")));
addExtraAspect(new WorkingDirectoryAspect(this,
QStringLiteral("Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory")));
QmakeProject *project = static_cast<QmakeProject *>(parent->project()); QmakeProject *project = static_cast<QmakeProject *>(parent->project());
m_parseSuccess = project->validParse(m_proFilePath); m_parseSuccess = project->validParse(m_proFilePath);
@@ -101,7 +102,6 @@ DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *parent, Deskt
m_proFilePath(source->m_proFilePath), m_proFilePath(source->m_proFilePath),
m_isUsingDyldImageSuffix(source->m_isUsingDyldImageSuffix), m_isUsingDyldImageSuffix(source->m_isUsingDyldImageSuffix),
m_isUsingLibrarySearchPath(source->m_isUsingLibrarySearchPath), m_isUsingLibrarySearchPath(source->m_isUsingLibrarySearchPath),
m_userWorkingDirectory(source->m_userWorkingDirectory),
m_parseSuccess(source->m_parseSuccess), m_parseSuccess(source->m_parseSuccess),
m_parseInProgress(source->m_parseInProgress) m_parseInProgress(source->m_parseInProgress)
{ {
@@ -206,29 +206,7 @@ DesktopQmakeRunConfigurationWidget::DesktopQmakeRunConfigurationWidget(DesktopQm
toplayout->addRow(tr("Executable:"), m_executableLineLabel); toplayout->addRow(tr("Executable:"), m_executableLineLabel);
m_qmakeRunConfiguration->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, toplayout); m_qmakeRunConfiguration->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, toplayout);
m_qmakeRunConfiguration->extraAspect<WorkingDirectoryAspect>()->addToMainConfigurationWidget(this, toplayout);
m_workingDirectoryEdit = new PathChooser(this);
m_workingDirectoryEdit->setExpectedKind(PathChooser::Directory);
m_workingDirectoryEdit->setHistoryCompleter(QLatin1String("Qmake.WorkingDir.History"));
m_workingDirectoryEdit->setPath(m_qmakeRunConfiguration->baseWorkingDirectory());
m_workingDirectoryEdit->setBaseFileName(m_qmakeRunConfiguration->target()->project()->projectDirectory());
EnvironmentAspect *aspect = qmakeRunConfiguration->extraAspect<EnvironmentAspect>();
if (aspect) {
connect(aspect, SIGNAL(environmentChanged()), this, SLOT(environmentWasChanged()));
environmentWasChanged();
}
m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
QToolButton *resetButton = new QToolButton(this);
resetButton->setToolTip(tr("Reset to Default"));
resetButton->setIcon(Core::Icons::RESET.icon());
QHBoxLayout *boxlayout = new QHBoxLayout();
boxlayout->setMargin(0);
boxlayout->addWidget(m_workingDirectoryEdit);
boxlayout->addWidget(resetButton);
toplayout->addRow(tr("Working directory:"), boxlayout);
m_qmakeRunConfiguration->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, toplayout); m_qmakeRunConfiguration->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, toplayout);
m_useQvfbCheck = new QCheckBox(tr("Run on QVFb"), this); m_useQvfbCheck = new QCheckBox(tr("Run on QVFb"), this);
@@ -270,18 +248,9 @@ DesktopQmakeRunConfigurationWidget::DesktopQmakeRunConfigurationWidget(DesktopQm
runConfigurationEnabledChange(); runConfigurationEnabledChange();
connect(m_workingDirectoryEdit, SIGNAL(rawPathChanged(QString)),
this, SLOT(workDirectoryEdited()));
connect(resetButton, SIGNAL(clicked()),
this, SLOT(workingDirectoryReseted()));
connect(m_useQvfbCheck, SIGNAL(toggled(bool)), connect(m_useQvfbCheck, SIGNAL(toggled(bool)),
this, SLOT(qvfbToggled(bool))); this, SLOT(qvfbToggled(bool)));
connect(qmakeRunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
this, SLOT(workingDirectoryChanged(QString)));
connect(qmakeRunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)), connect(qmakeRunConfiguration, SIGNAL(usingDyldImageSuffixChanged(bool)),
this, SLOT(usingDyldImageSuffixChanged(bool))); this, SLOT(usingDyldImageSuffixChanged(bool)));
connect(qmakeRunConfiguration, &DesktopQmakeRunConfiguration::usingLibrarySearchPathChanged, connect(qmakeRunConfiguration, &DesktopQmakeRunConfiguration::usingLibrarySearchPathChanged,
@@ -299,13 +268,6 @@ DesktopQmakeRunConfigurationWidget::~DesktopQmakeRunConfigurationWidget()
{ {
} }
void DesktopQmakeRunConfigurationWidget::environmentWasChanged()
{
EnvironmentAspect *aspect = m_qmakeRunConfiguration->extraAspect<EnvironmentAspect>();
QTC_ASSERT(aspect, return);
m_workingDirectoryEdit->setEnvironment(aspect->environment());
}
void DesktopQmakeRunConfigurationWidget::runConfigurationEnabledChange() void DesktopQmakeRunConfigurationWidget::runConfigurationEnabledChange()
{ {
bool enabled = m_qmakeRunConfiguration->isEnabled(); bool enabled = m_qmakeRunConfiguration->isEnabled();
@@ -314,22 +276,6 @@ void DesktopQmakeRunConfigurationWidget::runConfigurationEnabledChange()
m_disabledReason->setText(m_qmakeRunConfiguration->disabledReason()); m_disabledReason->setText(m_qmakeRunConfiguration->disabledReason());
} }
void DesktopQmakeRunConfigurationWidget::workDirectoryEdited()
{
if (m_ignoreChange)
return;
m_ignoreChange = true;
m_qmakeRunConfiguration->setBaseWorkingDirectory(m_workingDirectoryEdit->rawPath());
m_ignoreChange = false;
}
void DesktopQmakeRunConfigurationWidget::workingDirectoryReseted()
{
// This emits a signal connected to workingDirectoryChanged()
// that sets the m_workingDirectoryEdit
m_qmakeRunConfiguration->setBaseWorkingDirectory(QString());
}
void DesktopQmakeRunConfigurationWidget::qvfbToggled(bool on) void DesktopQmakeRunConfigurationWidget::qvfbToggled(bool on)
{ {
Q_UNUSED(on); Q_UNUSED(on);
@@ -351,12 +297,6 @@ void DesktopQmakeRunConfigurationWidget::usingLibrarySearchPathToggled(bool stat
m_ignoreChange = false; m_ignoreChange = false;
} }
void DesktopQmakeRunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
if (!m_ignoreChange)
m_workingDirectoryEdit->setPath(workingDirectory);
}
void DesktopQmakeRunConfigurationWidget::usingDyldImageSuffixChanged(bool state) void DesktopQmakeRunConfigurationWidget::usingDyldImageSuffixChanged(bool state)
{ {
if (!m_ignoreChange && m_usingDyldImageSuffix) if (!m_ignoreChange && m_usingDyldImageSuffix)
@@ -371,25 +311,13 @@ void DesktopQmakeRunConfigurationWidget::usingLibrarySearchPathChanged(bool stat
void DesktopQmakeRunConfigurationWidget::effectiveTargetInformationChanged() void DesktopQmakeRunConfigurationWidget::effectiveTargetInformationChanged()
{ {
if (m_isShown) { m_executableLineLabel->setText(QDir::toNativeSeparators(m_qmakeRunConfiguration->executable()));
m_executableLineLabel->setText(QDir::toNativeSeparators(m_qmakeRunConfiguration->executable()));
m_ignoreChange = true;
m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qmakeRunConfiguration->baseWorkingDirectory()));
m_ignoreChange = false;
}
}
void DesktopQmakeRunConfigurationWidget::showEvent(QShowEvent *event) m_ignoreChange = true;
{ auto aspect = m_qmakeRunConfiguration->extraAspect<WorkingDirectoryAspect>();
m_isShown = true; aspect->setDefaultWorkingDirectory(m_qmakeRunConfiguration->baseWorkingDirectory());
effectiveTargetInformationChanged(); aspect->pathChooser()->setBaseFileName(m_qmakeRunConfiguration->target()->project()->projectDirectory());
QWidget::showEvent(event); m_ignoreChange = false;
}
void DesktopQmakeRunConfigurationWidget::hideEvent(QHideEvent *event)
{
m_isShown = false;
QWidget::hideEvent(event);
} }
QWidget *DesktopQmakeRunConfiguration::createConfigurationWidget() QWidget *DesktopQmakeRunConfiguration::createConfigurationWidget()
@@ -404,7 +332,6 @@ QVariantMap DesktopQmakeRunConfiguration::toMap() const
map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath.toString())); map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath.toString()));
map.insert(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), m_isUsingDyldImageSuffix); map.insert(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), m_isUsingDyldImageSuffix);
map.insert(QLatin1String(USE_LIBRARY_SEARCH_PATH), m_isUsingLibrarySearchPath); map.insert(QLatin1String(USE_LIBRARY_SEARCH_PATH), m_isUsingLibrarySearchPath);
map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory);
return map; return map;
} }
@@ -415,8 +342,6 @@ bool DesktopQmakeRunConfiguration::fromMap(const QVariantMap &map)
m_isUsingDyldImageSuffix = map.value(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), false).toBool(); m_isUsingDyldImageSuffix = map.value(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), false).toBool();
m_isUsingLibrarySearchPath = map.value(QLatin1String(USE_LIBRARY_SEARCH_PATH), true).toBool(); m_isUsingLibrarySearchPath = map.value(QLatin1String(USE_LIBRARY_SEARCH_PATH), true).toBool();
m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString();
m_parseSuccess = static_cast<QmakeProject *>(target()->project())->validParse(m_proFilePath); m_parseSuccess = static_cast<QmakeProject *>(target()->project())->validParse(m_proFilePath);
m_parseInProgress = static_cast<QmakeProject *>(target()->project())->parseInProgress(m_proFilePath); m_parseInProgress = static_cast<QmakeProject *>(target()->project())->parseInProgress(m_proFilePath);
@@ -467,19 +392,11 @@ void DesktopQmakeRunConfiguration::setUsingLibrarySearchPath(bool state)
QString DesktopQmakeRunConfiguration::workingDirectory() const QString DesktopQmakeRunConfiguration::workingDirectory() const
{ {
EnvironmentAspect *aspect = extraAspect<EnvironmentAspect>(); return extraAspect<WorkingDirectoryAspect>()->workingDirectory();
QTC_ASSERT(aspect, return baseWorkingDirectory());
return QDir::cleanPath(aspect->environment().expandVariables(
macroExpander()->expand(baseWorkingDirectory())));
} }
QString DesktopQmakeRunConfiguration::baseWorkingDirectory() const QString DesktopQmakeRunConfiguration::baseWorkingDirectory() const
{ {
// if the user overrode us, then return his working directory
if (!m_userWorkingDirectory.isEmpty())
return m_userWorkingDirectory;
// else what the pro file reader tells us
QmakeProject *pro = static_cast<QmakeProject *>(target()->project()); QmakeProject *pro = static_cast<QmakeProject *>(target()->project());
const QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePath); const QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePath);
return extractWorkingDirAndExecutable(node).first; return extractWorkingDirAndExecutable(node).first;
@@ -490,17 +407,6 @@ QString DesktopQmakeRunConfiguration::commandLineArguments() const
return extraAspect<ArgumentsAspect>()->arguments(); return extraAspect<ArgumentsAspect>()->arguments();
} }
void DesktopQmakeRunConfiguration::setBaseWorkingDirectory(const QString &wd)
{
const QString &oldWorkingDirectory = workingDirectory();
m_userWorkingDirectory = wd;
const QString &newWorkingDirectory = workingDirectory();
if (oldWorkingDirectory != newWorkingDirectory)
emit baseWorkingDirectoryChanged(newWorkingDirectory);
}
void DesktopQmakeRunConfiguration::addToBaseEnvironment(Environment &env) const void DesktopQmakeRunConfiguration::addToBaseEnvironment(Environment &env) const
{ {
if (m_isUsingDyldImageSuffix) if (m_isUsingDyldImageSuffix)

View File

@@ -111,7 +111,6 @@ protected:
private: private:
QPair<QString, QString> extractWorkingDirAndExecutable(const QmakeProFileNode *node) const; QPair<QString, QString> extractWorkingDirAndExecutable(const QmakeProFileNode *node) const;
void setBaseWorkingDirectory(const QString &workingDirectory);
QString baseWorkingDirectory() const; QString baseWorkingDirectory() const;
QString defaultDisplayName(); QString defaultDisplayName();
@@ -123,7 +122,6 @@ private:
// Cached startup sub project information // Cached startup sub project information
bool m_isUsingDyldImageSuffix = false; bool m_isUsingDyldImageSuffix = false;
bool m_isUsingLibrarySearchPath = true; bool m_isUsingLibrarySearchPath = true;
QString m_userWorkingDirectory;
bool m_parseSuccess = false; bool m_parseSuccess = false;
bool m_parseInProgress = false; bool m_parseInProgress = false;
}; };
@@ -136,17 +134,8 @@ public:
DesktopQmakeRunConfigurationWidget(DesktopQmakeRunConfiguration *qmakeRunConfiguration, QWidget *parent); DesktopQmakeRunConfigurationWidget(DesktopQmakeRunConfiguration *qmakeRunConfiguration, QWidget *parent);
~DesktopQmakeRunConfigurationWidget(); ~DesktopQmakeRunConfigurationWidget();
protected:
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
private slots: private slots:
void runConfigurationEnabledChange(); void runConfigurationEnabledChange();
void workDirectoryEdited();
void workingDirectoryReseted();
void environmentWasChanged();
void workingDirectoryChanged(const QString &workingDirectory);
void effectiveTargetInformationChanged(); void effectiveTargetInformationChanged();
void qvfbToggled(bool); void qvfbToggled(bool);
@@ -161,13 +150,11 @@ private:
QLabel *m_disabledIcon = nullptr; QLabel *m_disabledIcon = nullptr;
QLabel *m_disabledReason = nullptr; QLabel *m_disabledReason = nullptr;
QLabel *m_executableLineLabel = nullptr; QLabel *m_executableLineLabel = nullptr;
Utils::PathChooser *m_workingDirectoryEdit = nullptr;
QCheckBox *m_useQvfbCheck = nullptr; QCheckBox *m_useQvfbCheck = nullptr;
QCheckBox *m_usingDyldImageSuffix = nullptr; QCheckBox *m_usingDyldImageSuffix = nullptr;
QCheckBox *m_usingLibrarySearchPath = nullptr; QCheckBox *m_usingLibrarySearchPath = nullptr;
QLineEdit *m_qmlDebugPort = nullptr; QLineEdit *m_qmlDebugPort = nullptr;
Utils::DetailsWidget *m_detailsContainer = nullptr; Utils::DetailsWidget *m_detailsContainer = nullptr;
bool m_isShown = false;
}; };
class DesktopQmakeRunConfigurationFactory : public QmakeRunConfigurationFactory class DesktopQmakeRunConfigurationFactory : public QmakeRunConfigurationFactory