-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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 an action for identifying windows #9523
Changes from 6 commits
1c7da00
97818c6
2ec9415
e13e1e7
136ce6d
ec97c43
fa26f7f
a391455
001f545
9270e0f
1f0dceb
e238daa
27d12a2
9d6f47f
c202257
eaaa204
9f54229
bba09e3
0799a19
1105328
97b4935
765c969
b66503c
b7703d2
d035e50
d64aa61
8b6e0bc
7c775d5
b1b94f6
31cb1b7
5904c58
2ff4c60
ff2ce4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</data> | ||||||
<data name="WindowMaximizeButtonToolTip" xml:space="preserve"> | ||||||
<value>Maximize</value> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,17 +274,9 @@ namespace winrt::TerminalApp::implementation | |
|
||
_isAlwaysOnTop = _settings.GlobalSettings().AlwaysOnTop(); | ||
|
||
// This lambda is a local because there will be more toasts in the | ||
// future that will need the same logic. | ||
auto safeRefocus = [weakThis{ get_weak() }](auto&&, auto&&) { | ||
if (auto page{ weakThis.get() }) | ||
{ | ||
page->_FocusActiveControl(nullptr, nullptr); | ||
} | ||
}; | ||
|
||
_windowIdToast = std::make_unique<Toast>(WindowIdToast()); | ||
WindowIdToast().Closed(safeRefocus); | ||
// DON'T set up Toasts/TeachingTips here. They should be loaded and | ||
// initialized the first time they're opened, in whatever method opens | ||
// them. | ||
|
||
// Setup mouse vanish attributes | ||
SystemParametersInfoW(SPI_GETMOUSEVANISH, 0, &_shouldMouseVanish, false); | ||
|
@@ -3025,8 +3017,8 @@ namespace winrt::TerminalApp::implementation | |
return {}; | ||
} | ||
|
||
void TerminalPage::_FocusActiveControl(const IInspectable& /*sender*/, | ||
const RoutedEventArgs& /*eventArgs*/) | ||
void TerminalPage::_FocusActiveControl(IInspectable /*sender*/, | ||
IInspectable /*eventArgs*/) | ||
{ | ||
// We don't want to set focus on the tab if fly-out is open as it will be closed | ||
// TODO GH#5400: consider checking we are not in the opening state, by hooking both Opening and Open events | ||
|
@@ -3375,19 +3367,81 @@ namespace winrt::TerminalApp::implementation | |
co_await winrt::resume_foreground(Dispatcher()); | ||
if (auto page{ weakThis.get() }) | ||
{ | ||
page->_windowIdToast->Open(); | ||
// If we haven't ever loaded the TeachingTip, then do so now and | ||
// create the toast for it. | ||
if (page->_windowIdToast == nullptr) | ||
{ | ||
if (MUX::Controls::TeachingTip tip{ page->FindName(L"WindowIdToast").try_as<MUX::Controls::TeachingTip>() }) | ||
{ | ||
page->_windowIdToast = std::make_shared<Toast>(tip); | ||
// Make sure to use the weak ref when setting up this | ||
// callback. | ||
tip.Closed({ page->get_weak(), &TerminalPage::_FocusActiveControl }); | ||
} | ||
} | ||
|
||
if (page->_windowIdToast != nullptr) | ||
{ | ||
page->_windowIdToast->Open(); | ||
} | ||
} | ||
} | ||
|
||
// 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" }); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could probably set up a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meh, yea, I decided against that b/c I thought at runtime, that would end up being less performant (raise one event, handle it, raise another), rather than just skipping the step. |
||
|
||
// -------------------------------- WinRT Events --------------------------------- | ||
// Winrt events need a method for adding a callback to the event and removing the callback. | ||
// These macros will define them both for you. | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, UIElement); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FocusModeChanged, _focusModeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FullscreenChanged, _fullscreenChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, AlwaysOnTopChanged, _alwaysOnTopChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, RaiseVisualBell, _raiseVisualBellHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); | ||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTaskbarProgress, _setTaskbarProgressHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable); | ||
// 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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" /> | ||
|
@@ -144,9 +137,10 @@ the MIT License. See LICENSE in the project root for license information. --> | |
dismiss itself if the window is unfocused (In Xaml Islands). This is | ||
tracked by MUX#4382--> | ||
<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}" | ||
Subtitle="{x:Bind WindowNameForDisplay}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So,
The default is |
||
</mux:TeachingTip> | ||
</Grid> | ||
</Page> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait... if we're not using
id
, should we just remove it from the first param in_forAllPeasantsIgnoringTheDead
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mike: writes generic function
Reviewers: is it possibly too generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, I presumed a future user of this helper might want it.