Skip to content

Commit

Permalink
Add a information popup about default terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Oct 2, 2021
1 parent e5293b7 commit 752ab6c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@
<data name="CloseOnExitInfoBar.Message" xml:space="preserve">
<value>Termination behavior can be configured in advanced profile settings.</value>
</data>
<data name="SetAsDefaultInfoBar.Message" xml:space="preserve">
<value>Windows Terminal can be set as your default terminal application in your settings.</value>
</data>
<data name="InfoBarDismissButton.Content" xml:space="preserve">
<value>Don't show again</value>
</data>
Expand Down
52 changes: 47 additions & 5 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ namespace winrt::TerminalApp::implementation
_defaultPointerCursor = CoreWindow::GetForCurrentThread().PointerCursor();
}
CATCH_LOG();

if (CascadiaSettings::IsDefaultTerminalAvailable())
{
ShowSetAsDefaultInfoBar();
}
}

// Method Description;
Expand Down Expand Up @@ -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<MUX::Controls::InfoBar>())
{
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
Expand Down Expand Up @@ -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:
// - <none>
// Return Value:
// - <none>
void TerminalPage::_SetAsDefaultDismissHandler(const IInspectable& /*sender*/, const IInspectable& /*args*/) const
{
_DismissMessage(InfoBarMessage::SetAsDefault);
if (const auto infoBar = FindName(L"SetAsDefaultInfoBar").try_as<MUX::Controls::InfoBar>())
{
infoBar.IsOpen(false);
}
}

// Method Description:
// - Checks whether information bar message was dismissed earlier (in the application state)
// Arguments:
Expand Down Expand Up @@ -3342,13 +3377,20 @@ namespace winrt::TerminalApp::implementation
// - <none>
void TerminalPage::_DismissMessage(const InfoBarMessage& message)
{
auto dismissedMessages = ApplicationState::SharedInstance().DismissedMessages();
if (!dismissedMessages)
const auto applicationState = ApplicationState::SharedInstance();
std::vector<InfoBarMessage> 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<InfoBarMessage>();
messages.emplace_back(message);
}

dismissedMessages.Append(message);
ApplicationState::SharedInstance().DismissedMessages(dismissedMessages);
applicationState.DismissedMessages(std::move(messages));
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@
Click="_CloseOnExitInfoDismissHandler" />
</mux:InfoBar.ActionButton>
</mux:InfoBar>

<mux:InfoBar x:Name="SetAsDefaultInfoBar"
x:Uid="SetAsDefaultInfoBar"
x:Load="False"
IsClosable="True"
IsIconVisible="True"
IsOpen="False"
Severity="Informational">
<mux:InfoBar.ActionButton>
<Button x:Uid="InfoBarDismissButton"
Click="_SetAsDefaultDismissHandler" />
</mux:InfoBar.ActionButton>
</mux:InfoBar>
</StackPanel>

<!--
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/ApplicationState.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace Microsoft.Terminal.Settings.Model
enum InfoBarMessage
{
CloseOnExitInfo = 0,
KeyboardServiceWarning
KeyboardServiceWarning,
SetAsDefault,
};

runtimeclass WindowLayout
Expand Down

0 comments on commit 752ab6c

Please sign in to comment.