Skip to content

Commit 341bb4f

Browse files
authored
Enable moving back to the root level in the command palette (#8051)
This commit adds functionality so that users can move back from sub menu whenever they want. As a result, users no longer have to close command palette and open it again to get all commands again. Closes #7910
1 parent c0c2329 commit 341bb4f

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

src/cascadia/TerminalApp/CommandPalette.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,25 @@ namespace winrt::TerminalApp::implementation
428428
_dispatchCommand(e.ClickedItem().try_as<Command>());
429429
}
430430

431+
// Method Description:
432+
// This event is called when the user clicks on an ChevronLeft button right
433+
// next to the ParentCommandName (e.g. New Tab...) above the subcommands list.
434+
// It'll go up a level when the users click the button.
435+
// Arguments:
436+
// - sender: the button that got clicked
437+
// Return Value:
438+
// - <none>
439+
void CommandPalette::_moveBackButtonClicked(Windows::Foundation::IInspectable const& /*sender*/,
440+
Windows::UI::Xaml::RoutedEventArgs const&)
441+
{
442+
_nestedActionStack.Clear();
443+
ParentCommandName(L"");
444+
_currentNestedCommands.Clear();
445+
_searchBox().Focus(FocusState::Programmatic);
446+
_updateFilteredActions();
447+
_filteredActionsView().SelectedIndex(0);
448+
}
449+
431450
// Method Description:
432451
// - This is called when the user selects a command with subcommands. It
433452
// will update our UI to now display the list of subcommands instead, and

src/cascadia/TerminalApp/CommandPalette.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace winrt::TerminalApp::implementation
8181

8282
void _listItemClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::ItemClickEventArgs const& e);
8383

84+
void _moveBackButtonClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const&);
85+
8486
void _updateFilteredActions();
8587

8688
std::vector<Microsoft::Terminal::Settings::Model::Command> _collectFilteredActions();

src/cascadia/TerminalApp/CommandPalette.xaml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,36 @@ the MIT License. See LICENSE in the project root for license information. -->
186186
>
187187
</TextBlock>
188188

189-
<TextBlock
190-
Padding="16, 0, 16, 4"
191-
x:Name="_parentCommandText"
192-
FontStyle="Italic"
193-
Visibility="{x:Bind ParentCommandName,
194-
Mode=OneWay,
195-
Converter={StaticResource ParentCommandVisibilityConverter}}"
196-
Grid.Row="1"
197-
Text="{x:Bind ParentCommandName, Mode=OneWay}">
198-
</TextBlock>
189+
<StackPanel Orientation="Horizontal"
190+
Padding="16, 0, 16, 4"
191+
Grid.Row="1"
192+
Visibility="{x:Bind ParentCommandName,
193+
Mode=OneWay,
194+
Converter={StaticResource ParentCommandVisibilityConverter}}">
195+
196+
<Button
197+
Background="Transparent"
198+
x:Name="_parentCommandBackButton"
199+
x:Uid="ParentCommandBackButton"
200+
Click="_moveBackButtonClicked"
201+
ClickMode="Press"
202+
VerticalAlignment="Center">
203+
<FontIcon
204+
FontSize="12"
205+
FontFamily="Segoe MDL2 Assets"
206+
Glyph="&#xE76b;">
207+
</FontIcon>
208+
</Button>
209+
210+
<TextBlock
211+
Padding="16, 0, 16, 4"
212+
x:Name="_parentCommandText"
213+
FontStyle="Italic"
214+
Grid.Row="1"
215+
Text="{x:Bind ParentCommandName, Mode=OneWay}"
216+
VerticalAlignment="Center">
217+
</TextBlock>
218+
</StackPanel>
199219

200220
<TextBlock
201221
Padding="16"

src/cascadia/TerminalApp/Resources/en-US/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,10 @@
482482
<data name="FailedToWriteToSettings" xml:space="preserve">
483483
<value>We could not write to your settings file. Check the permissions on that file to ensure that the read-only flag is not set and that write access is granted.</value>
484484
</data>
485+
<data name="ParentCommandBackButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
486+
<value>Back</value>
487+
</data>
488+
<data name="ParentCommandBackButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
489+
<value>Back</value>
490+
</data>
485491
</root>

0 commit comments

Comments
 (0)