80da24ecf8
We were using std::basic_string_view as a stand-in for std::span so that
we could change over all at once when C++20 dropped with full span
support. That day's not here yet, but as of 54a7fce3e
we're using GSL 3,
whose span is C++20-compliant.
This commit replaces every instance of basic_string_view that was not
referring to an actual string with a span of the appropriate type.
I moved the `const` qualifier into span's `T` because while
`basic_string_view.at()` returns `const T&`, `span.at()` returns `T&`
(without the const). I wanted to maintain the invariant that members of
the span were immutable.
* Mechanical Changes
* `sv.at(x)` -> `gsl::at(sp, x)`
* `sv.c{begin,end}` -> `sp.{begin,end}` (span's iterators are const)
I had to replace a `std::basic_string<>` with a `std::vector<>` in
ConImeInfo, and I chose to replace a manual array walk in
ScreenInfoUiaProviderBase with a ranged-for. Please review those
specifically.
This will almost certainly cause a code size regression in Windows
because I'm blowing out all the PGO counts. Whoops.
Related: #3956, #975.
134 lines
4.8 KiB
C++
134 lines
4.8 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
Licensed under the MIT license.
|
|
|
|
Module Name:
|
|
- CascadiaSettings.h
|
|
|
|
Abstract:
|
|
- This class acts as the container for all app settings. It's composed of two
|
|
parts: Globals, which are app-wide settings, and Profiles, which contain
|
|
a set of settings that apply to a single instance of the terminal.
|
|
Also contains the logic for serializing and deserializing this object.
|
|
|
|
Author(s):
|
|
- Mike Griese - March 2019
|
|
|
|
--*/
|
|
#pragma once
|
|
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
|
|
#include "GlobalAppSettings.h"
|
|
#include "TerminalWarnings.h"
|
|
#include "Profile.h"
|
|
#include "IDynamicProfileGenerator.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace TerminalAppLocalTests
|
|
{
|
|
class SettingsTests;
|
|
class ProfileTests;
|
|
class ColorSchemeTests;
|
|
class KeyBindingsTests;
|
|
class TabTests;
|
|
};
|
|
namespace TerminalAppUnitTests
|
|
{
|
|
class DynamicProfileTests;
|
|
class JsonTests;
|
|
};
|
|
|
|
namespace TerminalApp
|
|
{
|
|
class CascadiaSettings;
|
|
};
|
|
|
|
class TerminalApp::CascadiaSettings final
|
|
{
|
|
public:
|
|
CascadiaSettings();
|
|
explicit CascadiaSettings(const bool addDynamicProfiles);
|
|
|
|
static std::unique_ptr<CascadiaSettings> LoadDefaults();
|
|
static std::unique_ptr<CascadiaSettings> LoadAll();
|
|
static std::unique_ptr<CascadiaSettings> LoadUniversal();
|
|
|
|
static const CascadiaSettings& GetCurrentAppSettings();
|
|
|
|
std::tuple<GUID, winrt::Microsoft::Terminal::Settings::TerminalSettings> BuildSettings(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const;
|
|
winrt::Microsoft::Terminal::Settings::TerminalSettings BuildSettings(GUID profileGuid) const;
|
|
|
|
GlobalAppSettings& GlobalSettings();
|
|
|
|
gsl::span<const Profile> GetProfiles() const noexcept;
|
|
|
|
winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept;
|
|
|
|
static std::unique_ptr<CascadiaSettings> FromJson(const Json::Value& json);
|
|
void LayerJson(const Json::Value& json);
|
|
|
|
static std::filesystem::path GetSettingsPath();
|
|
static std::filesystem::path GetDefaultSettingsPath();
|
|
|
|
const Profile* FindProfile(GUID profileGuid) const noexcept;
|
|
const ColorScheme* GetColorSchemeForProfile(const GUID profileGuid) const;
|
|
|
|
std::vector<TerminalApp::SettingsLoadWarnings>& GetWarnings();
|
|
|
|
private:
|
|
GlobalAppSettings _globals;
|
|
std::vector<Profile> _profiles;
|
|
std::vector<TerminalApp::SettingsLoadWarnings> _warnings;
|
|
|
|
std::vector<std::unique_ptr<TerminalApp::IDynamicProfileGenerator>> _profileGenerators;
|
|
|
|
std::string _userSettingsString;
|
|
Json::Value _userSettings;
|
|
Json::Value _defaultSettings;
|
|
Json::Value _userDefaultProfileSettings{ Json::Value::null };
|
|
|
|
void _LayerOrCreateProfile(const Json::Value& profileJson);
|
|
Profile* _FindMatchingProfile(const Json::Value& profileJson);
|
|
void _LayerOrCreateColorScheme(const Json::Value& schemeJson);
|
|
ColorScheme* _FindMatchingColorScheme(const Json::Value& schemeJson);
|
|
void _ParseJsonString(std::string_view fileData, const bool isDefaultSettings);
|
|
static const Json::Value& _GetProfilesJsonObject(const Json::Value& json);
|
|
static const Json::Value& _GetDisabledProfileSourcesJsonObject(const Json::Value& json);
|
|
bool _PrependSchemaDirective();
|
|
bool _AppendDynamicProfilesToUserSettings();
|
|
std::string _ApplyFirstRunChangesToSettingsTemplate(std::string_view settingsTemplate) const;
|
|
|
|
void _ApplyDefaultsFromUserSettings();
|
|
|
|
void _LoadDynamicProfiles();
|
|
|
|
static bool _IsPackaged();
|
|
static void _WriteSettings(const std::string_view content);
|
|
static std::optional<std::string> _ReadUserSettings();
|
|
static std::optional<std::string> _ReadFile(HANDLE hFile);
|
|
|
|
std::optional<GUID> _GetProfileGuidByName(const std::wstring_view) const;
|
|
std::optional<GUID> _GetProfileGuidByIndex(std::optional<int> index) const;
|
|
GUID _GetProfileForArgs(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const;
|
|
|
|
void _ValidateSettings();
|
|
void _ValidateProfilesExist();
|
|
void _ValidateProfilesHaveGuid();
|
|
void _ValidateDefaultProfileExists();
|
|
void _ValidateNoDuplicateProfiles();
|
|
void _ResolveDefaultProfile();
|
|
void _ReorderProfilesToMatchUserSettingsOrder();
|
|
void _RemoveHiddenProfiles();
|
|
void _ValidateAllSchemesExist();
|
|
void _ValidateMediaResources();
|
|
void _ValidateKeybindings();
|
|
void _ValidateNoGlobalsKey();
|
|
|
|
friend class TerminalAppLocalTests::SettingsTests;
|
|
friend class TerminalAppLocalTests::ProfileTests;
|
|
friend class TerminalAppLocalTests::ColorSchemeTests;
|
|
friend class TerminalAppLocalTests::KeyBindingsTests;
|
|
friend class TerminalAppLocalTests::TabTests;
|
|
friend class TerminalAppUnitTests::DynamicProfileTests;
|
|
friend class TerminalAppUnitTests::JsonTests;
|
|
};
|