Skip to content
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 a close button to the Snippets pane #17528

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,10 @@
<data name="ActionSaveFailedToast.Title" xml:space="preserve">
<value>Action save failed</value>
</data>
<data name="CloseSnippetsPaneButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Close pane</value>
</data>
<data name="CloseSnippetsPaneButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Close pane</value>
</data>
</root>
7 changes: 6 additions & 1 deletion src/cascadia/TerminalApp/SnippetsPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace winrt::TerminalApp::implementation

winrt::WUX::Media::Brush SnippetsPaneContent::BackgroundBrush()
{
static const auto key = winrt::box_value(L"UnfocusedBorderBrush");
static const auto key = winrt::box_value(L"SettingsUiTabBrush");
return ThemeLookup(WUX::Application::Current().Resources(),
_settings.GlobalSettings().CurrentTheme().RequestedTheme(),
key)
Expand Down Expand Up @@ -138,6 +138,11 @@ namespace winrt::TerminalApp::implementation
_runCommand(taskVM->Command());
}
}
void SnippetsPaneContent::_closePaneClick(const Windows::Foundation::IInspectable& /*sender*/,
const Windows::UI::Xaml::RoutedEventArgs&)
{
Close();
}

// Called when one of the items in the list is tapped, or enter/space is
// pressed on it while focused. Notably, this isn't the Tapped event - it
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/SnippetsPaneContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::Foundation::Collections::IObservableVector<TerminalApp::FilteredTask> _allTasks{ nullptr };

void _runCommandButtonClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&);
void _closePaneClick(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs&);
void _filterTextChanged(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);

void _updateFilteredCommands();
Expand Down
21 changes: 16 additions & 5 deletions src/cascadia/TerminalApp/SnippetsPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,22 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock x:Name="_title"
x:Uid="SnippetPaneTitle"
Grid.Row="0"
Margin="4"
FontSize="24" />
<Grid Grid.Row="0"
Margin="4"
HorizontalAlignment="Stretch">
<TextBlock x:Name="_title"
x:Uid="SnippetPaneTitle"
HorizontalAlignment="Left"
FontSize="24" />
<Button x:Uid="CloseSnippetsPaneButton" HorizontalAlignment="Right" Click="_closePaneClick">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Button x:Uid="CloseSnippetsPaneButton" HorizontalAlignment="Right" Click="_closePaneClick">
<Button x:Uid="CloseSnippetsPaneButton" HorizontalAlignment="Right" Click="Close">

does this work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, cause Close() doesn't take the two arguments needed for a Click handler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd thought the XAML compiler was flexible and used metadata to determine the arity of the event handler, but it appears I had mixed it up with something else.


<Button.Content>
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE8BB;" />
</Button.Content>
</Button>
</Grid>

<TextBlock Grid.Row="1"
Margin="8,16,8,8"
Expand Down
29 changes: 18 additions & 11 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3311,18 +3311,22 @@ namespace winrt::TerminalApp::implementation
// Prevent the user from opening a bunch of snippets panes.
//
// Look at the focused tab, and if it already has one, then just focus it.
const bool found = _GetFocusedTab().try_as<TerminalTab>()->GetRootPane()->WalkTree([](const auto& p) -> bool {
if (const auto& snippets{ p->GetContent().try_as<SnippetsPaneContent>() })
if (const auto& focusedTab{ _GetFocusedTab() })
{
const auto rootPane{ focusedTab.try_as<TerminalTab>()->GetRootPane() };
const bool found = rootPane == nullptr ? false : rootPane->WalkTree([](const auto& p) -> bool {
if (const auto& snippets{ p->GetContent().try_as<SnippetsPaneContent>() })
{
snippets->Focus(FocusState::Programmatic);
return true;
}
return false;
});
// Bail out if we already found one.
if (found)
{
snippets->Focus(FocusState::Programmatic);
return true;
return nullptr;
}
return false;
});
// Bail out if we already found one.
if (found)
{
return nullptr;
}

const auto& tasksContent{ winrt::make_self<SnippetsPaneContent>() };
Expand Down Expand Up @@ -4687,7 +4691,10 @@ namespace winrt::TerminalApp::implementation
{
const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
bgColor = ThemeColor::ColorFromBrush(themeBrush);
TitlebarBrush(themeBrush);
// If the tab content returned nullptr for the terminalBrush, we
// _don't_ want to use it as the tab row background. We want to just
// use the default tab row background.
TitlebarBrush(themeBrush ? themeBrush : backgroundSolidBrush);
}
else
{
Expand Down
Loading