22// Licensed under the MIT license.
33
44#include " pch.h"
5- #include " ActionPaletteItem.h"
6- #include " TabPaletteItem.h"
7- #include " CommandLinePaletteItem.h"
85#include " CommandPalette.h"
6+ #include " CommandPaletteItems.h"
97#include < LibraryResources.h>
108
119#include " CommandPalette.g.cpp"
@@ -233,9 +231,11 @@ namespace winrt::TerminalApp::implementation
233231 }
234232 else if (_currentMode == CommandPaletteMode::ActionMode && filteredCommand != nullptr )
235233 {
236- if (const auto actionPaletteItem{ filteredCommand.Item ().try_as <winrt::TerminalApp::ActionPaletteItem>() })
234+ const auto item{ filteredCommand.Item () };
235+ if (item.Type () == PaletteItemType::Action)
237236 {
238- PreviewAction.raise (*this , actionPaletteItem.Command ());
237+ const auto actionPaletteItem{ winrt::get_self<ActionPaletteItem>(item) };
238+ PreviewAction.raise (*this , actionPaletteItem->Command ());
239239 }
240240 }
241241 else if (_currentMode == CommandPaletteMode::CommandlineMode)
@@ -555,10 +555,11 @@ namespace winrt::TerminalApp::implementation
555555 const auto enteredItem = listViewItem.Content ();
556556 if (const auto filteredCommand{ enteredItem.try_as <winrt::TerminalApp::FilteredCommand>() })
557557 {
558- if (const auto actionPaletteItem{ filteredCommand.Item ().try_as <winrt::TerminalApp::ActionPaletteItem>() })
558+ const auto item{ filteredCommand.Item () };
559+ if (item.Type () == PaletteItemType::Action)
559560 {
560- // immediately preview the hovered command
561- PreviewAction.raise (*this , actionPaletteItem. Command ());
561+ const auto actionPaletteItem{ winrt::get_self<ActionPaletteItem>(item) };
562+ PreviewAction.raise (*this , actionPaletteItem-> Command ());
562563 }
563564 }
564565 }
@@ -589,9 +590,11 @@ namespace winrt::TerminalApp::implementation
589590 {
590591 if (_currentMode == CommandPaletteMode::ActionMode && filteredCommand)
591592 {
592- if (const auto actionPaletteItem{ filteredCommand.Item ().try_as <winrt::TerminalApp::ActionPaletteItem>() })
593+ const auto item{ filteredCommand.Item () };
594+ if (item.Type () == PaletteItemType::Action)
593595 {
594- PreviewAction.raise (*this , actionPaletteItem.Command ());
596+ const auto actionPaletteItem{ winrt::get_self<ActionPaletteItem>(item) };
597+ PreviewAction.raise (*this , actionPaletteItem->Command ());
595598 }
596599 }
597600 }
@@ -617,7 +620,7 @@ namespace winrt::TerminalApp::implementation
617620 const auto selectedCommand = selectedList.GetAt (0 );
618621 if (const auto filteredCmd = selectedCommand.try_as <TerminalApp::FilteredCommand>())
619622 {
620- if (const auto paletteItem = filteredCmd.Item (). try_as <TerminalApp::PaletteItem>() )
623+ if (const auto paletteItem = filteredCmd.Item ())
621624 {
622625 automationPeer.RaiseNotificationEvent (
623626 Automation::Peers::AutomationNotificationKind::ItemAdded,
@@ -652,10 +655,13 @@ namespace winrt::TerminalApp::implementation
652655 if (_nestedActionStack.Size () > 0 )
653656 {
654657 const auto newPreviousAction{ _nestedActionStack.GetAt (_nestedActionStack.Size () - 1 ) };
655- const auto actionPaletteItem{ newPreviousAction.Item ().try_as <winrt::TerminalApp::ActionPaletteItem>() };
656-
657- ParentCommandName (actionPaletteItem.Command ().Name ());
658- _updateCurrentNestedCommands (actionPaletteItem.Command ());
658+ const auto item{ newPreviousAction.Item () };
659+ if (item.Type () == PaletteItemType::Action)
660+ {
661+ const auto actionPaletteItem{ winrt::get_self<ActionPaletteItem>(item) };
662+ ParentCommandName (actionPaletteItem->Command ().Name ());
663+ _updateCurrentNestedCommands (actionPaletteItem->Command ());
664+ }
659665 }
660666 else
661667 {
@@ -757,16 +763,19 @@ namespace winrt::TerminalApp::implementation
757763 }
758764 else if (filteredCommand)
759765 {
760- if (const auto actionPaletteItem{ filteredCommand.Item ().try_as <winrt::TerminalApp::ActionPaletteItem>() })
766+ auto item{ filteredCommand.Item () };
767+ if (item.Type () == PaletteItemType::Action)
761768 {
762- if (actionPaletteItem.Command ().HasNestedCommands ())
769+ const auto actionPaletteItem{ winrt::get_self<ActionPaletteItem>(item) };
770+ auto command{ actionPaletteItem->Command () };
771+ if (command.HasNestedCommands ())
763772 {
764773 // If this Command had subcommands, then don't dispatch the
765774 // action. Instead, display a new list of commands for the user
766775 // to pick from.
767776 _nestedActionStack.Append (filteredCommand);
768- ParentCommandName (actionPaletteItem. Command () .Name ());
769- _updateCurrentNestedCommands (actionPaletteItem. Command () );
777+ ParentCommandName (command .Name ());
778+ _updateCurrentNestedCommands (command );
770779
771780 _updateUIForStackChange ();
772781 }
@@ -785,9 +794,9 @@ namespace winrt::TerminalApp::implementation
785794 // But make an exception for the Toggle Command Palette action: we don't want the dispatch
786795 // make the command palette - that was just closed - visible again.
787796 // All other actions can just be dispatched.
788- if (actionPaletteItem. Command () .ActionAndArgs ().Action () != ShortcutAction::ToggleCommandPalette)
797+ if (command .ActionAndArgs ().Action () != ShortcutAction::ToggleCommandPalette)
789798 {
790- DispatchCommandRequested.raise (*this , actionPaletteItem. Command () );
799+ DispatchCommandRequested.raise (*this , command );
791800 }
792801
793802 TraceLoggingWrite (
@@ -837,9 +846,11 @@ namespace winrt::TerminalApp::implementation
837846 {
838847 if (filteredCommand)
839848 {
840- if (const auto tabPaletteItem{ filteredCommand.Item ().try_as <winrt::TerminalApp::TabPaletteItem>() })
849+ const auto item{ filteredCommand.Item () };
850+ if (item.Type () == PaletteItemType::Tab)
841851 {
842- if (const auto tab{ tabPaletteItem.Tab () })
852+ const auto tabPaletteItem{ winrt::get_self<TabPaletteItem>(item) };
853+ if (const auto tab{ tabPaletteItem->Tab () })
843854 {
844855 SwitchToTabRequested.raise (*this , tab);
845856 }
@@ -867,9 +878,11 @@ namespace winrt::TerminalApp::implementation
867878 TraceLoggingKeyword (MICROSOFT_KEYWORD_MEASURES),
868879 TelemetryPrivacyDataTag (PDT_ProductAndServiceUsage));
869880
870- if (const auto commandLinePaletteItem{ filteredCommand.value ().Item ().try_as <winrt::TerminalApp::CommandLinePaletteItem>() })
881+ const auto item{ filteredCommand->Item () };
882+ if (item.Type () == PaletteItemType::CommandLine)
871883 {
872- CommandLineExecutionRequested.raise (*this , commandLinePaletteItem.CommandLine ());
884+ const auto commandLinePaletteItem{ winrt::get_self<CommandLinePaletteItem>(item) };
885+ CommandLineExecutionRequested.raise (*this , commandLinePaletteItem->CommandLine ());
873886 _close ();
874887 }
875888 }
0 commit comments