Commit 1b3909e4 authored by Aaron McCarthy's avatar Aaron McCarthy

Add option to place shadow build directory parallel to source tree.

This option requires that the projects directory setting is enabled.
For example with the following settings:

Projects directory: $HOME/depot
Build directory: $HOME/build

This will by default place the default shadow build directory in the
$HOME/build tree instead of adjacent to the source in $HOME/depot.

Change-Id: I74bfc00883d0479d5965350c760d14ef7602cc34
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 2198fa90
......@@ -97,6 +97,8 @@ static const char editorsKeyC[] = "EditorIds";
static const char directoryGroupC[] = "Directories";
static const char projectDirectoryKeyC[] = "Projects";
static const char useProjectDirectoryKeyC[] = "UseProjectsDirectory";
static const char buildDirectoryKeyC[] = "BuildDirectory";
static const char useBuildDirectoryKeyC[] = "UseBuildDirectory";
namespace Core {
......@@ -156,6 +158,8 @@ struct DocumentManagerPrivate
QString m_lastVisitedDirectory;
QString m_projectsDirectory;
bool m_useProjectsDirectory;
QString m_buildDirectory;
bool m_useBuildDirectory;
// When we are callling into a IDocument
// we don't want to receive a changed()
// signal
......@@ -198,6 +202,7 @@ DocumentManagerPrivate::DocumentManagerPrivate(QMainWindow *mw) :
m_blockActivated(false),
m_lastVisitedDirectory(QDir::currentPath()),
m_useProjectsDirectory(Utils::HostOsInfo::isMacHost()), // Creator is in bizarre places when launched via finder.
m_useBuildDirectory(false),
m_blockedIDocument(0)
{
}
......@@ -1165,6 +1170,8 @@ void DocumentManager::saveSettings()
s->beginGroup(QLatin1String(directoryGroupC));
s->setValue(QLatin1String(projectDirectoryKeyC), d->m_projectsDirectory);
s->setValue(QLatin1String(useProjectDirectoryKeyC), d->m_useProjectsDirectory);
s->setValue(QLatin1String(buildDirectoryKeyC), d->m_buildDirectory);
s->setValue(QLatin1String(useBuildDirectoryKeyC), d->m_useBuildDirectory);
s->endGroup();
}
......@@ -1197,6 +1204,16 @@ void readSettings()
}
d->m_useProjectsDirectory = s->value(QLatin1String(useProjectDirectoryKeyC),
d->m_useProjectsDirectory).toBool();
const QString settingsShadowDir = s->value(QLatin1String(buildDirectoryKeyC),
QString()).toString();
if (!settingsShadowDir.isEmpty() && QFileInfo(settingsShadowDir).isDir())
d->m_buildDirectory = settingsShadowDir;
else
d->m_buildDirectory = Utils::PathChooser::homePath();
d->m_useBuildDirectory = s->value(QLatin1String(useBuildDirectoryKeyC),
d->m_useBuildDirectory).toBool();
s->endGroup();
}
......@@ -1267,6 +1284,47 @@ void DocumentManager::setProjectsDirectory(const QString &dir)
d->m_projectsDirectory = dir;
}
/*!
Returns whether the default shadow build directory is placed adjacent to the source in the
projects directory or in a separate build tree.
\sa setUseBuildDirectory, setBuildDirectory
*/
bool DocumentManager::useBuildDirectory()
{
return d->m_useBuildDirectory;
}
/*!
Sets whether a separate build directory is to the used when shadow building.
\sa buildDirectory, usebuildDirectory
*/
void DocumentManager::setUseBuildDirectory(bool use)
{
d->m_useBuildDirectory = use;
}
/*!
Returns the shadow build directory.
\sa setBuildDirectory, useBuildDirectory
*/
QString DocumentManager::buildDirectory()
{
return d->m_buildDirectory;
}
/*!
Sets the shadow build directory to \a directory.
\sa buildDirectory, useBuildDirectory
*/
void DocumentManager::setBuildDirectory(const QString &directory)
{
d->m_buildDirectory = directory;
}
/*!
Returns whether the directory for projects is to be
......
......@@ -129,6 +129,12 @@ public:
static QString projectsDirectory();
static void setProjectsDirectory(const QString &);
static bool useBuildDirectory();
static void setUseBuildDirectory(bool use);
static QString buildDirectory();
static void setBuildDirectory(const QString &directory);
static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
/* Used to notify e.g. the code model to update the given files. Does *not*
......
......@@ -53,6 +53,8 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) :
m_ui.directoryButtonGroup->setId(m_ui.directoryRadioButton, UseProjectDirectory);
connect(m_ui.directoryButtonGroup, SIGNAL(buttonClicked(int)),
this, SLOT(slotDirectoryButtonGroupChanged()));
connect(m_ui.buildDirectoryCheckBox, SIGNAL(toggled(bool)),
this, SLOT(slotBuildDirectoryCheckBoxChanged(bool)));
}
void ProjectExplorerSettingsWidget::setJomVisible(bool v)
......@@ -118,9 +120,40 @@ void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b)
}
}
bool ProjectExplorerSettingsWidget::useBuildDirectory() const
{
return m_ui.buildDirectoryCheckBox->isChecked();
}
void ProjectExplorerSettingsWidget::setUseBuildDirectory(bool v)
{
if (useBuildDirectory() != v) {
m_ui.buildDirectoryCheckBox->setChecked(v);
slotBuildDirectoryCheckBoxChanged(v);
}
}
QString ProjectExplorerSettingsWidget::buildDirectory() const
{
return m_ui.buildDirectoryPathChooser->path();
}
void ProjectExplorerSettingsWidget::setBuildDirectory(const QString &bd)
{
m_ui.buildDirectoryPathChooser->setPath(bd);
}
void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged()
{
m_ui.projectsDirectoryPathChooser->setEnabled(useProjectsDirectory());
bool enable = useProjectsDirectory();
m_ui.projectsDirectoryPathChooser->setEnabled(enable);
m_ui.buildDirectoryCheckBox->setEnabled(enable);
m_ui.buildDirectoryPathChooser->setEnabled(enable && useBuildDirectory());
}
void ProjectExplorerSettingsWidget::slotBuildDirectoryCheckBoxChanged(bool checked)
{
m_ui.buildDirectoryPathChooser->setEnabled(useProjectsDirectory() && checked);
}
QString ProjectExplorerSettingsWidget::searchKeywords() const
......@@ -167,6 +200,8 @@ QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent)
m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings());
m_widget->setProjectsDirectory(Core::DocumentManager::projectsDirectory());
m_widget->setUseProjectsDirectory(Core::DocumentManager::useProjectsDirectory());
m_widget->setUseBuildDirectory(Core::DocumentManager::useBuildDirectory());
m_widget->setBuildDirectory(Core::DocumentManager::buildDirectory());
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget;
......@@ -178,6 +213,8 @@ void ProjectExplorerSettingsPage::apply()
ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings());
Core::DocumentManager::setProjectsDirectory(m_widget->projectsDirectory());
Core::DocumentManager::setUseProjectsDirectory(m_widget->useProjectsDirectory());
Core::DocumentManager::setUseBuildDirectory(m_widget->useBuildDirectory());
Core::DocumentManager::setBuildDirectory(m_widget->buildDirectory());
}
}
......
......@@ -55,10 +55,17 @@ public:
bool useProjectsDirectory();
void setUseProjectsDirectory(bool v);
bool useBuildDirectory() const;
void setUseBuildDirectory(bool v);
QString buildDirectory() const;
void setBuildDirectory(const QString &bd);
QString searchKeywords() const;
private slots:
void slotDirectoryButtonGroupChanged();
void slotBuildDirectoryCheckBoxChanged(bool checked);
private:
void setJomVisible(bool);
......
......@@ -20,6 +20,9 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="currentDirectoryRadioButton">
<property name="text">
......@@ -30,6 +33,23 @@
</attribute>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="projectsDirectoryPathChooser" native="true"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="buildDirectoryCheckBox">
<property name="text">
<string>Build directory</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="buildDirectoryPathChooser" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="directoryRadioButton">
<property name="text">
......@@ -43,9 +63,6 @@
</attribute>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="projectsDirectoryPathChooser" native="true"/>
</item>
</layout>
</widget>
</item>
......@@ -237,6 +254,7 @@
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
......
......@@ -46,6 +46,7 @@
#include <coreplugin/messagemanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/documentmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <cpptools/ModelManagerInterface.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
......@@ -1426,9 +1427,25 @@ QString Qt4Project::shadowBuildDirectory(const QString &profilePath, const Kit *
if (version && !version->supportsShadowBuilds())
return info.absolutePath();
QString base = QDir::cleanPath(projectDirectory(profilePath) + QLatin1String("/../")
+ info.baseName() + QLatin1String("-build-"));
return base + buildNameFor(k) + QLatin1String("-") + sanitize(suffix);
Utils::FileName buildDirBase = Utils::FileName::fromString(projectDirectory(profilePath));
if (Core::DocumentManager::useProjectsDirectory() &&
Core::DocumentManager::useBuildDirectory()) {
const Utils::FileName projectsDirectory =
Utils::FileName::fromString(Core::DocumentManager::projectsDirectory());
if (buildDirBase.isChildOf(projectsDirectory)) {
Utils::FileName buildDirectory =
Utils::FileName::fromString(Core::DocumentManager::buildDirectory());
buildDirectory.appendPath(buildDirBase.relativeChildPath(projectsDirectory).toString());
buildDirBase = buildDirectory;
}
}
buildDirBase.append(QLatin1String("-build-") + buildNameFor(k) +
QLatin1Char('-') + sanitize(suffix));
return QDir::cleanPath(buildDirBase.toString());
}
QString Qt4Project::buildNameFor(const Kit *k)
......
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