Skip to content

Commit

Permalink
This will make @DHowett happy
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 26, 2021
1 parent 31cb1b7 commit 5904c58
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 97 deletions.
10 changes: 7 additions & 3 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,13 @@
<data name="CommandPalette_MoreOptions.[using:Windows.UI.Xaml.Automation]AutomationProperties.HelpText" xml:space="preserve">
<value>More options</value>
</data>
<data name="WindowIdPrefix" xml:space="preserve">
<value>Window: {}</value>
<comment>{} will be replaced with a number identifying this window</comment>
<data name="WindowIdLabel" xml:space="preserve">
<value>Window</value>
<comment>This is displayed as a label for a number, like "Window: 10"</comment>
</data>
<data name="UnnamedWindowName" xml:space="preserve">
<value>unnamed window</value>
<comment>text used to identify when a window hasn't been assigned a name by the user</comment>
</data>
<data name="WindowMaximizeButtonToolTip" xml:space="preserve">
<value>Maximize</value>
Expand Down
8 changes: 0 additions & 8 deletions src/cascadia/TerminalApp/TerminalAppLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
<ClInclude Include="MinMaxCloseControl.h">
<DependentUpon>MinMaxCloseControl.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="WindowNameConverter.h">
<DependentUpon>TerminalPage.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="PaletteItemTemplateSelector.h">
<DependentUpon>PaletteItemTemplateSelector.idl</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -157,10 +153,6 @@
<ClCompile Include="MinMaxCloseControl.cpp">
<DependentUpon>MinMaxCloseControl.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="WindowNameConverter.cpp">
<DependentUpon>TerminalPage.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="PaletteItemTemplateSelector.cpp">
<DependentUpon>PaletteItemTemplateSelector.idl</DependentUpon>
<SubType>Code</SubType>
Expand Down
57 changes: 57 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// - <none>
// 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 "<unnamed window>" when the window has no name, or the name of the window.
// Arguments:
// - <none>
// 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;
}
}
14 changes: 12 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<int> _rearrangeFrom;
Expand Down
14 changes: 2 additions & 12 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ namespace TerminalApp
Windows.Foundation.IAsyncOperation<Windows.UI.Xaml.Controls.ContentDialogResult> 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();
Expand All @@ -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,
Expand Down
11 changes: 2 additions & 9 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Page.Resources>
<ResourceDictionary>
<local:WindowIdConverter x:Key="WindowIdConverter"/>
<local:WindowNameConverter x:Key="WindowNameConverter"/>
</ResourceDictionary>
</Page.Resources>

<Grid x:Name="Root" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -146,8 +139,8 @@ the MIT License. See LICENSE in the project root for license information. -->
<mux:TeachingTip x:Name="WindowIdToast"
x:Load="False"
IsLightDismissEnabled="True"
Title="{x:Bind WindowId, Mode=OneWay, Converter={StaticResource WindowIdConverter}}"
Subtitle="{x:Bind WindowName, Mode=OneWay, Converter={StaticResource WindowNameConverter}}">
Title="{x:Bind WindowIdForDisplay}"

This comment was marked as outdated.

Copy link
@DHowett

DHowett Mar 26, 2021

Member

youj're right, i love it!

Subtitle="{x:Bind WindowNameForDisplay}">
</mux:TeachingTip>
</Grid>
</Page>
52 changes: 0 additions & 52 deletions src/cascadia/TerminalApp/WindowNameConverter.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/cascadia/TerminalApp/WindowNameConverter.h

This file was deleted.

0 comments on commit 5904c58

Please sign in to comment.