forked from qt-creator/qt-creator
Core: Move system env storage to SystemSettings
Less indirections in the code. Change-Id: I61cb9fe100732db62fd01b45cb706ef2d47a2462 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "modemanager.h"
|
#include "modemanager.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "settingsdatabase.h"
|
#include "settingsdatabase.h"
|
||||||
|
#include "systemsettings.h"
|
||||||
#include "themechooser.h"
|
#include "themechooser.h"
|
||||||
#include "vcsmanager.h"
|
#include "vcsmanager.h"
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/checkablemessagebox.h>
|
#include <utils/checkablemessagebox.h>
|
||||||
#include <utils/commandline.h>
|
#include <utils/commandline.h>
|
||||||
|
#include <utils/environment.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/macroexpander.h>
|
#include <utils/macroexpander.h>
|
||||||
@@ -67,11 +69,13 @@ using namespace Utils;
|
|||||||
static CorePlugin *m_instance = nullptr;
|
static CorePlugin *m_instance = nullptr;
|
||||||
|
|
||||||
const char kWarnCrashReportingSetting[] = "WarnCrashReporting";
|
const char kWarnCrashReportingSetting[] = "WarnCrashReporting";
|
||||||
const char kEnvironmentChanges[] = "Core/EnvironmentChanges";
|
|
||||||
|
|
||||||
CorePlugin::CorePlugin()
|
CorePlugin::CorePlugin()
|
||||||
: m_startupSystemEnvironment(Environment::systemEnvironment())
|
|
||||||
{
|
{
|
||||||
|
// Trigger creation as early as possible before anyone else could
|
||||||
|
// mess with the systemEnvironment before it is "backed up".
|
||||||
|
(void) systemSettings();
|
||||||
|
|
||||||
qRegisterMetaType<Id>();
|
qRegisterMetaType<Id>();
|
||||||
qRegisterMetaType<Utils::Text::Position>();
|
qRegisterMetaType<Utils::Text::Position>();
|
||||||
qRegisterMetaType<Utils::CommandLine>();
|
qRegisterMetaType<Utils::CommandLine>();
|
||||||
@@ -82,10 +86,6 @@ CorePlugin::CorePlugin()
|
|||||||
qRegisterMetaType<Utils::KeyList>();
|
qRegisterMetaType<Utils::KeyList>();
|
||||||
qRegisterMetaType<Utils::OldStore>();
|
qRegisterMetaType<Utils::OldStore>();
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
|
||||||
const EnvironmentItems changes = EnvironmentItem::fromStringList(
|
|
||||||
ICore::settings()->value(kEnvironmentChanges).toStringList());
|
|
||||||
setEnvironmentChanges(changes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CorePlugin::~CorePlugin()
|
CorePlugin::~CorePlugin()
|
||||||
@@ -455,25 +455,6 @@ QObject *CorePlugin::remoteCommand(const QStringList & /* options */,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
EnvironmentItems CorePlugin::environmentChanges()
|
|
||||||
{
|
|
||||||
return m_instance->m_environmentChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CorePlugin::setEnvironmentChanges(const EnvironmentItems &changes)
|
|
||||||
{
|
|
||||||
if (m_instance->m_environmentChanges == changes)
|
|
||||||
return;
|
|
||||||
m_instance->m_environmentChanges = changes;
|
|
||||||
Environment systemEnv = m_instance->m_startupSystemEnvironment;
|
|
||||||
systemEnv.modify(changes);
|
|
||||||
Environment::setSystemEnvironment(systemEnv);
|
|
||||||
ICore::settings()->setValueWithDefault(kEnvironmentChanges,
|
|
||||||
EnvironmentItem::toStringList(changes));
|
|
||||||
if (ICore::instance())
|
|
||||||
emit ICore::instance()->systemEnvironmentChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CorePlugin::fileOpenRequest(const QString &f)
|
void CorePlugin::fileOpenRequest(const QString &f)
|
||||||
{
|
{
|
||||||
remoteCommand(QStringList(), QString(), QStringList(f));
|
remoteCommand(QStringList(), QString(), QStringList(f));
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <extensionsystem/pluginspec.h>
|
#include <extensionsystem/pluginspec.h>
|
||||||
#include <utils/environment.h>
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@@ -39,8 +38,6 @@ public:
|
|||||||
const QString &workingDirectory,
|
const QString &workingDirectory,
|
||||||
const QStringList &args) override;
|
const QStringList &args) override;
|
||||||
|
|
||||||
static Utils::EnvironmentItems environmentChanges();
|
|
||||||
static void setEnvironmentChanges(const Utils::EnvironmentItems &changes);
|
|
||||||
static QString msgCrashpadInformation();
|
static QString msgCrashpadInformation();
|
||||||
|
|
||||||
static void loadMimeFromPlugin(const ExtensionSystem::PluginSpec *plugin);
|
static void loadMimeFromPlugin(const ExtensionSystem::PluginSpec *plugin);
|
||||||
@@ -65,8 +62,6 @@ private:
|
|||||||
EditMode *m_editMode = nullptr;
|
EditMode *m_editMode = nullptr;
|
||||||
Locator *m_locator = nullptr;
|
Locator *m_locator = nullptr;
|
||||||
FolderNavigationWidgetFactory *m_folderNavigationWidgetFactory = nullptr;
|
FolderNavigationWidgetFactory *m_folderNavigationWidgetFactory = nullptr;
|
||||||
const Utils::Environment m_startupSystemEnvironment;
|
|
||||||
Utils::EnvironmentItems m_environmentChanges;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -4,13 +4,11 @@
|
|||||||
#include "systemsettings.h"
|
#include "systemsettings.h"
|
||||||
|
|
||||||
#include "coreconstants.h"
|
#include "coreconstants.h"
|
||||||
#include "coreplugin.h"
|
|
||||||
#include "coreplugintr.h"
|
#include "coreplugintr.h"
|
||||||
#include "editormanager/editormanager_p.h"
|
#include "editormanager/editormanager_p.h"
|
||||||
#include "dialogs/ioptionspage.h"
|
#include "dialogs/ioptionspage.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
#include "iversioncontrol.h"
|
|
||||||
#include "vcsmanager.h"
|
#include "vcsmanager.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -61,7 +59,12 @@ SystemSettings &systemSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SystemSettings::SystemSettings()
|
SystemSettings::SystemSettings()
|
||||||
|
: m_startupSystemEnvironment(Environment::systemEnvironment())
|
||||||
{
|
{
|
||||||
|
const EnvironmentItems changes = EnvironmentItem::fromStringList(
|
||||||
|
ICore::settings()->value(kEnvironmentChanges).toStringList());
|
||||||
|
setEnvironmentChanges(changes);
|
||||||
|
|
||||||
setAutoApply(false);
|
setAutoApply(false);
|
||||||
|
|
||||||
patchCommand.setSettingsKey("General/PatchCommand");
|
patchCommand.setSettingsKey("General/PatchCommand");
|
||||||
@@ -348,7 +351,7 @@ public:
|
|||||||
updatePath();
|
updatePath();
|
||||||
|
|
||||||
m_environmentChangesLabel->setElideMode(Qt::ElideRight);
|
m_environmentChangesLabel->setElideMode(Qt::ElideRight);
|
||||||
m_environmentChanges = CorePlugin::environmentChanges();
|
m_environmentChanges = systemSettings().environmentChanges();
|
||||||
updateEnvironmentChangesLabel();
|
updateEnvironmentChangesLabel();
|
||||||
connect(environmentButton, &QPushButton::clicked, this, [this, environmentButton] {
|
connect(environmentButton, &QPushButton::clicked, this, [this, environmentButton] {
|
||||||
std::optional<EnvironmentItems> changes
|
std::optional<EnvironmentItems> changes
|
||||||
@@ -418,7 +421,7 @@ void SystemSettingsWidget::apply()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CorePlugin::setEnvironmentChanges(m_environmentChanges);
|
systemSettings().setEnvironmentChanges(m_environmentChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemSettingsWidget::resetTerminal()
|
void SystemSettingsWidget::resetTerminal()
|
||||||
@@ -480,6 +483,25 @@ void SystemSettingsWidget::showHelpForFileBrowser()
|
|||||||
showHelpDialog(Tr::tr("Variables"), UnixUtils::fileBrowserHelpText());
|
showHelpDialog(Tr::tr("Variables"), UnixUtils::fileBrowserHelpText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnvironmentItems SystemSettings::environmentChanges() const
|
||||||
|
{
|
||||||
|
return m_environmentChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemSettings::setEnvironmentChanges(const EnvironmentItems &changes)
|
||||||
|
{
|
||||||
|
if (m_environmentChanges == changes)
|
||||||
|
return;
|
||||||
|
m_environmentChanges = changes;
|
||||||
|
Environment systemEnv = m_startupSystemEnvironment;
|
||||||
|
systemEnv.modify(changes);
|
||||||
|
Environment::setSystemEnvironment(systemEnv);
|
||||||
|
ICore::settings()->setValueWithDefault(kEnvironmentChanges,
|
||||||
|
EnvironmentItem::toStringList(changes));
|
||||||
|
if (ICore::instance())
|
||||||
|
emit ICore::instance()->systemEnvironmentChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// SystemSettingsPage
|
// SystemSettingsPage
|
||||||
|
|
||||||
class SystemSettingsPage final : public IOptionsPage
|
class SystemSettingsPage final : public IOptionsPage
|
||||||
|
@@ -6,9 +6,12 @@
|
|||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
|
#include <utils/environment.h>
|
||||||
|
|
||||||
namespace Core::Internal {
|
namespace Core::Internal {
|
||||||
|
|
||||||
|
const char kEnvironmentChanges[] = "Core/EnvironmentChanges";
|
||||||
|
|
||||||
class CORE_TEST_EXPORT SystemSettings final : public Utils::AspectContainer
|
class CORE_TEST_EXPORT SystemSettings final : public Utils::AspectContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -36,6 +39,13 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Utils::BoolAspect askBeforeExit{this};
|
Utils::BoolAspect askBeforeExit{this};
|
||||||
|
|
||||||
|
Utils::EnvironmentItems environmentChanges() const;
|
||||||
|
void setEnvironmentChanges(const Utils::EnvironmentItems &changes);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::EnvironmentItems m_environmentChanges;
|
||||||
|
const Utils::Environment m_startupSystemEnvironment;
|
||||||
};
|
};
|
||||||
|
|
||||||
CORE_TEST_EXPORT SystemSettings &systemSettings();
|
CORE_TEST_EXPORT SystemSettings &systemSettings();
|
||||||
|
Reference in New Issue
Block a user