[Settings UI] Allow renaming a profile (#8837)

This adds a "Name" text box to the Profile page in the Settings UI.
Any changes to the name/icon are propagated to the relevant
NavigationViewItem.

Base Layer does not have a "Name".

## References
#6800 - Settings UI Epic
This commit is contained in:
Carlos Zamora 2021-01-22 15:43:54 -08:00 committed by GitHub
parent 9700598ecb
commit d45cc4c2e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -357,6 +357,25 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
icon.IconSource(iconSource);
profileNavItem.Icon(icon);
// Update the menu item when the icon/name changes
auto weakMenuItem{ make_weak(profileNavItem) };
profile.PropertyChanged([weakMenuItem](const auto&, const WUX::Data::PropertyChangedEventArgs& args) {
if (auto menuItem{ weakMenuItem.get() })
{
const auto& tag{ menuItem.Tag().as<Editor::ProfileViewModel>() };
if (args.PropertyName() == L"Icon")
{
const auto iconSource{ IconPathConverter::IconSourceWUX(tag.Icon()) };
WUX::Controls::IconSourceElement icon;
icon.IconSource(iconSource);
menuItem.Icon(icon);
}
else if (args.PropertyName() == L"Name")
{
menuItem.Content(box_value(tag.Name()));
}
}
});
return profileNavItem;
}

View file

@ -56,6 +56,16 @@ the MIT License. See LICENSE in the project root for license information. -->
<PivotItem x:Uid="Profile_General">
<ScrollViewer>
<StackPanel Style="{StaticResource PivotStackStyle}">
<!--Name-->
<ContentPresenter Visibility="{x:Bind State.Profile.IsBaseLayer, Mode=OneWay, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
Style="{StaticResource SettingContainerStyle}"
Margin="0,0,0,24">
<TextBox x:Uid="Profile_Name"
Text="{x:Bind State.Profile.Name, Mode=TwoWay}"
Style="{StaticResource TextBoxSettingStyle}"/>
</ContentPresenter>
<!--Commandline-->
<ContentPresenter Visibility="{x:Bind State.Profile.IsBaseLayer, Mode=OneWay, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
Style="{StaticResource SettingContainerStyle}"