Group font options in the json into a single object (#10433)
Introduces `FontConfig`, an object that isolates font-related settings in our profiles Users can now define font settings in their json as so: ``` "font":{ "face": "Consolas", "size": 12 } ``` Backwards compatible with the currently expected way of defining font settings in the json, note however that upon hitting 'Save' in the SUI, these settings **will be rewritten to the font-object style in the json (as above)**. ## Validation Steps Performed Existing functionality works, new functionality works References #1790 Closes #6049
This commit is contained in:
parent
f3e30d07fa
commit
9b9b0738c8
|
@ -165,6 +165,49 @@
|
|||
},
|
||||
"type": "object"
|
||||
},
|
||||
"FontConfig": {
|
||||
"properties": {
|
||||
"face": {
|
||||
"default": "Cascadia Mono",
|
||||
"description": "Name of the font face used in the profile.",
|
||||
"type": "string"
|
||||
},
|
||||
"size": {
|
||||
"default": 12,
|
||||
"description": "Size of the font in points.",
|
||||
"minimum": 1,
|
||||
"type": "integer"
|
||||
},
|
||||
"weight": {
|
||||
"default": "normal",
|
||||
"description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.",
|
||||
"oneOf": [
|
||||
{
|
||||
"enum": [
|
||||
"thin",
|
||||
"extra-light",
|
||||
"light",
|
||||
"semi-light",
|
||||
"normal",
|
||||
"medium",
|
||||
"semi-bold",
|
||||
"bold",
|
||||
"extra-bold",
|
||||
"black",
|
||||
"extra-black"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"maximum": 990,
|
||||
"minimum": 100,
|
||||
"type": "integer"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ProfileGuid": {
|
||||
"default": "{}",
|
||||
"pattern": "^\\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\}$",
|
||||
|
@ -1264,6 +1307,11 @@
|
|||
"description": "Sets the appearance of the terminal when it is unfocused.",
|
||||
"type": ["object", "null"]
|
||||
},
|
||||
"font": {
|
||||
"$ref": "#/definitions/FontConfig",
|
||||
"description": "Sets the font options of the terminal.",
|
||||
"type": ["object", "null"]
|
||||
},
|
||||
"backgroundImage": {
|
||||
"description": "Sets the file location of the image to draw over the window background.",
|
||||
"oneOf": [
|
||||
|
@ -1380,18 +1428,20 @@
|
|||
},
|
||||
"fontFace": {
|
||||
"default": "Cascadia Mono",
|
||||
"description": "Name of the font face used in the profile.",
|
||||
"type": "string"
|
||||
"description": "[deprecated] Define 'face' within the 'font' object instead.",
|
||||
"type": "string",
|
||||
"deprecated": true
|
||||
},
|
||||
"fontSize": {
|
||||
"default": 12,
|
||||
"description": "Size of the font in points.",
|
||||
"description": "[deprecated] Define 'size' within the 'font' object instead.",
|
||||
"minimum": 1,
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"deprecated": true
|
||||
},
|
||||
"fontWeight": {
|
||||
"default": "normal",
|
||||
"description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.",
|
||||
"description": "[deprecated] Define 'weight' within the 'font' object instead.",
|
||||
"oneOf": [
|
||||
{
|
||||
"enum": [
|
||||
|
@ -1414,7 +1464,8 @@
|
|||
"minimum": 100,
|
||||
"type": "integer"
|
||||
}
|
||||
]
|
||||
],
|
||||
"deprecated": true
|
||||
},
|
||||
"foreground": {
|
||||
"$ref": "#/definitions/Color",
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace SettingsModelLocalTests
|
|||
TEST_METHOD(ColorScheme);
|
||||
TEST_METHOD(Actions);
|
||||
TEST_METHOD(CascadiaSettings);
|
||||
TEST_METHOD(LegacyFontSettings);
|
||||
|
||||
TEST_CLASS_SETUP(ClassSetup)
|
||||
{
|
||||
|
@ -138,9 +139,11 @@ namespace SettingsModelLocalTests
|
|||
"tabTitle": "Cool Tab",
|
||||
"suppressApplicationTitle": false,
|
||||
|
||||
"fontFace": "Cascadia Mono",
|
||||
"fontSize": 12,
|
||||
"fontWeight": "normal",
|
||||
"font": {
|
||||
"face": "Cascadia Mono",
|
||||
"size": 12,
|
||||
"weight": "normal"
|
||||
},
|
||||
"padding": "8, 8, 8, 8",
|
||||
"antialiasingMode": "grayscale",
|
||||
|
||||
|
@ -402,11 +405,13 @@ namespace SettingsModelLocalTests
|
|||
|
||||
"profiles": {
|
||||
"defaults": {
|
||||
"fontFace": "Zamora Code"
|
||||
"font": {
|
||||
"face": "Zamora Code"
|
||||
}
|
||||
},
|
||||
"list": [
|
||||
{
|
||||
"fontFace": "Cascadia Code",
|
||||
"font": { "face": "Cascadia Code" },
|
||||
"guid": "{61c54bbd-1111-5271-96e7-009a87ff44bf}",
|
||||
"name": "HowettShell"
|
||||
},
|
||||
|
@ -464,4 +469,35 @@ namespace SettingsModelLocalTests
|
|||
const auto result{ settings->ToJson() };
|
||||
VERIFY_ARE_EQUAL(toString(settings->_userSettings), toString(result));
|
||||
}
|
||||
|
||||
void SerializationTests::LegacyFontSettings()
|
||||
{
|
||||
const std::string profileString{ R"(
|
||||
{
|
||||
"name": "Profile with legacy font settings",
|
||||
|
||||
"fontFace": "Cascadia Mono",
|
||||
"fontSize": 12,
|
||||
"fontWeight": "normal"
|
||||
})" };
|
||||
|
||||
const std::string expectedOutput{ R"(
|
||||
{
|
||||
"name": "Profile with legacy font settings",
|
||||
|
||||
"font": {
|
||||
"face": "Cascadia Mono",
|
||||
"size": 12,
|
||||
"weight": "normal"
|
||||
}
|
||||
})" };
|
||||
|
||||
const auto json{ VerifyParseSucceeded(profileString) };
|
||||
const auto settings{ implementation::Profile::FromJson(json) };
|
||||
const auto result{ settings->ToJson() };
|
||||
|
||||
const auto jsonOutput{ VerifyParseSucceeded(expectedOutput) };
|
||||
|
||||
VERIFY_ARE_EQUAL(toString(jsonOutput), toString(result));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
OBSERVABLE_PROJECTED_SETTING(_profile, UseAcrylic);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, AcrylicOpacity);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, ScrollState);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, FontFace);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, FontSize);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, FontWeight);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontFace);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontSize);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontWeight);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, Padding);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, Commandline);
|
||||
OBSERVABLE_PROJECTED_SETTING(_profile, StartingDirectory);
|
||||
|
|
|
@ -296,6 +296,13 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate
|
|||
duplicated->##settingName(source.##settingName()); \
|
||||
}
|
||||
|
||||
#define DUPLICATE_FONT_SETTING_MACRO(settingName) \
|
||||
if (source.FontInfo().Has##settingName() || \
|
||||
(source.FontInfo().##settingName##OverrideSource() != nullptr && source.FontInfo().##settingName##OverrideSource().SourceProfile().Origin() != OriginTag::ProfilesDefaults)) \
|
||||
{ \
|
||||
duplicated->FontInfo().##settingName(source.FontInfo().##settingName()); \
|
||||
}
|
||||
|
||||
#define DUPLICATE_APPEARANCE_SETTING_MACRO(settingName) \
|
||||
if (source.DefaultAppearance().Has##settingName() || \
|
||||
(source.DefaultAppearance().##settingName##OverrideSource() != nullptr && source.DefaultAppearance().##settingName##OverrideSource().SourceProfile().Origin() != OriginTag::ProfilesDefaults)) \
|
||||
|
@ -312,9 +319,6 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate
|
|||
DUPLICATE_SETTING_MACRO(UseAcrylic);
|
||||
DUPLICATE_SETTING_MACRO(AcrylicOpacity);
|
||||
DUPLICATE_SETTING_MACRO(ScrollState);
|
||||
DUPLICATE_SETTING_MACRO(FontFace);
|
||||
DUPLICATE_SETTING_MACRO(FontSize);
|
||||
DUPLICATE_SETTING_MACRO(FontWeight);
|
||||
DUPLICATE_SETTING_MACRO(Padding);
|
||||
DUPLICATE_SETTING_MACRO(Commandline);
|
||||
DUPLICATE_SETTING_MACRO(StartingDirectory);
|
||||
|
@ -326,6 +330,10 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate
|
|||
DUPLICATE_SETTING_MACRO(AltGrAliasing);
|
||||
DUPLICATE_SETTING_MACRO(BellStyle);
|
||||
|
||||
DUPLICATE_FONT_SETTING_MACRO(FontFace);
|
||||
DUPLICATE_FONT_SETTING_MACRO(FontSize);
|
||||
DUPLICATE_FONT_SETTING_MACRO(FontWeight);
|
||||
|
||||
DUPLICATE_APPEARANCE_SETTING_MACRO(ColorSchemeName);
|
||||
DUPLICATE_APPEARANCE_SETTING_MACRO(Foreground);
|
||||
DUPLICATE_APPEARANCE_SETTING_MACRO(Background);
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "pch.h"
|
||||
#include "FontConfig.h"
|
||||
#include "FontConfig.g.cpp"
|
||||
#include "TerminalSettingsSerializationHelpers.h"
|
||||
#include "JsonUtils.h"
|
||||
|
||||
using namespace Microsoft::Terminal::Settings::Model;
|
||||
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
|
||||
|
||||
static constexpr std::string_view FontInfoKey{ "font" };
|
||||
static constexpr std::string_view FontFaceKey{ "face" };
|
||||
static constexpr std::string_view FontSizeKey{ "size" };
|
||||
static constexpr std::string_view FontWeightKey{ "weight" };
|
||||
static constexpr std::string_view LegacyFontFaceKey{ "fontFace" };
|
||||
static constexpr std::string_view LegacyFontSizeKey{ "fontSize" };
|
||||
static constexpr std::string_view LegacyFontWeightKey{ "fontWeight" };
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::implementation::FontConfig::FontConfig(winrt::weak_ref<Profile> sourceProfile) :
|
||||
_sourceProfile(std::move(sourceProfile))
|
||||
{
|
||||
}
|
||||
|
||||
winrt::com_ptr<FontConfig> FontConfig::CopyFontInfo(const winrt::com_ptr<FontConfig> source, winrt::weak_ref<Profile> sourceProfile)
|
||||
{
|
||||
auto fontInfo{ winrt::make_self<FontConfig>(std::move(sourceProfile)) };
|
||||
fontInfo->_FontFace = source->_FontFace;
|
||||
fontInfo->_FontSize = source->_FontSize;
|
||||
fontInfo->_FontWeight = source->_FontWeight;
|
||||
return fontInfo;
|
||||
}
|
||||
|
||||
Json::Value FontConfig::ToJson() const
|
||||
{
|
||||
Json::Value json{ Json::ValueType::objectValue };
|
||||
|
||||
JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace);
|
||||
JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize);
|
||||
JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Layer values from the given json object on top of the existing properties
|
||||
// of this object. For any keys we're expecting to be able to parse in the
|
||||
// given object, we'll parse them and replace our settings with values from
|
||||
// the new json object. Properties that _aren't_ in the json object will _not_
|
||||
// be replaced.
|
||||
// - Optional values that are set to `null` in the json object
|
||||
// will be set to nullopt.
|
||||
// - This is similar to Profile::LayerJson but for FontConfig
|
||||
// Arguments:
|
||||
// - json: an object which should be a partial serialization of a FontConfig object.
|
||||
void FontConfig::LayerJson(const Json::Value& json)
|
||||
{
|
||||
// Legacy users may not have a font object defined in their profile,
|
||||
// so check for that before we decide how to parse this
|
||||
if (json.isMember(JsonKey(FontInfoKey)))
|
||||
{
|
||||
// A font object is defined, use that
|
||||
const auto fontInfoJson = json[JsonKey(FontInfoKey)];
|
||||
JsonUtils::GetValueForKey(fontInfoJson, FontFaceKey, _FontFace);
|
||||
JsonUtils::GetValueForKey(fontInfoJson, FontSizeKey, _FontSize);
|
||||
JsonUtils::GetValueForKey(fontInfoJson, FontWeightKey, _FontWeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No font object is defined
|
||||
JsonUtils::GetValueForKey(json, LegacyFontFaceKey, _FontFace);
|
||||
JsonUtils::GetValueForKey(json, LegacyFontSizeKey, _FontSize);
|
||||
JsonUtils::GetValueForKey(json, LegacyFontWeightKey, _FontWeight);
|
||||
}
|
||||
}
|
||||
|
||||
bool FontConfig::HasAnyOptionSet() const
|
||||
{
|
||||
return HasFontFace() || HasFontSize() || HasFontWeight();
|
||||
}
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::Profile FontConfig::SourceProfile()
|
||||
{
|
||||
return _sourceProfile.get();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*++
|
||||
Copyright (c) Microsoft Corporation
|
||||
Licensed under the MIT license.
|
||||
|
||||
Module Name:
|
||||
- FontConfig
|
||||
|
||||
Abstract:
|
||||
- The implementation of the FontConfig winrt class. Provides settings related
|
||||
to the font settings of the terminal, for the terminal control.
|
||||
|
||||
Author(s):
|
||||
- Pankaj Bhojwani - June 2021
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
#include "FontConfig.g.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "../inc/cppwinrt_utils.h"
|
||||
#include "IInheritable.h"
|
||||
#include <DefaultSettings.h>
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
{
|
||||
struct FontConfig : FontConfigT<FontConfig>, IInheritable<FontConfig>
|
||||
{
|
||||
public:
|
||||
FontConfig(winrt::weak_ref<Profile> sourceProfile);
|
||||
static winrt::com_ptr<FontConfig> CopyFontInfo(const winrt::com_ptr<FontConfig> source, winrt::weak_ref<Profile> sourceProfile);
|
||||
Json::Value ToJson() const;
|
||||
void LayerJson(const Json::Value& json);
|
||||
bool HasAnyOptionSet() const;
|
||||
|
||||
Model::Profile SourceProfile();
|
||||
|
||||
INHERITABLE_SETTING(Model::FontConfig, hstring, FontFace, DEFAULT_FONT_FACE);
|
||||
INHERITABLE_SETTING(Model::FontConfig, int32_t, FontSize, DEFAULT_FONT_SIZE);
|
||||
INHERITABLE_SETTING(Model::FontConfig, Windows::UI::Text::FontWeight, FontWeight, DEFAULT_FONT_WEIGHT);
|
||||
|
||||
private:
|
||||
winrt::weak_ref<Profile> _sourceProfile;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import "Profile.idl";
|
||||
#include "IInheritable.idl.h"
|
||||
|
||||
#define INHERITABLE_FONT_SETTING(Type, Name) \
|
||||
_BASE_INHERITABLE_SETTING(Type, Name); \
|
||||
Microsoft.Terminal.Settings.Model.FontConfig Name##OverrideSource { get; }
|
||||
|
||||
namespace Microsoft.Terminal.Settings.Model
|
||||
{
|
||||
[default_interface] runtimeclass FontConfig {
|
||||
Microsoft.Terminal.Settings.Model.Profile SourceProfile { get; };
|
||||
|
||||
INHERITABLE_FONT_SETTING(String, FontFace);
|
||||
INHERITABLE_FONT_SETTING(Int32, FontSize);
|
||||
INHERITABLE_FONT_SETTING(Windows.UI.Text.FontWeight, FontWeight);
|
||||
}
|
||||
}
|
|
@ -63,6 +63,9 @@
|
|||
<ClInclude Include="AppearanceConfig.h">
|
||||
<DependentUpon>AppearanceConfig.idl</DependentUpon>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FontConfig.h">
|
||||
<DependentUpon>FontConfig.idl</DependentUpon>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EnumMappings.h">
|
||||
<DependentUpon>EnumMappings.idl</DependentUpon>
|
||||
</ClInclude>
|
||||
|
@ -131,6 +134,9 @@
|
|||
<ClCompile Include="AppearanceConfig.cpp">
|
||||
<DependentUpon>AppearanceConfig.idl</DependentUpon>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FontConfig.cpp">
|
||||
<DependentUpon>FontConfig.idl</DependentUpon>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TerminalSettings.cpp">
|
||||
<DependentUpon>TerminalSettings.idl</DependentUpon>
|
||||
</ClCompile>
|
||||
|
@ -163,6 +169,7 @@
|
|||
<Midl Include="KeyChordSerialization.idl" />
|
||||
<Midl Include="AppearanceConfig.idl" />
|
||||
<Midl Include="IAppearanceConfig.idl" />
|
||||
<Midl Include="FontConfig.idl" />
|
||||
</ItemGroup>
|
||||
<!-- ========================= Misc Files ======================== -->
|
||||
<ItemGroup>
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<Midl Include="TerminalSettings.idl" />
|
||||
<Midl Include="AppearanceConfig.idl" />
|
||||
<Midl Include="IAppearanceConfig.idl" />
|
||||
<Midl Include="FontConfig.idl" />
|
||||
<Midl Include="DefaultTerminal.idl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "LegacyProfileGeneratorNamespaces.h"
|
||||
#include "TerminalSettingsSerializationHelpers.h"
|
||||
#include "AppearanceConfig.h"
|
||||
#include "FontConfig.h"
|
||||
|
||||
#include "Profile.g.cpp"
|
||||
|
||||
|
@ -34,9 +35,7 @@ static constexpr std::string_view AltGrAliasingKey{ "altGrAliasing" };
|
|||
|
||||
static constexpr std::string_view ConnectionTypeKey{ "connectionType" };
|
||||
static constexpr std::string_view CommandlineKey{ "commandline" };
|
||||
static constexpr std::string_view FontFaceKey{ "fontFace" };
|
||||
static constexpr std::string_view FontSizeKey{ "fontSize" };
|
||||
static constexpr std::string_view FontWeightKey{ "fontWeight" };
|
||||
static constexpr std::string_view FontInfoKey{ "font" };
|
||||
static constexpr std::string_view AcrylicTransparencyKey{ "acrylicOpacity" };
|
||||
static constexpr std::string_view UseAcrylicKey{ "useAcrylic" };
|
||||
static constexpr std::string_view ScrollbarStateKey{ "scrollbarState" };
|
||||
|
@ -76,9 +75,6 @@ winrt::com_ptr<Profile> Profile::CopySettings(winrt::com_ptr<Profile> source)
|
|||
profile->_UseAcrylic = source->_UseAcrylic;
|
||||
profile->_AcrylicOpacity = source->_AcrylicOpacity;
|
||||
profile->_ScrollState = source->_ScrollState;
|
||||
profile->_FontFace = source->_FontFace;
|
||||
profile->_FontSize = source->_FontSize;
|
||||
profile->_FontWeight = source->_FontWeight;
|
||||
profile->_Padding = source->_Padding;
|
||||
profile->_Commandline = source->_Commandline;
|
||||
profile->_StartingDirectory = source->_StartingDirectory;
|
||||
|
@ -92,8 +88,14 @@ winrt::com_ptr<Profile> Profile::CopySettings(winrt::com_ptr<Profile> source)
|
|||
profile->_ConnectionType = source->_ConnectionType;
|
||||
profile->_Origin = source->_Origin;
|
||||
|
||||
// Copy over the appearance
|
||||
// Copy over the font info
|
||||
const auto weakRefToProfile = weak_ref<Model::Profile>(*profile);
|
||||
winrt::com_ptr<FontConfig> sourceFontInfoImpl;
|
||||
sourceFontInfoImpl.copy_from(winrt::get_self<FontConfig>(source->_FontInfo));
|
||||
auto copiedFontInfo = FontConfig::CopyFontInfo(sourceFontInfoImpl, weakRefToProfile);
|
||||
profile->_FontInfo = *copiedFontInfo;
|
||||
|
||||
// Copy over the appearance
|
||||
winrt::com_ptr<AppearanceConfig> sourceDefaultAppearanceImpl;
|
||||
sourceDefaultAppearanceImpl.copy_from(winrt::get_self<AppearanceConfig>(source->_DefaultAppearance));
|
||||
auto copiedDefaultAppearance = AppearanceConfig::CopyAppearance(sourceDefaultAppearanceImpl, weakRefToProfile);
|
||||
|
@ -315,6 +317,10 @@ void Profile::LayerJson(const Json::Value& json)
|
|||
auto defaultAppearanceImpl = winrt::get_self<implementation::AppearanceConfig>(_DefaultAppearance);
|
||||
defaultAppearanceImpl->LayerJson(json);
|
||||
|
||||
// Font Settings
|
||||
auto fontInfoImpl = winrt::get_self<implementation::FontConfig>(_FontInfo);
|
||||
fontInfoImpl->LayerJson(json);
|
||||
|
||||
// Profile-specific Settings
|
||||
JsonUtils::GetValueForKey(json, NameKey, _Name);
|
||||
JsonUtils::GetValueForKey(json, GuidKey, _Guid);
|
||||
|
@ -328,11 +334,8 @@ void Profile::LayerJson(const Json::Value& json)
|
|||
JsonUtils::GetValueForKey(json, TabTitleKey, _TabTitle);
|
||||
|
||||
// Control Settings
|
||||
JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight);
|
||||
JsonUtils::GetValueForKey(json, ConnectionTypeKey, _ConnectionType);
|
||||
JsonUtils::GetValueForKey(json, CommandlineKey, _Commandline);
|
||||
JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace);
|
||||
JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize);
|
||||
JsonUtils::GetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity);
|
||||
JsonUtils::GetValueForKey(json, UseAcrylicKey, _UseAcrylic);
|
||||
JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle);
|
||||
|
@ -392,6 +395,19 @@ void Profile::_FinalizeInheritance()
|
|||
}
|
||||
}
|
||||
}
|
||||
if (auto fontInfoImpl = get_self<FontConfig>(_FontInfo))
|
||||
{
|
||||
// Clear any existing parents first, we don't want duplicates from any previous
|
||||
// calls to this function
|
||||
fontInfoImpl->ClearParents();
|
||||
for (auto& parent : _parents)
|
||||
{
|
||||
if (auto parentFontInfoImpl = parent->_FontInfo.try_as<FontConfig>())
|
||||
{
|
||||
fontInfoImpl->InsertParent(parentFontInfoImpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig Profile::DefaultAppearance()
|
||||
|
@ -399,6 +415,11 @@ winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig Profile::DefaultA
|
|||
return _DefaultAppearance;
|
||||
}
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::FontConfig Profile::FontInfo()
|
||||
{
|
||||
return _FontInfo;
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Helper function for expanding any environment variables in a user-supplied starting directory and validating the resulting path
|
||||
// Arguments:
|
||||
|
@ -510,11 +531,8 @@ Json::Value Profile::ToJson() const
|
|||
JsonUtils::SetValueForKey(json, TabTitleKey, _TabTitle);
|
||||
|
||||
// Control Settings
|
||||
JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight);
|
||||
JsonUtils::SetValueForKey(json, ConnectionTypeKey, _ConnectionType);
|
||||
JsonUtils::SetValueForKey(json, CommandlineKey, _Commandline);
|
||||
JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace);
|
||||
JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize);
|
||||
JsonUtils::SetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity);
|
||||
JsonUtils::SetValueForKey(json, UseAcrylicKey, _UseAcrylic);
|
||||
JsonUtils::SetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle);
|
||||
|
@ -530,6 +548,13 @@ Json::Value Profile::ToJson() const
|
|||
JsonUtils::SetValueForKey(json, TabColorKey, _TabColor);
|
||||
JsonUtils::SetValueForKey(json, BellStyleKey, _BellStyle);
|
||||
|
||||
// Font settings
|
||||
const auto fontInfoImpl = winrt::get_self<FontConfig>(_FontInfo);
|
||||
if (fontInfoImpl->HasAnyOptionSet())
|
||||
{
|
||||
json[JsonKey(FontInfoKey)] = winrt::get_self<FontConfig>(_FontInfo)->ToJson();
|
||||
}
|
||||
|
||||
if (_UnfocusedAppearance)
|
||||
{
|
||||
json[JsonKey(UnfocusedAppearanceKey)] = winrt::get_self<AppearanceConfig>(_UnfocusedAppearance.value())->ToJson();
|
||||
|
|
|
@ -51,6 +51,7 @@ Author(s):
|
|||
#include "JsonUtils.h"
|
||||
#include <DefaultSettings.h>
|
||||
#include "AppearanceConfig.h"
|
||||
#include "FontConfig.h"
|
||||
|
||||
// fwdecl unittest classes
|
||||
namespace SettingsModelLocalTests
|
||||
|
@ -98,6 +99,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
static guid GetGuidOrGenerateForJson(const Json::Value& json) noexcept;
|
||||
|
||||
Model::IAppearanceConfig DefaultAppearance();
|
||||
Model::FontConfig FontInfo();
|
||||
|
||||
void _FinalizeInheritance() override;
|
||||
|
||||
|
@ -121,9 +123,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
INHERITABLE_SETTING(Model::Profile, double, AcrylicOpacity, 0.5);
|
||||
INHERITABLE_SETTING(Model::Profile, Microsoft::Terminal::Control::ScrollbarState, ScrollState, Microsoft::Terminal::Control::ScrollbarState::Visible);
|
||||
|
||||
INHERITABLE_SETTING(Model::Profile, hstring, FontFace, DEFAULT_FONT_FACE);
|
||||
INHERITABLE_SETTING(Model::Profile, int32_t, FontSize, DEFAULT_FONT_SIZE);
|
||||
INHERITABLE_SETTING(Model::Profile, Windows::UI::Text::FontWeight, FontWeight, DEFAULT_FONT_WEIGHT);
|
||||
INHERITABLE_SETTING(Model::Profile, hstring, Padding, DEFAULT_PADDING);
|
||||
|
||||
INHERITABLE_SETTING(Model::Profile, hstring, Commandline, L"cmd.exe");
|
||||
|
@ -143,6 +142,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
|
||||
private:
|
||||
Model::IAppearanceConfig _DefaultAppearance{ winrt::make<AppearanceConfig>(weak_ref<Model::Profile>(*this)) };
|
||||
Model::FontConfig _FontInfo{ winrt::make<FontConfig>(weak_ref<Model::Profile>(*this)) };
|
||||
static std::wstring EvaluateStartingDirectory(const std::wstring& directory);
|
||||
|
||||
static guid _GenerateGuidForProfile(const hstring& name, const hstring& source) noexcept;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import "IAppearanceConfig.idl";
|
||||
import "FontConfig.idl";
|
||||
#include "IInheritable.idl.h"
|
||||
|
||||
#define INHERITABLE_PROFILE_SETTING(Type, Name) \
|
||||
|
@ -62,15 +63,14 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
INHERITABLE_PROFILE_SETTING(Boolean, UseAcrylic);
|
||||
INHERITABLE_PROFILE_SETTING(Double, AcrylicOpacity);
|
||||
INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.ScrollbarState, ScrollState);
|
||||
INHERITABLE_PROFILE_SETTING(String, FontFace);
|
||||
INHERITABLE_PROFILE_SETTING(Int32, FontSize);
|
||||
INHERITABLE_PROFILE_SETTING(Windows.UI.Text.FontWeight, FontWeight);
|
||||
INHERITABLE_PROFILE_SETTING(String, Padding);
|
||||
INHERITABLE_PROFILE_SETTING(String, Commandline);
|
||||
|
||||
INHERITABLE_PROFILE_SETTING(String, StartingDirectory);
|
||||
String EvaluatedStartingDirectory { get; };
|
||||
|
||||
FontConfig FontInfo { get; };
|
||||
|
||||
IAppearanceConfig DefaultAppearance { get; };
|
||||
INHERITABLE_PROFILE_SETTING(IAppearanceConfig, UnfocusedAppearance);
|
||||
|
||||
|
|
|
@ -260,9 +260,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
_UseAcrylic = profile.UseAcrylic();
|
||||
_TintOpacity = profile.AcrylicOpacity();
|
||||
|
||||
_FontFace = profile.FontFace();
|
||||
_FontSize = profile.FontSize();
|
||||
_FontWeight = profile.FontWeight();
|
||||
_FontFace = profile.FontInfo().FontFace();
|
||||
_FontSize = profile.FontInfo().FontSize();
|
||||
_FontWeight = profile.FontInfo().FontWeight();
|
||||
_Padding = profile.Padding();
|
||||
|
||||
_Commandline = profile.Commandline();
|
||||
|
|
Loading…
Reference in New Issue