Commit 5df4f930 authored by dt's avatar dt
Browse files

Make it possible to edit the working directory the executable is run in.

parent d2ada829
......@@ -45,6 +45,7 @@
#include <QtGui/QInputDialog>
#include <QtGui/QLabel>
#include <QtGui/QCheckBox>
#include <QtGui/QToolButton>
using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
......@@ -58,10 +59,9 @@ Qt4RunConfiguration::Qt4RunConfiguration(Qt4Project *pro, const QString &proFile
m_runMode(Gui),
m_userSetName(false),
m_configWidget(0),
m_executableLabel(0),
m_workingDirectoryLabel(0),
m_cachedTargetInformationValid(false),
m_isUsingDyldImageSuffix(false)
m_isUsingDyldImageSuffix(false),
m_userSetWokingDirectory(false)
{
if (!m_proFilePath.isEmpty())
setName(QFileInfo(m_proFilePath).completeBaseName());
......@@ -104,8 +104,19 @@ Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4Run
m_executableLabel = new QLabel(m_qt4RunConfiguration->executable());
toplayout->addRow(tr("Executable:"), m_executableLabel);
m_workingDirectoryLabel = new QLabel(m_qt4RunConfiguration->workingDirectory());
toplayout->addRow(tr("Working Directory:"), m_workingDirectoryLabel);
m_workingDirectoryEdit = new Core::Utils::PathChooser();
m_workingDirectoryEdit->setPath(m_qt4RunConfiguration->workingDirectory());
m_workingDirectoryEdit->setExpectedKind(Core::Utils::PathChooser::Directory);
m_workingDirectoryEdit->setPromptDialogTitle(tr("Select the working directory"));
QToolButton *resetButton = new QToolButton();
resetButton->setToolTip(tr("Reset to default"));
resetButton->setIcon(QIcon(":/core/images/reset.png"));
QHBoxLayout *boxlayout = new QHBoxLayout();
boxlayout->addWidget(m_workingDirectoryEdit);
boxlayout->addWidget(resetButton);
toplayout->addRow(tr("Working Directory:"), boxlayout);
QLabel *argumentsLabel = new QLabel(tr("&Arguments:"));
m_argumentsLineEdit = new QLineEdit(ProjectExplorer::Environment::joinArgumentList(qt4RunConfiguration->commandLineArguments()));
......@@ -124,6 +135,12 @@ Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4Run
this, SLOT(usingDyldImageSuffixToggled(bool)));
#endif
connect(m_workingDirectoryEdit, SIGNAL(changed()),
this, SLOT(setWorkingDirectory()));
connect(resetButton, SIGNAL(clicked()),
this, SLOT(resetWorkingDirectory()));
connect(m_argumentsLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(setCommandLineArguments(QString)));
connect(m_nameLineEdit, SIGNAL(textEdited(QString)),
......@@ -131,6 +148,9 @@ Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4Run
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SLOT(termToggled(bool)));
connect(qt4RunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
this, SLOT(workingDirectoryChanged(QString)));
connect(qt4RunConfiguration, SIGNAL(commandLineArgumentsChanged(QString)),
this, SLOT(commandLineArgumentsChanged(QString)));
connect(qt4RunConfiguration, SIGNAL(nameChanged(QString)),
......@@ -144,6 +164,22 @@ Qt4RunConfigurationWidget::Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4Run
this, SLOT(effectiveTargetInformationChanged()), Qt::QueuedConnection);
}
void Qt4RunConfigurationWidget::setWorkingDirectory()
{
if (m_ignoreChange)
return;
m_ignoreChange = true;
m_qt4RunConfiguration->setWorkingDirectory(m_workingDirectoryEdit->path());
m_ignoreChange = false;
}
void Qt4RunConfigurationWidget::resetWorkingDirectory()
{
// This emits a signal connected to workingDirectoryChanged()
// that sets the m_workingDirectoryEdit
m_qt4RunConfiguration->setWorkingDirectory("");
}
void Qt4RunConfigurationWidget::setCommandLineArguments(const QString &args)
{
m_ignoreChange = true;
......@@ -173,6 +209,12 @@ void Qt4RunConfigurationWidget::usingDyldImageSuffixToggled(bool state)
m_ignoreChange = false;
}
void Qt4RunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
if (!m_ignoreChange)
m_workingDirectoryEdit->setPath(workingDirectory);
}
void Qt4RunConfigurationWidget::commandLineArgumentsChanged(const QString &args)
{
if (!m_ignoreChange)
......@@ -201,7 +243,9 @@ void Qt4RunConfigurationWidget::effectiveTargetInformationChanged()
{
if (m_isShown) {
m_executableLabel->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->executable()));
m_workingDirectoryLabel->setText(QDir::toNativeSeparators(m_qt4RunConfiguration->workingDirectory()));
m_ignoreChange = true;
m_workingDirectoryEdit->setPath(QDir::toNativeSeparators(m_qt4RunConfiguration->workingDirectory()));
m_ignoreChange = false;
}
}
......@@ -275,6 +319,11 @@ void Qt4RunConfiguration::setUsingDyldImageSuffix(bool state)
QString Qt4RunConfiguration::workingDirectory() const
{
// if the user overrode us, then return his working directory
if (m_userSetWokingDirectory)
return m_userWorkingDirectory;
// else what the pro file reader tells us
const_cast<Qt4RunConfiguration *>(this)->updateTarget();
return m_workingDir;
}
......@@ -296,6 +345,19 @@ ProjectExplorer::Environment Qt4RunConfiguration::environment() const
return env;
}
void Qt4RunConfiguration::setWorkingDirectory(const QString &wd)
{
if (wd== "") {
m_userSetWokingDirectory = false;
m_userWorkingDirectory = QString::null;
emit workingDirectoryChanged(workingDirectory());
} else {
m_userSetWokingDirectory = true;
m_userWorkingDirectory = wd;
emit workingDirectoryChanged(m_userWorkingDirectory);
}
}
void Qt4RunConfiguration::setCommandLineArguments(const QString &argumentsString)
{
m_commandLineArguments = ProjectExplorer::Environment::parseCombinedArgString(argumentsString);
......
......@@ -30,6 +30,7 @@
#ifndef QT4RUNCONFIGURATION_H
#define QT4RUNCONFIGURATION_H
#include <utils/pathchooser.h>
#include <projectexplorer/applicationrunconfiguration.h>
#include <QtCore/QStringList>
#include <QtGui/QWidget>
......@@ -87,6 +88,7 @@ public slots:
signals:
void nameChanged(const QString&);
void commandLineArgumentsChanged(const QString&);
void workingDirectoryChanged(const QString&);
void runModeChanged(ProjectExplorer::ApplicationRunConfiguration::RunMode runMode);
void usingDyldImageSuffixChanged(bool);
......@@ -95,6 +97,7 @@ signals:
private slots:
void setCommandLineArguments(const QString &argumentsString);
void setWorkingDirectory(const QString &workingDirectory);
void nameEdited(const QString&);
void setRunMode(RunMode runMode);
......@@ -110,10 +113,10 @@ private:
ProjectExplorer::ApplicationRunConfiguration::RunMode m_runMode;
bool m_userSetName;
QWidget *m_configWidget;
QLabel *m_executableLabel;
QLabel *m_workingDirectoryLabel;
bool m_cachedTargetInformationValid;
bool m_isUsingDyldImageSuffix;
bool m_userSetWokingDirectory;
QString m_userWorkingDirectory;
};
class Qt4RunConfigurationWidget : public QWidget
......@@ -125,12 +128,16 @@ protected:
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
private slots:
void setWorkingDirectory();
void resetWorkingDirectory();
void setCommandLineArguments(const QString &arguments);
void nameEdited(const QString &name);
// TODO connect to signals from qt4runconfiguration for changed arguments and names
void workingDirectoryChanged(const QString &workingDirectory);
void commandLineArgumentsChanged(const QString &args);
void nameChanged(const QString &name);
void runModeChanged(ProjectExplorer::ApplicationRunConfiguration::RunMode runMode);
void effectiveTargetInformationChanged();
void termToggled(bool);
void usingDyldImageSuffixToggled(bool);
......@@ -139,7 +146,7 @@ private:
Qt4RunConfiguration *m_qt4RunConfiguration;
bool m_ignoreChange;
QLabel *m_executableLabel;
QLabel *m_workingDirectoryLabel;
Core::Utils::PathChooser *m_workingDirectoryEdit;
QLineEdit *m_nameLineEdit;
QLineEdit *m_argumentsLineEdit;
QCheckBox *m_useTerminalCheck;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment