Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icon override setting for newTabMenu entries #18116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@
"type": "string",
"default": "",
"description": "The name or GUID of the profile to show in this entry"
},
"icon": {
"$ref": "#/$defs/Icon"
}
}
}
Expand Down Expand Up @@ -804,6 +807,9 @@
"type": "string",
"default": "",
"description": "The ID of the action to show in this entry"
},
"icon": {
"$ref": "#/$defs/Icon"
}
}
}
Expand Down
24 changes: 13 additions & 11 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ namespace winrt::TerminalApp::implementation

for (auto&& [profileIndex, remainingProfile] : remainingProfilesEntry.Profiles())
{
items.push_back(_CreateNewTabFlyoutProfile(remainingProfile, profileIndex));
items.push_back(_CreateNewTabFlyoutProfile(remainingProfile, profileIndex, {}));
}

break;
Expand All @@ -1003,7 +1003,7 @@ namespace winrt::TerminalApp::implementation
break;
}

auto profileItem = _CreateNewTabFlyoutProfile(profileEntry.Profile(), profileEntry.ProfileIndex());
auto profileItem = _CreateNewTabFlyoutProfile(profileEntry.Profile(), profileEntry.ProfileIndex(), profileEntry.Icon());
items.push_back(profileItem);
break;
}
Expand All @@ -1013,7 +1013,7 @@ namespace winrt::TerminalApp::implementation
const auto actionId = actionEntry.ActionId();
if (_settings.ActionMap().GetActionByID(actionId))
{
auto actionItem = _CreateNewTabFlyoutAction(actionId);
auto actionItem = _CreateNewTabFlyoutAction(actionId, actionEntry.Icon());
items.push_back(actionItem);
}

Expand All @@ -1028,7 +1028,7 @@ namespace winrt::TerminalApp::implementation
// Method Description:
// - This method creates a flyout menu item for a given profile with the given index.
// It makes sure to set the correct icon, keybinding, and click-action.
WUX::Controls::MenuFlyoutItem TerminalPage::_CreateNewTabFlyoutProfile(const Profile profile, int profileIndex)
WUX::Controls::MenuFlyoutItem TerminalPage::_CreateNewTabFlyoutProfile(const Profile profile, int profileIndex, const winrt::hstring& iconPathOverride)
{
auto profileMenuItem = WUX::Controls::MenuFlyoutItem{};

Expand All @@ -1049,9 +1049,10 @@ namespace winrt::TerminalApp::implementation
auto profileName = profile.Name();
profileMenuItem.Text(profileName);

// If there's an icon set for this profile, set it as the icon for
// this flyout item
const auto& iconPath = profile.EvaluatedIcon();
// If a custom icon path has been specified, set it as the icon for
// this flyout item. Otherwise, if an icon is set for this profile, set that icon
// for this flyout item.
const auto& iconPath = iconPathOverride.empty() ? profile.EvaluatedIcon() : iconPathOverride;
if (!iconPath.empty())
{
const auto icon = _CreateNewTabFlyoutIcon(iconPath);
Expand Down Expand Up @@ -1112,7 +1113,7 @@ namespace winrt::TerminalApp::implementation
// Method Description:
// - This method creates a flyout menu item for a given action
// It makes sure to set the correct icon, keybinding, and click-action.
WUX::Controls::MenuFlyoutItem TerminalPage::_CreateNewTabFlyoutAction(const winrt::hstring& actionId)
WUX::Controls::MenuFlyoutItem TerminalPage::_CreateNewTabFlyoutAction(const winrt::hstring& actionId, const winrt::hstring& iconPathOverride)
{
auto actionMenuItem = WUX::Controls::MenuFlyoutItem{};
const auto action{ _settings.ActionMap().GetActionByID(actionId) };
Expand All @@ -1125,9 +1126,10 @@ namespace winrt::TerminalApp::implementation

actionMenuItem.Text(action.Name());

// If there's an icon set for this action, set it as the icon for
// this flyout item
const auto& iconPath = action.IconPath();
// If a custom icon path has been specified, set it as the icon for
// this flyout item. Otherwise, if an icon is set for this action, set that icon
// for this flyout item.
const auto& iconPath = iconPathOverride.empty() ? action.IconPath() : iconPathOverride;
if (!iconPath.empty())
{
const auto icon = _CreateNewTabFlyoutIcon(iconPath);
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ namespace winrt::TerminalApp::implementation
void _CreateNewTabFlyout();
std::vector<winrt::Windows::UI::Xaml::Controls::MenuFlyoutItemBase> _CreateNewTabFlyoutItems(winrt::Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::NewTabMenuEntry> entries);
winrt::Windows::UI::Xaml::Controls::IconElement _CreateNewTabFlyoutIcon(const winrt::hstring& icon);
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutProfile(const Microsoft::Terminal::Settings::Model::Profile profile, int profileIndex);
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutAction(const winrt::hstring& actionId);
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutProfile(const Microsoft::Terminal::Settings::Model::Profile profile, int profileIndex, const winrt::hstring& iconPathOverride);
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutAction(const winrt::hstring& actionId, const winrt::hstring& iconPathOverride);

void _OpenNewTabDropdown();
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::INewContentArgs& newContentArgs);
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;

static constexpr std::string_view ActionIdKey{ "id" };
static constexpr std::string_view IconKey{ "icon" };

ActionEntry::ActionEntry() noexcept :
ActionEntryT<ActionEntry, NewTabMenuEntry>(NewTabMenuEntryType::Action)
Expand All @@ -22,6 +23,7 @@ Json::Value ActionEntry::ToJson() const
auto json = NewTabMenuEntry::ToJson();

JsonUtils::SetValueForKey(json, ActionIdKey, _ActionId);
JsonUtils::SetValueForKey(json, IconKey, _Icon);

return json;
}
Expand All @@ -31,6 +33,7 @@ winrt::com_ptr<NewTabMenuEntry> ActionEntry::FromJson(const Json::Value& json)
auto entry = winrt::make_self<ActionEntry>();

JsonUtils::GetValueForKey(json, ActionIdKey, entry->_ActionId);
JsonUtils::GetValueForKey(json, IconKey, entry->_Icon);

return entry;
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/ActionEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static com_ptr<NewTabMenuEntry> FromJson(const Json::Value& json);

WINRT_PROPERTY(winrt::hstring, ActionId);
WINRT_PROPERTY(winrt::hstring, Icon);
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/NewTabMenuEntry.idl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ namespace Microsoft.Terminal.Settings.Model

Profile Profile;
Int32 ProfileIndex;
String Icon;
}

[default_interface] runtimeclass ActionEntry : NewTabMenuEntry
{
ActionEntry();

String ActionId;
String Icon;
}

enum FolderEntryInlining
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettingsModel/ProfileEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;

static constexpr std::string_view ProfileKey{ "profile" };
static constexpr std::string_view IconKey{ "icon" };

ProfileEntry::ProfileEntry() noexcept :
ProfileEntry{ winrt::hstring{} }
Expand Down Expand Up @@ -46,6 +47,8 @@ Json::Value ProfileEntry::ToJson() const
JsonUtils::SetValueForKey(json, ProfileKey, _Profile.Guid());
}

JsonUtils::SetValueForKey(json, IconKey, _Icon);

return json;
}

Expand All @@ -54,6 +57,7 @@ winrt::com_ptr<NewTabMenuEntry> ProfileEntry::FromJson(const Json::Value& json)
auto entry = winrt::make_self<ProfileEntry>();

JsonUtils::GetValueForKey(json, ProfileKey, entry->_ProfileName);
JsonUtils::GetValueForKey(json, IconKey, entry->_Icon);

return entry;
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/ProfileEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

WINRT_PROPERTY(Model::Profile, Profile);
WINRT_PROPERTY(int, ProfileIndex);
WINRT_PROPERTY(winrt::hstring, Icon);

private:
winrt::hstring _ProfileName;
Expand Down
Loading