Move "builddirectory" template from Core to ProjectExplorer

Move Core::DocumentManager::buildDirectory to
ProjectExplorerPlugin::buildDirectoryTemplate.

Move the setter along.

Change-Id: I3f1739723e800d04d2934149369b8881208305b4
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2018-10-05 15:04:25 +02:00
parent 5f80bdfbcb
commit a43331ba67
12 changed files with 65 additions and 57 deletions

View File

@@ -35,7 +35,6 @@
#include "cmakeprojectmanager.h" #include "cmakeprojectmanager.h"
#include "cmakeprojectnodes.h" #include "cmakeprojectnodes.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/buildmanager.h> #include <projectexplorer/buildmanager.h>
@@ -160,7 +159,7 @@ FileName CMakeBuildConfiguration::shadowBuildDirectory(const FileName &projectFi
const QString projectName = projectFilePath.parentDir().fileName(); const QString projectName = projectFilePath.parentDir().fileName();
ProjectMacroExpander expander(projectFilePath.toString(), projectName, k, bcName, buildType); ProjectMacroExpander expander(projectFilePath.toString(), projectName, k, bcName, buildType);
QDir projectDir = QDir(Project::projectDirectory(projectFilePath).toString()); QDir projectDir = QDir(Project::projectDirectory(projectFilePath).toString());
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory()); QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
return FileName::fromUserInput(projectDir.absoluteFilePath(buildPath)); return FileName::fromUserInput(projectDir.absoluteFilePath(buildPath));
} }

View File

@@ -209,8 +209,6 @@ const char DEFAULT_THEME[] = "flat";
const char TR_CLEAR_MENU[] = QT_TRANSLATE_NOOP("Core", "Clear Menu"); const char TR_CLEAR_MENU[] = QT_TRANSLATE_NOOP("Core", "Clear Menu");
const char DEFAULT_BUILD_DIRECTORY[] = "../%{JS: Util.asciify(\"build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}\")}";
const int MODEBAR_ICON_SIZE = 34; const int MODEBAR_ICON_SIZE = 34;
const int MODEBAR_ICONSONLY_BUTTON_SIZE = MODEBAR_ICON_SIZE + 4; const int MODEBAR_ICONSONLY_BUTTON_SIZE = MODEBAR_ICON_SIZE + 4;
const int DEFAULT_MAX_CHAR_COUNT = 10000000; const int DEFAULT_MAX_CHAR_COUNT = 10000000;

View File

@@ -105,7 +105,6 @@ static const char editorsKeyC[] = "EditorIds";
static const char directoryGroupC[] = "Directories"; static const char directoryGroupC[] = "Directories";
static const char projectDirectoryKeyC[] = "Projects"; static const char projectDirectoryKeyC[] = "Projects";
static const char useProjectDirectoryKeyC[] = "UseProjectsDirectory"; static const char useProjectDirectoryKeyC[] = "UseProjectsDirectory";
static const char buildDirectoryKeyC[] = "BuildDirectory.Template";
using namespace Utils; using namespace Utils;
@@ -155,16 +154,16 @@ public:
QList<DocumentManager::RecentFile> m_recentFiles; QList<DocumentManager::RecentFile> m_recentFiles;
static const int m_maxRecentFiles = 7; static const int m_maxRecentFiles = 7;
QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation.
QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen).
bool m_postponeAutoReload = false; bool m_postponeAutoReload = false;
bool m_blockActivated = false; bool m_blockActivated = false;
bool m_checkOnFocusChange = false; bool m_checkOnFocusChange = false;
bool m_useProjectsDirectory = true;
QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation.
QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen).
QString m_lastVisitedDirectory = QDir::currentPath(); QString m_lastVisitedDirectory = QDir::currentPath();
QString m_defaultLocationForNewFiles; QString m_defaultLocationForNewFiles;
FileName m_projectsDirectory; FileName m_projectsDirectory;
bool m_useProjectsDirectory = true;
QString m_buildDirectory;
// When we are calling into an IDocument // When we are calling into an IDocument
// we don't want to receive a changed() // we don't want to receive a changed()
// signal // signal
@@ -1313,7 +1312,6 @@ void DocumentManager::saveSettings()
s->beginGroup(QLatin1String(directoryGroupC)); s->beginGroup(QLatin1String(directoryGroupC));
s->setValue(QLatin1String(projectDirectoryKeyC), d->m_projectsDirectory.toString()); s->setValue(QLatin1String(projectDirectoryKeyC), d->m_projectsDirectory.toString());
s->setValue(QLatin1String(useProjectDirectoryKeyC), d->m_useProjectsDirectory); s->setValue(QLatin1String(useProjectDirectoryKeyC), d->m_useProjectsDirectory);
s->setValue(QLatin1String(buildDirectoryKeyC), d->m_buildDirectory);
s->endGroup(); s->endGroup();
} }
@@ -1346,13 +1344,6 @@ void readSettings()
d->m_useProjectsDirectory = s->value(QLatin1String(useProjectDirectoryKeyC), d->m_useProjectsDirectory = s->value(QLatin1String(useProjectDirectoryKeyC),
d->m_useProjectsDirectory).toBool(); d->m_useProjectsDirectory).toBool();
const QString settingsShadowDir = s->value(QLatin1String(buildDirectoryKeyC),
QString()).toString();
if (!settingsShadowDir.isEmpty())
d->m_buildDirectory = settingsShadowDir;
else
d->m_buildDirectory = QLatin1String(Constants::DEFAULT_BUILD_DIRECTORY);
s->endGroup(); s->endGroup();
} }
@@ -1422,26 +1413,6 @@ void DocumentManager::setProjectsDirectory(const FileName &directory)
} }
} }
/*!
Returns the default build directory.
\sa setBuildDirectory
*/
QString DocumentManager::buildDirectory()
{
return d->m_buildDirectory;
}
/*!
Sets the shadow build directory to \a directory.
\sa buildDirectory
*/
void DocumentManager::setBuildDirectory(const QString &directory)
{
d->m_buildDirectory = directory;
}
/*! /*!
Returns whether the directory for projects is to be used or whether the user Returns whether the directory for projects is to be used or whether the user

View File

@@ -141,9 +141,6 @@ public:
static Utils::FileName projectsDirectory(); static Utils::FileName projectsDirectory();
static void setProjectsDirectory(const Utils::FileName &directory); static void setProjectsDirectory(const Utils::FileName &directory);
static QString buildDirectory();
static void setBuildDirectory(const QString &directory);
/* Used to notify e.g. the code model to update the given files. Does *not* /* Used to notify e.g. the code model to update the given files. Does *not*
lead to any editors to reload or any other editor manager actions. */ lead to any editors to reload or any other editor manager actions. */
static void notifyFilesChangedInternally(const QStringList &files); static void notifyFilesChangedInternally(const QStringList &files);

View File

@@ -34,12 +34,12 @@
#include "../nimconstants.h" #include "../nimconstants.h"
#include <coreplugin/documentmanager.h>
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildinfo.h> #include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildstep.h> #include <projectexplorer/buildstep.h>
#include <projectexplorer/kit.h> #include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h> #include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -59,7 +59,7 @@ static FileName defaultBuildDirectory(const Kit *k,
QFileInfo projectFileInfo(projectFilePath); QFileInfo projectFileInfo(projectFilePath);
ProjectMacroExpander expander(projectFilePath, projectFileInfo.baseName(), k, bc, buildType); ProjectMacroExpander expander(projectFilePath, projectFileInfo.baseName(), k, bc, buildType);
QString buildDirectory = expander.expand(Core::DocumentManager::buildDirectory()); QString buildDirectory = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
if (FileUtils::isAbsolutePath(buildDirectory)) if (FileUtils::isAbsolutePath(buildDirectory))
return FileName::fromString(buildDirectory); return FileName::fromString(buildDirectory);

View File

@@ -237,6 +237,10 @@ const char RUNMENUCONTEXTMENU[] = "Project.RunMenu";
const char FOLDER_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.F.OpenLocation.CtxMenu"; const char FOLDER_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.F.OpenLocation.CtxMenu";
const char PROJECT_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.P.OpenLocation.CtxMenu"; const char PROJECT_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.P.OpenLocation.CtxMenu";
// Default directories:
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE[] = "../%{JS: Util.asciify(\"build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}\")}";
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY[] = "Directories/BuildDirectory.Template";
} // namespace Constants } // namespace Constants
@@ -1294,6 +1298,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
if (tmp < 0 || tmp > ProjectExplorerSettings::StopSameBuildDir) if (tmp < 0 || tmp > ProjectExplorerSettings::StopSameBuildDir)
tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0; tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0;
dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp); dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp);
dd->m_projectExplorerSettings.buildDirectoryTemplate
= s->value(Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY).toString();
if (dd->m_projectExplorerSettings.buildDirectoryTemplate.isEmpty())
dd->m_projectExplorerSettings.buildDirectoryTemplate = Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE;
auto buildManager = new BuildManager(this, dd->m_cancelBuildAction); auto buildManager = new BuildManager(this, dd->m_cancelBuildAction);
connect(buildManager, &BuildManager::buildStateChanged, connect(buildManager, &BuildManager::buildStateChanged,
@@ -1825,6 +1833,9 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
s->setValue(QLatin1String("ProjectExplorer/Settings/MaxBuildOutputLines"), dd->m_projectExplorerSettings.maxBuildOutputChars / 100); s->setValue(QLatin1String("ProjectExplorer/Settings/MaxBuildOutputLines"), dd->m_projectExplorerSettings.maxBuildOutputChars / 100);
s->setValue(QLatin1String("ProjectExplorer/Settings/EnvironmentId"), dd->m_projectExplorerSettings.environmentId.toByteArray()); s->setValue(QLatin1String("ProjectExplorer/Settings/EnvironmentId"), dd->m_projectExplorerSettings.environmentId.toByteArray());
s->setValue(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"), dd->m_projectExplorerSettings.stopBeforeBuild); s->setValue(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"), dd->m_projectExplorerSettings.stopBeforeBuild);
// Store this in the Core directory scope for backward compatibility!
s->setValue(Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY, dd->m_projectExplorerSettings.buildDirectoryTemplate);
} }
void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName) void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
@@ -3600,6 +3611,31 @@ void ProjectExplorerPlugin::openOpenProjectDialog()
ICore::openFiles(files, ICore::SwitchMode); ICore::openFiles(files, ICore::SwitchMode);
} }
/*!
Returns the current build directory template.
\sa setBuildDirectoryTemplate
*/
QString ProjectExplorerPlugin::buildDirectoryTemplate()
{
return dd->m_projectExplorerSettings.buildDirectoryTemplate;
}
/*!
Sets the current build directory template to \a directory.
\sa defaultbuildDirectory
*/
void ProjectExplorerPlugin::setBuildDirectoryTemplate(const QString &dir)
{
dd->m_projectExplorerSettings.buildDirectoryTemplate = dir;
}
QString ProjectExplorerPlugin::defaultBuildDirectoryTemplate()
{
return Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE;
}
QList<QPair<QString, QString> > ProjectExplorerPlugin::recentProjects() QList<QPair<QString, QString> > ProjectExplorerPlugin::recentProjects()
{ {
return dd->recentProjects(); return dd->recentProjects();

View File

@@ -163,6 +163,10 @@ public:
static void openNewProjectDialog(); static void openNewProjectDialog();
static void openOpenProjectDialog(); static void openOpenProjectDialog();
static QString buildDirectoryTemplate();
static void setBuildDirectoryTemplate(const QString &dir);
static QString defaultBuildDirectoryTemplate();
signals: signals:
void finishedInitialization(); void finishedInitialization();

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QUuid> #include <QUuid>
@@ -54,6 +55,7 @@ public:
int maxAppOutputChars = Core::Constants::DEFAULT_MAX_CHAR_COUNT; int maxAppOutputChars = Core::Constants::DEFAULT_MAX_CHAR_COUNT;
int maxBuildOutputChars = Core::Constants::DEFAULT_MAX_CHAR_COUNT; int maxBuildOutputChars = Core::Constants::DEFAULT_MAX_CHAR_COUNT;
StopBeforeBuild stopBeforeBuild = StopBeforeBuild::StopNone; StopBeforeBuild stopBeforeBuild = StopBeforeBuild::StopNone;
QString buildDirectoryTemplate;
// Add a UUid which is used to identify the development environment. // Add a UUid which is used to identify the development environment.
// This is used to warn the user when he is trying to open a .user file that was created // This is used to warn the user when he is trying to open a .user file that was created
@@ -80,7 +82,8 @@ inline bool operator==(const ProjectExplorerSettings &p1, const ProjectExplorerS
&& p1.maxAppOutputChars == p2.maxAppOutputChars && p1.maxAppOutputChars == p2.maxAppOutputChars
&& p1.maxBuildOutputChars == p2.maxBuildOutputChars && p1.maxBuildOutputChars == p2.maxBuildOutputChars
&& p1.environmentId == p2.environmentId && p1.environmentId == p2.environmentId
&& p1.stopBeforeBuild == p2.stopBeforeBuild; && p1.stopBeforeBuild == p2.stopBeforeBuild
&& p1.buildDirectoryTemplate == p2.buildDirectoryTemplate;
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -57,12 +57,12 @@ public:
bool useProjectsDirectory(); bool useProjectsDirectory();
void setUseProjectsDirectory(bool v); void setUseProjectsDirectory(bool v);
QString buildDirectory() const; QString buildDirectoryTemplate() const;
void setBuildDirectory(const QString &bd); void setBuildDirectoryTemplate(const QString &bd);
private: private:
void slotDirectoryButtonGroupChanged(); void slotDirectoryButtonGroupChanged();
void resetDefaultBuildDirectory(); void resetBuildDirectoryTemplate();
void updateBuildDirectoryResetButton(); void updateBuildDirectoryResetButton();
void setJomVisible(bool); void setJomVisible(bool);
@@ -82,7 +82,7 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) :
connect(m_ui.directoryButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), connect(m_ui.directoryButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
this, &ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged); this, &ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged);
connect(m_ui.buildDirectoryResetButton, &QAbstractButton::clicked, connect(m_ui.buildDirectoryResetButton, &QAbstractButton::clicked,
this, &ProjectExplorerSettingsWidget::resetDefaultBuildDirectory); this, &ProjectExplorerSettingsWidget::resetBuildDirectoryTemplate);
connect(m_ui.buildDirectoryEdit, &QLineEdit::textChanged, connect(m_ui.buildDirectoryEdit, &QLineEdit::textChanged,
this, &ProjectExplorerSettingsWidget::updateBuildDirectoryResetButton); this, &ProjectExplorerSettingsWidget::updateBuildDirectoryResetButton);
@@ -160,12 +160,12 @@ void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b)
} }
} }
QString ProjectExplorerSettingsWidget::buildDirectory() const QString ProjectExplorerSettingsWidget::buildDirectoryTemplate() const
{ {
return m_ui.buildDirectoryEdit->text(); return m_ui.buildDirectoryEdit->text();
} }
void ProjectExplorerSettingsWidget::setBuildDirectory(const QString &bd) void ProjectExplorerSettingsWidget::setBuildDirectoryTemplate(const QString &bd)
{ {
m_ui.buildDirectoryEdit->setText(bd); m_ui.buildDirectoryEdit->setText(bd);
} }
@@ -176,14 +176,14 @@ void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged()
m_ui.projectsDirectoryPathChooser->setEnabled(enable); m_ui.projectsDirectoryPathChooser->setEnabled(enable);
} }
void ProjectExplorerSettingsWidget::resetDefaultBuildDirectory() void ProjectExplorerSettingsWidget::resetBuildDirectoryTemplate()
{ {
setBuildDirectory(QLatin1String(Core::Constants::DEFAULT_BUILD_DIRECTORY)); setBuildDirectoryTemplate(ProjectExplorerPlugin::defaultBuildDirectoryTemplate());
} }
void ProjectExplorerSettingsWidget::updateBuildDirectoryResetButton() void ProjectExplorerSettingsWidget::updateBuildDirectoryResetButton()
{ {
m_ui.buildDirectoryResetButton->setEnabled(buildDirectory() != QLatin1String(Core::Constants::DEFAULT_BUILD_DIRECTORY)); m_ui.buildDirectoryResetButton->setEnabled(buildDirectoryTemplate() != ProjectExplorerPlugin::defaultBuildDirectoryTemplate());
} }
// ------------------ ProjectExplorerSettingsPage // ------------------ ProjectExplorerSettingsPage
@@ -204,7 +204,7 @@ QWidget *ProjectExplorerSettingsPage::widget()
m_widget->setSettings(ProjectExplorerPlugin::projectExplorerSettings()); m_widget->setSettings(ProjectExplorerPlugin::projectExplorerSettings());
m_widget->setProjectsDirectory(Core::DocumentManager::projectsDirectory().toString()); m_widget->setProjectsDirectory(Core::DocumentManager::projectsDirectory().toString());
m_widget->setUseProjectsDirectory(Core::DocumentManager::useProjectsDirectory()); m_widget->setUseProjectsDirectory(Core::DocumentManager::useProjectsDirectory());
m_widget->setBuildDirectory(Core::DocumentManager::buildDirectory()); m_widget->setBuildDirectoryTemplate(ProjectExplorerPlugin::buildDirectoryTemplate());
} }
return m_widget; return m_widget;
} }
@@ -216,7 +216,7 @@ void ProjectExplorerSettingsPage::apply()
Core::DocumentManager::setProjectsDirectory( Core::DocumentManager::setProjectsDirectory(
Utils::FileName::fromString(m_widget->projectsDirectory())); Utils::FileName::fromString(m_widget->projectsDirectory()));
Core::DocumentManager::setUseProjectsDirectory(m_widget->useProjectsDirectory()); Core::DocumentManager::setUseProjectsDirectory(m_widget->useProjectsDirectory());
Core::DocumentManager::setBuildDirectory(m_widget->buildDirectory()); ProjectExplorerPlugin::setBuildDirectoryTemplate(m_widget->buildDirectoryTemplate());
} }
} }

View File

@@ -66,7 +66,7 @@ static FileName defaultBuildDirectory(const QString &projectFilePath, const Kit
const QString projectName = QFileInfo(projectFilePath).completeBaseName(); const QString projectName = QFileInfo(projectFilePath).completeBaseName();
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType); ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
QString projectDir = Project::projectDirectory(FileName::fromString(projectFilePath)).toString(); QString projectDir = Project::projectDirectory(FileName::fromString(projectFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory()); QString buildPath = expander.expand(ProjectExplorerPlugin::defaultBuildDirectory());
return FileName::fromString(FileUtils::resolvePath(projectDir, buildPath)); return FileName::fromString(FileUtils::resolvePath(projectDir, buildPath));
} }

View File

@@ -93,7 +93,7 @@ static QString buildDir(const QString &projectFilePath, const Kit *k)
BuildConfiguration::Unknown); BuildConfiguration::Unknown);
const QString projectDir const QString projectDir
= Project::projectDirectory(FileName::fromString(projectFilePath)).toString(); = Project::projectDirectory(FileName::fromString(projectFilePath)).toString();
const QString buildPath = expander.expand(Core::DocumentManager::buildDirectory()); const QString buildPath = expander.expand(ProjectExplorerPlugin::defaultBuildDirectory());
return FileUtils::resolvePath(projectDir, buildPath); return FileUtils::resolvePath(projectDir, buildPath);
} }

View File

@@ -83,7 +83,7 @@ QString QmakeBuildConfiguration::shadowBuildDirectory(const QString &proFilePath
const QString projectName = QFileInfo(proFilePath).completeBaseName(); const QString projectName = QFileInfo(proFilePath).completeBaseName();
ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType); ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType);
QString projectDir = Project::projectDirectory(FileName::fromString(proFilePath)).toString(); QString projectDir = Project::projectDirectory(FileName::fromString(proFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory()); QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
return FileUtils::resolvePath(projectDir, buildPath); return FileUtils::resolvePath(projectDir, buildPath);
} }