Skip to content

Commit

Permalink
Introduce ProfileDefaults, CreateNewProfile, default icon
Browse files Browse the repository at this point in the history
This commit is an amalgamation of some of the TSM changes in PR microsoft#8048.
It:
* Introduces CascadiaSettings.CreateNewProfile to add a new profile
* Introduces CascadiaSettings.ProfileDefaults, which returns the
  "defaults" object as a profile
* Fixes the font weight deserializer to work on uint16_ts
* Fixes a property getter in ColorScheme to not be a property getter
* Fixes a reserialization error with default profiles
* Sets a default icon for all profiles (to the C:\ Segoe MDL2 icon)
  • Loading branch information
carlos-zamora authored and mpela81 committed Jan 28, 2021
1 parent 477fb39 commit d182cf3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
29 changes: 29 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,35 @@ winrt::Microsoft::Terminal::Settings::Model::GlobalAppSettings CascadiaSettings:
return *_globals;
}

// Method Description:
// - Get a reference to our profiles.defaults object
// Arguments:
// - <none>
// Return Value:
// - a reference to our profile.defaults object
winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::ProfileDefaults() const
{
return *_userDefaultProfileSettings;
}

// Method Description:
// - Create a new profile based off the default profile settings.
// Arguments:
// - <none>
// Return Value:
// - a reference to the new profile
winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::CreateNewProfile()
{
auto newProfile{ _userDefaultProfileSettings->CreateChild() };
_allProfiles.Append(*newProfile);

// Give the new profile a distinct name so a guid is properly generated
const winrt::hstring newName{ fmt::format(L"Profile {}", _allProfiles.Size()) };
newProfile->Name(newName);

return *newProfile;
}

// Method Description:
// - Gets our list of warnings we found during loading. These are things that we
// knew were bad when we called `_ValidateSettings` last.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

static hstring SettingsPath();
static hstring DefaultSettingsPath();
Model::Profile ProfileDefaults() const;

static winrt::hstring ApplicationDisplayName();
static winrt::hstring ApplicationVersion();

Model::Profile CreateNewProfile();
Model::Profile FindProfile(guid profileGuid) const noexcept;
Model::ColorScheme GetColorSchemeForProfile(const guid profileGuid) const;

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace Microsoft.Terminal.Settings.Model

GlobalAppSettings GlobalSettings { get; };

Profile ProfileDefaults { get; };

Windows.Foundation.Collections.IObservableVector<Profile> AllProfiles { get; };
Windows.Foundation.Collections.IObservableVector<Profile> ActiveProfiles { get; };

Expand All @@ -34,6 +36,7 @@ namespace Microsoft.Terminal.Settings.Model
Windows.Foundation.IReference<SettingsLoadErrors> GetLoadingError { get; };
String GetSerializationErrorMessage { get; };

Profile CreateNewProfile();
Profile FindProfile(Guid profileGuid);
ColorScheme GetColorSchemeForProfile(Guid profileGuid);

Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalSettingsModel/ColorScheme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace Microsoft.Terminal.Settings.Model
Windows.UI.Color SelectionBackground;
Windows.UI.Color CursorColor;

Windows.UI.Color[] Table { get; };
// winrt::com_arrays prevent data binding.
// Instead of representing Table as a property,
// we expose the getter as a function.
Windows.UI.Color[] Table();
void SetColorTableEntry(UInt8 index, Windows.UI.Color value);
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void GlobalAppSettings::DefaultProfile(const winrt::guid& defaultProfile) noexce
{
_validDefaultProfile = true;
_defaultProfile = defaultProfile;
_UnparsedDefaultProfile = Utils::GuidToString(defaultProfile);
}

winrt::guid GlobalAppSettings::DefaultProfile() const
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
GETSET_SETTING(bool, Hidden, false);
GETSET_SETTING(guid, ConnectionType);

GETSET_SETTING(hstring, Icon);
// Default Icon: Segoe MDL2 CommandPrompt icon
GETSET_SETTING(hstring, Icon, L"\uE756");

GETSET_SETTING(CloseOnExitMode, CloseOnExit, CloseOnExitMode::Graceful);
GETSET_SETTING(hstring, TabTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,23 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::CloseOnExitMode)
template<>
struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winrt::Windows::UI::Text::FontWeight> :
public ::Microsoft::Terminal::Settings::Model::JsonUtils::EnumMapper<
unsigned int,
uint16_t,
::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winrt::Windows::UI::Text::FontWeight>>
{
// The original parser used the font weight getters Bold(), Normal(), etc.
// They were both cumbersome and *not constant expressions*
JSON_MAPPINGS(11) = {
pair_type{ "thin", 100u },
pair_type{ "extra-light", 200u },
pair_type{ "light", 300u },
pair_type{ "semi-light", 350u },
pair_type{ "normal", 400u },
pair_type{ "medium", 500u },
pair_type{ "semi-bold", 600u },
pair_type{ "bold", 700u },
pair_type{ "extra-bold", 800u },
pair_type{ "black", 900u },
pair_type{ "extra-black", 950u },
pair_type{ "thin", static_cast<uint16_t>(100u) },
pair_type{ "extra-light", static_cast<uint16_t>(200u) },
pair_type{ "light", static_cast<uint16_t>(300u) },
pair_type{ "semi-light", static_cast<uint16_t>(350u) },
pair_type{ "normal", static_cast<uint16_t>(400u) },
pair_type{ "medium", static_cast<uint16_t>(500u) },
pair_type{ "semi-bold", static_cast<uint16_t>(600u) },
pair_type{ "bold", static_cast<uint16_t>(700u) },
pair_type{ "extra-bold", static_cast<uint16_t>(800u) },
pair_type{ "black", static_cast<uint16_t>(900u) },
pair_type{ "extra-black", static_cast<uint16_t>(950u) },
};

// Override mapping parser to add boolean parsing
Expand Down

0 comments on commit d182cf3

Please sign in to comment.