Provide the CloseWindow warning experience for the 'X' button (#3049)
Related to #1589.
This commit is contained in:
parent
200e90d1c6
commit
82dd0b978a
|
@ -582,6 +582,22 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Used to tell the app that the 'X' button has been clicked and
|
||||
// the user wants to close the app. We kick off the close warning
|
||||
// experience.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void App::WindowCloseButtonClicked()
|
||||
{
|
||||
if (_root)
|
||||
{
|
||||
_root->CloseWindow();
|
||||
}
|
||||
}
|
||||
|
||||
// Methods that proxy typed event handlers through TerminalPage
|
||||
winrt::event_token App::SetTitleBarContent(Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement> const& handler)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace winrt::TerminalApp::implementation
|
|||
hstring Title();
|
||||
void TitlebarClicked();
|
||||
|
||||
void WindowCloseButtonClicked();
|
||||
|
||||
// -------------------------------- WinRT Events ---------------------------------
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace TerminalApp
|
|||
Windows.Foundation.Point GetLaunchDimensions(UInt32 dpi);
|
||||
Boolean GetShowTabsInTitlebar();
|
||||
void TitlebarClicked();
|
||||
void WindowCloseButtonClicked();
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<Object, Windows.UI.Xaml.UIElement> SetTitleBarContent;
|
||||
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace winrt::TerminalApp::implementation
|
|||
void TerminalPage::_HandleCloseWindow(const IInspectable& /*sender*/,
|
||||
const TerminalApp::ActionEventArgs& args)
|
||||
{
|
||||
_CloseWindow();
|
||||
CloseWindow();
|
||||
args.Handled(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -823,9 +823,9 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
|
||||
// Method Description:
|
||||
// - Close the terminal app with keys. If there is more
|
||||
// - Close the terminal app. If there is more
|
||||
// than one tab opened, show a warning dialog.
|
||||
void TerminalPage::_CloseWindow()
|
||||
void TerminalPage::CloseWindow()
|
||||
{
|
||||
if (_tabs.size() > 1)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
void TitlebarClicked();
|
||||
|
||||
void CloseWindow();
|
||||
|
||||
// -------------------------------- WinRT Events ---------------------------------
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
|
||||
|
@ -94,7 +96,6 @@ namespace winrt::TerminalApp::implementation
|
|||
void _SetFocusedTabIndex(int tabIndex);
|
||||
void _CloseFocusedTab();
|
||||
void _CloseFocusedPane();
|
||||
void _CloseWindow();
|
||||
void _CloseAllTabs();
|
||||
|
||||
// Todo: add more event implementations here
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
void TitlebarControl::Close_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
|
||||
{
|
||||
::PostQuitMessage(0);
|
||||
::PostMessage(_window, WM_SYSCOMMAND, SC_CLOSE, 0);
|
||||
}
|
||||
|
||||
void TitlebarControl::SetWindowVisualState(WindowVisualState visualState)
|
||||
|
|
|
@ -70,6 +70,10 @@ void AppHost::Initialize()
|
|||
_app.SetTitleBarContent({ this, &AppHost::_UpdateTitleBarContent });
|
||||
}
|
||||
|
||||
// Register the 'X' button of the window for a warning experience of multiple
|
||||
// tabs opened, this is consistent with Alt+F4 closing
|
||||
_window->WindowCloseButtonClicked([this]() { _app.WindowCloseButtonClicked(); });
|
||||
|
||||
// Add an event handler to plumb clicks in the titlebar area down to the
|
||||
// application layer.
|
||||
_window->DragRegionClicked([this]() { _app.TitlebarClicked(); });
|
||||
|
|
|
@ -198,6 +198,14 @@ void IslandWindow::OnSize(const UINT width, const UINT height)
|
|||
// key that does not correspond to any mnemonic or accelerator key,
|
||||
return MAKELRESULT(0, MNC_CLOSE);
|
||||
}
|
||||
case WM_CLOSE:
|
||||
{
|
||||
// If the user wants to close the app by clicking 'X' button,
|
||||
// we hand off the close experience to the app layer. If all the tabs
|
||||
// are closed, the window will be closed as well.
|
||||
_windowCloseButtonClickedHandler();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: handle messages here...
|
||||
|
@ -285,3 +293,4 @@ void IslandWindow::UpdateTheme(const winrt::Windows::UI::Xaml::ElementTheme& req
|
|||
}
|
||||
|
||||
DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
|
||||
DEFINE_EVENT(IslandWindow, WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
#pragma endregion
|
||||
|
||||
DECLARE_EVENT(DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
|
||||
DECLARE_EVENT(WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
|
||||
|
||||
protected:
|
||||
void ForceResize()
|
||||
|
|
Loading…
Reference in a new issue