From 752ab6ce713a7c0caf9beddc6447d538bd1f917f Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Sat, 2 Oct 2021 02:06:45 +0200 Subject: [PATCH] Add a information popup about default terminals --- .../Resources/en-US/Resources.resw | 3 ++ src/cascadia/TerminalApp/TerminalPage.cpp | 52 +++++++++++++++++-- src/cascadia/TerminalApp/TerminalPage.h | 2 + src/cascadia/TerminalApp/TerminalPage.xaml | 13 +++++ .../ApplicationState.idl | 3 +- 5 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 55e51abbbc4..2727d4889ac 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -718,6 +718,9 @@ Termination behavior can be configured in advanced profile settings. + + Windows Terminal can be set as your default terminal application in your settings. + Don't show again diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 25140362de8..119400f9260 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -287,6 +287,11 @@ namespace winrt::TerminalApp::implementation _defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor(); } CATCH_LOG(); + + if (CascadiaSettings::IsDefaultTerminalAvailable()) + { + ShowSetAsDefaultInfoBar(); + } } // Method Description; @@ -2893,6 +2898,20 @@ namespace winrt::TerminalApp::implementation } } + // Method Description: + // - Displays a dialog stating the "Touch Keyboard and Handwriting Panel + // Service" is disabled. + void TerminalPage::ShowSetAsDefaultInfoBar() const + { + if (!_IsMessageDismissed(InfoBarMessage::SetAsDefault)) + { + if (const auto infoBar = FindName(L"SetAsDefaultInfoBar").try_as()) + { + infoBar.IsOpen(true); + } + } + } + // Function Description: // - Helper function to get the OS-localized name for the "Touch Keyboard // and Handwriting Panel Service". If we can't open up the service for any @@ -3313,6 +3332,22 @@ namespace winrt::TerminalApp::implementation } } + // Method Description: + // - Persists the user's choice not to show the information bar warning about "Windows Terminal can be set as your default terminal application" + // Then hides this information buffer. + // Arguments: + // - + // Return Value: + // - + void TerminalPage::_SetAsDefaultDismissHandler(const IInspectable& /*sender*/, const IInspectable& /*args*/) const + { + _DismissMessage(InfoBarMessage::SetAsDefault); + if (const auto infoBar = FindName(L"SetAsDefaultInfoBar").try_as()) + { + infoBar.IsOpen(false); + } + } + // Method Description: // - Checks whether information bar message was dismissed earlier (in the application state) // Arguments: @@ -3342,13 +3377,20 @@ namespace winrt::TerminalApp::implementation // - void TerminalPage::_DismissMessage(const InfoBarMessage& message) { - auto dismissedMessages = ApplicationState::SharedInstance().DismissedMessages(); - if (!dismissedMessages) + const auto applicationState = ApplicationState::SharedInstance(); + std::vector messages; + + if (const auto values = applicationState.DismissedMessages()) + { + messages.resize(values.Size()); + values.GetMany(0, messages); + } + + if (std::none_of(messages.begin(), messages.end(), [&](const auto& m) { return m == message; })) { - dismissedMessages = winrt::single_threaded_vector(); + messages.emplace_back(message); } - dismissedMessages.Append(message); - ApplicationState::SharedInstance().DismissedMessages(dismissedMessages); + applicationState.DismissedMessages(std::move(messages)); } } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 26332453a66..6fdc88d1585 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -95,6 +95,7 @@ namespace winrt::TerminalApp::implementation winrt::TerminalApp::TaskbarState TaskbarState() const; void ShowKeyboardServiceWarning() const; + void ShowSetAsDefaultInfoBar() const; winrt::hstring KeyboardServiceDisabledText(); winrt::fire_and_forget IdentifyWindow(); @@ -403,6 +404,7 @@ namespace winrt::TerminalApp::implementation winrt::fire_and_forget _ConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args) const; void _CloseOnExitInfoDismissHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args) const; void _KeyboardServiceWarningInfoDismissHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args) const; + void _SetAsDefaultDismissHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args) const; static bool _IsMessageDismissed(const winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage& message); static void _DismissMessage(const winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage& message); diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index b6a4676dd19..f5e5b7df4b1 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -141,6 +141,19 @@ Click="_CloseOnExitInfoDismissHandler" /> + + + +