From 5904c58c1a3acce1c9e8217a0a5b26c3868c3847 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 26 Mar 2021 16:32:58 -0500 Subject: [PATCH] This will make @dhowett happy --- .../Resources/en-US/Resources.resw | 10 +++- .../TerminalApp/TerminalAppLib.vcxproj | 8 --- src/cascadia/TerminalApp/TerminalPage.cpp | 57 +++++++++++++++++++ src/cascadia/TerminalApp/TerminalPage.h | 14 ++++- src/cascadia/TerminalApp/TerminalPage.idl | 14 +---- src/cascadia/TerminalApp/TerminalPage.xaml | 11 +--- .../TerminalApp/WindowNameConverter.cpp | 52 ----------------- .../TerminalApp/WindowNameConverter.h | 11 ---- 8 files changed, 80 insertions(+), 97 deletions(-) delete mode 100644 src/cascadia/TerminalApp/WindowNameConverter.cpp delete mode 100644 src/cascadia/TerminalApp/WindowNameConverter.h diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 473690af98a..51a69c4ba0f 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -588,9 +588,13 @@ More options - - Window: {} - {} will be replaced with a number identifying this window + + Window + This is displayed as a label for a number, like "Window: 10" + + + unnamed window + text used to identify when a window hasn't been assigned a name by the user Maximize diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 665058a58df..f368382268b 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -78,10 +78,6 @@ MinMaxCloseControl.xaml - - TerminalPage.idl - Code - PaletteItemTemplateSelector.idl Code @@ -157,10 +153,6 @@ MinMaxCloseControl.xaml - - TerminalPage.idl - Code - PaletteItemTemplateSelector.idl Code diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 41ed47a6148..89f9214134c 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -3387,4 +3387,61 @@ namespace winrt::TerminalApp::implementation } } + // WindowName is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs + // to raise a PropertyChanged for WindowNameForDisplay, instead of + // WindowName. + winrt::hstring TerminalPage::WindowName() const noexcept + { + return _WindowName; + } + void TerminalPage::WindowName(const winrt::hstring& value) + { + if (_WindowName != value) + { + _WindowName = value; + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" }); + } + } + + // WindowId is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs + // to raise a PropertyChanged for WindowIdForDisplay, instead of + // WindowId. + uint64_t TerminalPage::WindowId() const noexcept + { + return _WindowId; + } + void TerminalPage::WindowId(const uint64_t& value) + { + if (_WindowId != value) + { + _WindowId = value; + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowIdForDisplay" }); + } + } + + // Method Description: + // - Returns a label like "Window: 1234" for the ID of this window + // Arguments: + // - + // Return Value: + // - a string for displaying the name of the window. + winrt::hstring TerminalPage::WindowIdForDisplay() const noexcept + { + return winrt::hstring{ fmt::format(L"{}: {}", + std::wstring_view(RS_(L"WindowIdLabel")), + _WindowId) }; + } + + // Method Description: + // - Returns a label like "" when the window has no name, or the name of the window. + // Arguments: + // - + // Return Value: + // - a string for displaying the name of the window. + winrt::hstring TerminalPage::WindowNameForDisplay() const noexcept + { + return _WindowName.empty() ? + winrt::hstring{ fmt::format(L"<{}>", RS_(L"UnnamedWindowName")) } : + _WindowName; + } } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index cb4325dd096..209a0cfd32d 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -86,9 +86,17 @@ namespace winrt::TerminalApp::implementation const bool initial, const winrt::hstring cwd = L""); + // Normally, WindowName and WindowId would be + // WINRT_OBSERVABLE_PROPERTY's, but we want them to raise + // WindowNameForDisplay and WindowIdForDisplay instead + winrt::hstring WindowName() const noexcept; + void WindowName(const winrt::hstring& value); + uint64_t WindowId() const noexcept; + void WindowId(const uint64_t& value); + winrt::hstring WindowIdForDisplay() const noexcept; + winrt::hstring WindowNameForDisplay() const noexcept; + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); - WINRT_OBSERVABLE_PROPERTY(winrt::hstring, WindowName, _PropertyChangedHandlers); - WINRT_OBSERVABLE_PROPERTY(uint64_t, WindowId, _PropertyChangedHandlers); // -------------------------------- WinRT Events --------------------------------- TYPED_EVENT(TitleChanged, IInspectable, winrt::hstring); @@ -130,6 +138,8 @@ namespace winrt::TerminalApp::implementation bool _isInFocusMode{ false }; bool _isFullscreen{ false }; bool _isAlwaysOnTop{ false }; + winrt::hstring _WindowName{}; + uint64_t _WindowId{ 0 }; bool _rearranging; std::optional _rearrangeFrom; diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index 413e9d70ce2..d725d67ca73 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -10,18 +10,6 @@ namespace TerminalApp Windows.Foundation.IAsyncOperation ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog); }; - runtimeclass WindowIdConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - WindowIdConverter(); - }; - - - runtimeclass WindowNameConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - WindowNameConverter(); - }; - - [default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged { TerminalPage(); @@ -37,6 +25,8 @@ namespace TerminalApp void IdentifyWindow(); String WindowName; UInt64 WindowId; + String WindowNameForDisplay { get; }; + String WindowIdForDisplay { get; }; // We cannot use the default XAML APIs because we want to make sure // that there's only one application-global dialog visible at a time, diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 48bcedc92a0..ff2397eaf78 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -10,13 +10,6 @@ the MIT License. See LICENSE in the project root for license information. --> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> - - - - - - - @@ -146,8 +139,8 @@ the MIT License. See LICENSE in the project root for license information. --> + Title="{x:Bind WindowIdForDisplay}" + Subtitle="{x:Bind WindowNameForDisplay}"> diff --git a/src/cascadia/TerminalApp/WindowNameConverter.cpp b/src/cascadia/TerminalApp/WindowNameConverter.cpp deleted file mode 100644 index b782a918735..00000000000 --- a/src/cascadia/TerminalApp/WindowNameConverter.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#include "pch.h" -#include "WindowNameConverter.h" - -#include "WindowIdConverter.g.cpp" -#include "WindowNameConverter.g.cpp" -#include - -using namespace winrt::Windows; -using namespace winrt::Windows::UI::Xaml; -using namespace winrt::Windows::UI::Text; - -namespace winrt::TerminalApp::implementation -{ - Foundation::IInspectable WindowIdConverter::Convert(Foundation::IInspectable const& value, - Windows::UI::Xaml::Interop::TypeName const& /* targetType */, - Foundation::IInspectable const& /* parameter */, - hstring const& /* language */) - { - // Returns a string like "Window: 12345" for the window with ID 12345 - const auto& id = winrt::unbox_value_or(value, 0); - return winrt::box_value(fmt::format(std::wstring_view(RS_(L"WindowIdPrefix")), id)); - } - - Foundation::IInspectable WindowIdConverter::ConvertBack(Foundation::IInspectable const& /*value*/, - Windows::UI::Xaml::Interop::TypeName const& /* targetType */, - Foundation::IInspectable const& /*parameter*/, - hstring const& /* language */) - { - throw hresult_not_implemented(); - } - - Foundation::IInspectable WindowNameConverter::Convert(Foundation::IInspectable const& value, - Windows::UI::Xaml::Interop::TypeName const& /* targetType */, - Foundation::IInspectable const& /* parameter */, - hstring const& /* language */) - { - // Returns the window's name, or "" if a window has no name - const auto& name = winrt::unbox_value_or(value, L""); - return winrt::box_value(name.empty() ? L"" : name); - } - - Foundation::IInspectable WindowNameConverter::ConvertBack(Foundation::IInspectable const& /*value*/, - Windows::UI::Xaml::Interop::TypeName const& /* targetType */, - Foundation::IInspectable const& /*parameter*/, - hstring const& /* language */) - { - throw hresult_not_implemented(); - } -} diff --git a/src/cascadia/TerminalApp/WindowNameConverter.h b/src/cascadia/TerminalApp/WindowNameConverter.h deleted file mode 100644 index 2f2cb229941..00000000000 --- a/src/cascadia/TerminalApp/WindowNameConverter.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#pragma once - -#include "WindowIdConverter.g.h" -#include "WindowNameConverter.g.h" -#include "../inc/cppwinrt_utils.h" - -DECLARE_CONVERTER(winrt::TerminalApp, WindowIdConverter); -DECLARE_CONVERTER(winrt::TerminalApp, WindowNameConverter);