Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp (C++)

Code before:

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
    ColorSchemes::ColorSchemes()
    {
        InitializeComponent();

        Automation::AutomationProperties::SetName(AddNewButton(), RS_(L"ColorScheme_AddNewButton/Text"));
    }

    void ColorSchemes::OnNavigatedTo(const NavigationEventArgs& e)
    {
        _ViewModel = e.Parameter().as<Editor::ColorSchemesPageViewModel>();
        _ViewModel.CurrentPage(ColorSchemesSubPage::Base);

        _layoutUpdatedRevoker = LayoutUpdated(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) {
            // Only let this succeed once.
            _layoutUpdatedRevoker.revoke();

            ColorSchemeListView().Focus(FocusState::Programmatic);

            for (const auto scheme : _ViewModel.AllColorSchemes())
            {
                if (scheme.IsDefaultScheme())
                {
                    winrt::hstring newName{ fmt::format(L"{} ({})", scheme.Name(), RS_(L"ColorScheme_DefaultTag/Text")) };
                    Automation::AutomationProperties::SetName(ColorSchemeListView().ContainerFromItem(scheme), newName);
                    break;
                }
            }
        });
    }

    void ColorSchemes::AddNew_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
    {
        if (const auto newSchemeVM{ _ViewModel.RequestAddNew() })
        {
            ColorSchemeListView().SelectedItem(newSchemeVM);
            _ViewModel.RequestEditSelectedScheme();
        }
    }

    void ColorSchemes::ListView_PreviewKeyDown(const IInspectable& /*sender*/, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e)
    {
        if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Enter)
        {
            // Treat this as if 'edit' was clicked
            _ViewModel.RequestEditSelectedScheme();
            e.Handled(true);
        }
    }

Review comment (suggestion):
```suggestion
                    const auto newName = fmt::format(L"{} ({})", scheme.Name(), RS_(L"ColorScheme_DefaultTag/Text"));
```

You can also use `{}` instead of `=` if you prefer. This file seems to use a mix of both styles.

WinRT generated functions accept a `winrt::param::hstring` instead of a `winrt::hstring`, the former of which are "borrowed" strings. It allows you to pass a non-hstring string without making any additional copies and is very convenient to use, because any null-terminated string implicitly (!) converts to it. = No casting needed.

Code after:

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
    ColorSchemes::ColorSchemes()
    {
        InitializeComponent();

        Automation::AutomationProperties::SetName(AddNewButton(), RS_(L"ColorScheme_AddNewButton/Text"));
    }

    void ColorSchemes::OnNavigatedTo(const NavigationEventArgs& e)
    {
        _ViewModel = e.Parameter().as<Editor::ColorSchemesPageViewModel>();
        _ViewModel.CurrentPage(ColorSchemesSubPage::Base);

        _layoutUpdatedRevoker = LayoutUpdated(winrt::auto_revoke, [this](auto /*s*/, auto /*e*/) {
            // Only let this succeed once.
            _layoutUpdatedRevoker.revoke();

            ColorSchemeListView().Focus(FocusState::Programmatic);
        });
    }

    void ColorSchemes::AddNew_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
    {
        if (const auto newSchemeVM{ _ViewModel.RequestAddNew() })
        {
            ColorSchemeListView().SelectedItem(newSchemeVM);
            _ViewModel.RequestEditSelectedScheme();
        }
    }

    void ColorSchemes::ListView_PreviewKeyDown(const IInspectable& /*sender*/, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e)
    {
        if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Enter)
        {
            // Treat this as if 'edit' was clicked
            _ViewModel.RequestEditSelectedScheme();
            e.Handled(true);
        }
    }
}