Skip to content

Commit

Permalink
allow setting the icon to clear the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Oct 13, 2023
1 parent 10d9157 commit 77fb50a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ Model::Profile CascadiaSettings::DuplicateProfile(const Model::Profile& source)
// These aren't in MTSM_PROFILE_SETTINGS because they're special
DUPLICATE_SETTING_MACRO(TabColor);
DUPLICATE_SETTING_MACRO(Padding);
DUPLICATE_SETTING_MACRO(Icon);

{
const auto font = source.FontInfo();
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ Author(s):
X(hstring, StartingDirectory, "startingDirectory") \
X(bool, SuppressApplicationTitle, "suppressApplicationTitle", false) \
X(guid, ConnectionType, "connectionType") \
X(hstring, Icon, "icon", L"\uE756") \
X(CloseOnExitMode, CloseOnExit, "closeOnExit", CloseOnExitMode::Automatic) \
X(hstring, TabTitle, "tabTitle") \
X(Model::BellStyle, BellStyle, "bellStyle", BellStyle::Audible) \
Expand Down
19 changes: 19 additions & 0 deletions src/cascadia/TerminalSettingsModel/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static constexpr std::string_view NameKey{ "name" };
static constexpr std::string_view GuidKey{ "guid" };
static constexpr std::string_view SourceKey{ "source" };
static constexpr std::string_view HiddenKey{ "hidden" };
static constexpr std::string_view IconKey{ "icon" };

static constexpr std::string_view FontInfoKey{ "font" };
static constexpr std::string_view PaddingKey{ "padding" };
Expand Down Expand Up @@ -106,6 +107,7 @@ winrt::com_ptr<Profile> Profile::CopySettings() const
profile->_Hidden = _Hidden;
profile->_TabColor = _TabColor;
profile->_Padding = _Padding;
profile->_Icon = _Icon;

profile->_Origin = _Origin;
profile->_FontInfo = *fontInfo;
Expand Down Expand Up @@ -172,6 +174,7 @@ void Profile::LayerJson(const Json::Value& json)
JsonUtils::GetValueForKey(json, GuidKey, _Guid);
JsonUtils::GetValueForKey(json, HiddenKey, _Hidden);
JsonUtils::GetValueForKey(json, SourceKey, _Source);
JsonUtils::GetValueForKey(json, IconKey, _Icon);

// Padding was never specified as an integer, but it was a common working mistake.
// Allow it to be permissive.
Expand Down Expand Up @@ -314,6 +317,7 @@ Json::Value Profile::ToJson() const
JsonUtils::SetValueForKey(json, GuidKey, writeBasicSettings ? Guid() : _Guid);
JsonUtils::SetValueForKey(json, HiddenKey, writeBasicSettings ? Hidden() : _Hidden);
JsonUtils::SetValueForKey(json, SourceKey, writeBasicSettings ? Source() : _Source);
JsonUtils::SetValueForKey(json, IconKey, writeBasicSettings ? Icon() : _Icon);

// PermissiveStringConverter is unnecessary for serialization
JsonUtils::SetValueForKey(json, PaddingKey, _Padding);
Expand All @@ -338,6 +342,21 @@ Json::Value Profile::ToJson() const

return json;
}

// This is the implementation for and INHERITABLE_SETTING, but with one addition
// in the setter. We want to make sure to clear out our cached icon, so that we
// can re-evaluate it as it changes in the SUI.
void Profile::Icon(const winrt::hstring& value)
{
_evaluatedIcon = std::nullopt;
_Icon = value;
}
winrt::hstring Profile::Icon() const
{
const auto val{ _getIconImpl() };
return val ? *val : hstring{ L"\uE756" };
}

winrt::hstring Profile::EvaluatedIcon()
{
// We cache the result here, so we don't search the path for the exe every time.
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalSettingsModel/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void _FinalizeInheritance() override;

// Special fields
hstring Icon() const;
void Icon(const hstring& value);

WINRT_PROPERTY(bool, Deleted, false);
WINRT_PROPERTY(OriginTag, Origin, OriginTag::None);
WINRT_PROPERTY(guid, Updates);
Expand All @@ -123,7 +126,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::Profile, bool, Hidden, false);
INHERITABLE_SETTING(Model::Profile, guid, Guid, _GenerateGuidForProfile(Name(), Source()));
INHERITABLE_SETTING(Model::Profile, hstring, Padding, DEFAULT_PADDING);
// Icon is _very special_ because we want to customize its setter
_BASE_INHERITABLE_SETTING(Model::Profile, std::optional<hstring>, Icon, L"\uE756");

This comment has been minimized.

Copy link
@DHowett

DHowett Oct 17, 2023

Member

aaaaagh but i get it


public:
#define PROFILE_SETTINGS_INITIALIZE(type, name, jsonKey, ...) \
INHERITABLE_SETTING(Model::Profile, type, name, ##__VA_ARGS__)
MTSM_PROFILE_SETTINGS(PROFILE_SETTINGS_INITIALIZE)
Expand Down

0 comments on commit 77fb50a

Please sign in to comment.