Use WorkingDirectoryAspect in CustomExecutableRunConfiguration

Change-Id: Id7e082aed3161e7a85a4d23b74cc9b1c848e5631
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-03-20 11:39:22 +01:00
parent 417436c965
commit 7ae87fa8fd
4 changed files with 16 additions and 70 deletions

View File

@@ -60,26 +60,23 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
layout->addRow(tr("Executable:"), m_executableChooser);
auto argumentsAspect = rc->extraAspect<ArgumentsAspect>();
auto workingDirectoryAspect = rc->extraAspect<WorkingDirectoryAspect>();
auto terminalAspect = rc->extraAspect<TerminalAspect>();
if (mode == InstantApply) {
argumentsAspect->addToMainConfigurationWidget(this, layout);
workingDirectoryAspect->addToMainConfigurationWidget(this, layout);
terminalAspect->addToMainConfigurationWidget(this, layout);
} else {
m_temporaryArgumentsAspect = new ArgumentsAspect(rc, QString());
m_temporaryArgumentsAspect->copyFrom(argumentsAspect);
m_temporaryArgumentsAspect->addToMainConfigurationWidget(this, layout);
connect(m_temporaryArgumentsAspect, &ArgumentsAspect::argumentsChanged,
this, &CustomExecutableConfigurationWidget::validChanged);
}
m_workingDirectory = new PathChooser(this);
m_workingDirectory->setHistoryCompleter(QLatin1String("Qt.WorkingDir.History"));
m_workingDirectory->setExpectedKind(PathChooser::Directory);
m_temporaryWorkingDirectoryAspect = new WorkingDirectoryAspect(rc, QString());
m_temporaryWorkingDirectoryAspect->copyFrom(workingDirectoryAspect);
m_temporaryArgumentsAspect->addToMainConfigurationWidget(this, layout);
layout->addRow(tr("Working directory:"), m_workingDirectory);
auto terminalAspect = rc->extraAspect<TerminalAspect>();
if (mode == InstantApply) {
terminalAspect->addToMainConfigurationWidget(this, layout);
} else {
m_temporaryTerminalAspect = new TerminalAspect(rc, QString());
m_temporaryTerminalAspect->copyFrom(terminalAspect);
m_temporaryTerminalAspect->addToMainConfigurationWidget(this, layout);
@@ -103,13 +100,9 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
if (mode == InstantApply) {
connect(m_executableChooser, &PathChooser::rawPathChanged,
this, &CustomExecutableConfigurationWidget::executableEdited);
connect(m_workingDirectory, &PathChooser::rawPathChanged,
this, &CustomExecutableConfigurationWidget::workingDirectoryEdited);
} else {
connect(m_executableChooser, &PathChooser::rawPathChanged,
this, &CustomExecutableConfigurationWidget::validChanged);
connect(m_workingDirectory, &PathChooser::rawPathChanged,
this, &CustomExecutableConfigurationWidget::validChanged);
}
auto enviromentAspect = rc->extraAspect<EnvironmentAspect>();
@@ -132,13 +125,13 @@ CustomExecutableConfigurationWidget::~CustomExecutableConfigurationWidget()
{
delete m_temporaryArgumentsAspect;
delete m_temporaryTerminalAspect;
delete m_temporaryWorkingDirectoryAspect;
}
void CustomExecutableConfigurationWidget::environmentWasChanged()
{
auto aspect = m_runConfiguration->extraAspect<EnvironmentAspect>();
QTC_ASSERT(aspect, return);
m_workingDirectory->setEnvironment(aspect->environment());
m_executableChooser->setEnvironment(aspect->environment());
}
@@ -149,13 +142,6 @@ void CustomExecutableConfigurationWidget::executableEdited()
m_ignoreChange = false;
}
void CustomExecutableConfigurationWidget::workingDirectoryEdited()
{
m_ignoreChange = true;
m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
m_ignoreChange = false;
}
void CustomExecutableConfigurationWidget::changed()
{
// We triggered the change, don't update us
@@ -163,16 +149,16 @@ void CustomExecutableConfigurationWidget::changed()
return;
m_executableChooser->setPath(m_runConfiguration->rawExecutable());
m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory());
}
void CustomExecutableConfigurationWidget::apply()
{
m_ignoreChange = true;
m_runConfiguration->setExecutable(m_executableChooser->rawPath());
m_runConfiguration->setCommandLineArguments(m_temporaryArgumentsAspect->unexpandedArguments());
m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
m_runConfiguration->setRunMode(m_temporaryTerminalAspect->runMode());
m_runConfiguration->extraAspect<WorkingDirectoryAspect>()
->copyFrom(m_temporaryWorkingDirectoryAspect);
m_runConfiguration->extraAspect<ArgumentsAspect>()->copyFrom(m_temporaryArgumentsAspect);
m_runConfiguration->extraAspect<TerminalAspect>()->copyFrom(m_temporaryTerminalAspect);
m_ignoreChange = false;
}

View File

@@ -44,6 +44,7 @@ namespace ProjectExplorer {
class ArgumentsAspect;
class TerminalAspect;
class WorkingDirectoryAspect;
class CustomExecutableRunConfiguration;
namespace Internal {
@@ -66,15 +67,14 @@ signals:
private:
void changed();
void executableEdited();
void workingDirectoryEdited();
void environmentWasChanged();
bool m_ignoreChange = false;
CustomExecutableRunConfiguration *m_runConfiguration = 0;
ProjectExplorer::ArgumentsAspect *m_temporaryArgumentsAspect = 0;
ProjectExplorer::TerminalAspect *m_temporaryTerminalAspect = 0;
ProjectExplorer::WorkingDirectoryAspect *m_temporaryWorkingDirectoryAspect = 0;
Utils::PathChooser *m_executableChooser = 0;
Utils::PathChooser *m_workingDirectory = 0;
Utils::DetailsWidget *m_detailsContainer = 0;
};

View File

@@ -53,7 +53,6 @@ namespace ProjectExplorer {
const char CUSTOM_EXECUTABLE_ID[] = "ProjectExplorer.CustomExecutableRunConfiguration";
const char EXECUTABLE_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.Executable";
const char WORKING_DIRECTORY_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory";
// Dialog embedding the CustomExecutableConfigurationWidget
// prompting the user to complete the configuration.
@@ -88,6 +87,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
addExtraAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()));
addExtraAspect(new ArgumentsAspect(this, "ProjectExplorer.CustomExecutableRunConfiguration.Arguments"));
addExtraAspect(new TerminalAspect(this, "ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal"));
addExtraAspect(new WorkingDirectoryAspect(this, "ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory"));
setDefaultDisplayName(defaultDisplayName());
}
@@ -184,7 +184,7 @@ bool CustomExecutableRunConfiguration::validateExecutable(QString *executable, Q
if (aspect)
env = aspect->environment();
const Utils::FileName exec = env.searchInPath(macroExpander()->expand(m_executable),
{Utils::FileName::fromString(workingDirectory())});
{extraAspect<WorkingDirectoryAspect>()->workingDirectory()});
if (exec.isEmpty()) {
if (errorMessage)
*errorMessage = tr("The executable\n%1\ncannot be found in the path.").
@@ -213,31 +213,17 @@ bool CustomExecutableRunConfiguration::isConfigured() const
return !m_executable.isEmpty();
}
QString CustomExecutableRunConfiguration::workingDirectory() const
{
EnvironmentAspect *aspect = extraAspect<EnvironmentAspect>();
QTC_ASSERT(aspect, return baseWorkingDirectory());
return QDir::cleanPath(aspect->environment().expandVariables(
macroExpander()->expand(baseWorkingDirectory())));
}
Runnable CustomExecutableRunConfiguration::runnable() const
{
StandardRunnable r;
r.executable = executable();
r.commandLineArguments = extraAspect<ArgumentsAspect>()->arguments();
r.workingDirectory = workingDirectory();
r.environment = extraAspect<LocalEnvironmentAspect>()->environment();
r.runMode = extraAspect<TerminalAspect>()->runMode();
r.device = DeviceManager::instance()->defaultDevice(Constants::DESKTOP_DEVICE_TYPE);
return r;
}
QString CustomExecutableRunConfiguration::baseWorkingDirectory() const
{
return m_workingDirectory;
}
QString CustomExecutableRunConfiguration::defaultDisplayName() const
{
if (m_executable.isEmpty())
@@ -250,15 +236,12 @@ QVariantMap CustomExecutableRunConfiguration::toMap() const
{
QVariantMap map(RunConfiguration::toMap());
map.insert(QLatin1String(EXECUTABLE_KEY), m_executable);
map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory);
return map;
}
bool CustomExecutableRunConfiguration::fromMap(const QVariantMap &map)
{
m_executable = map.value(QLatin1String(EXECUTABLE_KEY)).toString();
m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString();
setDefaultDisplayName(defaultDisplayName());
return RunConfiguration::fromMap(map);
}
@@ -272,24 +255,6 @@ void CustomExecutableRunConfiguration::setExecutable(const QString &executable)
emit changed();
}
void CustomExecutableRunConfiguration::setCommandLineArguments(const QString &commandLineArguments)
{
extraAspect<ArgumentsAspect>()->setArguments(commandLineArguments);
emit changed();
}
void CustomExecutableRunConfiguration::setBaseWorkingDirectory(const QString &workingDirectory)
{
m_workingDirectory = workingDirectory;
emit changed();
}
void CustomExecutableRunConfiguration::setRunMode(ApplicationLauncher::Mode runMode)
{
extraAspect<TerminalAspect>()->setRunMode(runMode);
emit changed();
}
QWidget *CustomExecutableRunConfiguration::createConfigurationWidget()
{
return new CustomExecutableConfigurationWidget(this, CustomExecutableConfigurationWidget::InstantApply);

View File

@@ -51,7 +51,6 @@ public:
* ask the user if none is specified
*/
QString executable() const;
QString workingDirectory() const;
Runnable runnable() const override;
/** Returns whether this runconfiguration ever was configured with an executable
@@ -72,11 +71,7 @@ private:
void configurationDialogFinished();
void setExecutable(const QString &executable);
QString rawExecutable() const;
void setCommandLineArguments(const QString &commandLineArguments);
void setBaseWorkingDirectory(const QString &workingDirectory);
QString baseWorkingDirectory() const;
void setUserName(const QString &name);
void setRunMode(ApplicationLauncher::Mode runMode);
bool validateExecutable(QString *executable = 0, QString *errorMessage = 0) const;
QString m_executable;