@@ -1743,6 +1743,8 @@ namespace winrt::TerminalApp::implementation
1743
1743
1744
1744
term.ShowWindowChanged ({ get_weak (), &TerminalPage::_ShowWindowChangedHandler });
1745
1745
1746
+ term.SearchMissingCommand ({ get_weak (), &TerminalPage::_SearchMissingCommandHandler });
1747
+
1746
1748
// Don't even register for the event if the feature is compiled off.
1747
1749
if constexpr (Feature_ShellCompletions::IsEnabled ())
1748
1750
{
@@ -1761,6 +1763,12 @@ namespace winrt::TerminalApp::implementation
1761
1763
page->_PopulateContextMenu (weakTerm.get (), sender.try_as <MUX::Controls::CommandBarFlyout>(), true );
1762
1764
}
1763
1765
});
1766
+ term.QuickFixMenu ().Opening ([weak = get_weak (), weakTerm](auto && sender, auto && /* args*/ ) {
1767
+ if (const auto & page{ weak.get () })
1768
+ {
1769
+ page->_PopulateQuickFixMenu (weakTerm.get (), sender.try_as <Controls::MenuFlyout>());
1770
+ }
1771
+ });
1764
1772
}
1765
1773
1766
1774
// Method Description:
@@ -2993,6 +3001,30 @@ namespace winrt::TerminalApp::implementation
2993
3001
ShowWindowChanged.raise (*this , args);
2994
3002
}
2995
3003
3004
+ winrt::fire_and_forget TerminalPage::_SearchMissingCommandHandler (const IInspectable /* sender*/ , const Microsoft::Terminal::Control::SearchMissingCommandEventArgs args)
3005
+ {
3006
+ assert (!Dispatcher ().HasThreadAccess ());
3007
+
3008
+ if (!Feature_QuickFix::IsEnabled ())
3009
+ {
3010
+ co_return ;
3011
+ }
3012
+
3013
+ std::vector<hstring> suggestions;
3014
+ suggestions.reserve (1 );
3015
+ suggestions.emplace_back (fmt::format (L" winget install {}" , args.MissingCommand ()));
3016
+
3017
+ co_await wil::resume_foreground (Dispatcher ());
3018
+
3019
+ auto term = _GetActiveControl ();
3020
+ if (!term)
3021
+ {
3022
+ co_return ;
3023
+ }
3024
+ term.UpdateWinGetSuggestions (single_threaded_vector<hstring>(std::move (suggestions)));
3025
+ term.ShowQuickFixMenu ();
3026
+ }
3027
+
2996
3028
// Method Description:
2997
3029
// - Paste text from the Windows Clipboard to the focused terminal
2998
3030
void TerminalPage::_PasteText ()
@@ -4982,6 +5014,62 @@ namespace winrt::TerminalApp::implementation
4982
5014
makeItem (RS_ (L" TabClose" ), L" \xE711 " , ActionAndArgs{ ShortcutAction::CloseTab, CloseTabArgs{ _GetFocusedTabIndex ().value () } });
4983
5015
}
4984
5016
5017
+ void TerminalPage::_PopulateQuickFixMenu (const TermControl& control,
5018
+ const Controls::MenuFlyout& menu)
5019
+ {
5020
+ if (!control || !menu)
5021
+ {
5022
+ return ;
5023
+ }
5024
+
5025
+ // Helper lambda for dispatching a SendInput ActionAndArgs onto the
5026
+ // ShortcutActionDispatch. Used below to wire up each menu entry to the
5027
+ // respective action. Then clear the quick fix menu.
5028
+ auto weak = get_weak ();
5029
+ auto makeCallback = [weak](const hstring& suggestion) {
5030
+ return [weak, suggestion](auto &&, auto &&) {
5031
+ if (auto page{ weak.get () })
5032
+ {
5033
+ const auto actionAndArgs = ActionAndArgs{ ShortcutAction::SendInput, SendInputArgs{ hstring{ L" \u0003 " } + suggestion } };
5034
+ page->_actionDispatch ->DoAction (actionAndArgs);
5035
+ if (auto ctrl = page->_GetActiveControl ())
5036
+ {
5037
+ ctrl.ClearQuickFix ();
5038
+ }
5039
+ }
5040
+ };
5041
+ };
5042
+
5043
+ auto makeItem = [&menu, &makeCallback](const winrt::hstring& label,
5044
+ const winrt::hstring& icon,
5045
+ const winrt::hstring& suggestion) {
5046
+ MenuFlyoutItem item{};
5047
+
5048
+ if (!icon.empty ())
5049
+ {
5050
+ auto iconElement = UI::IconPathConverter::IconWUX (icon);
5051
+ Automation::AutomationProperties::SetAccessibilityView (iconElement, Automation::Peers::AccessibilityView::Raw);
5052
+ item.Icon (iconElement);
5053
+ }
5054
+
5055
+ item.Text (label);
5056
+ item.Click (makeCallback (suggestion));
5057
+ menu.Items ().Append (item);
5058
+ };
5059
+
5060
+ // Wire up each item to the action that should be performed. By actually
5061
+ // connecting these to actions, we ensure the implementation is
5062
+ // consistent. This also leaves room for customizing this menu with
5063
+ // actions in the future.
5064
+
5065
+ menu.Items ().Clear ();
5066
+ const auto quickFixes = control.CommandHistory ().QuickFixes ();
5067
+ for (const auto & qf : quickFixes)
5068
+ {
5069
+ makeItem (qf, L" \ue74c " , qf);
5070
+ }
5071
+ }
5072
+
4985
5073
// Handler for our WindowProperties's PropertyChanged event. We'll use this
4986
5074
// to pop the "Identify Window" toast when the user renames our window.
4987
5075
winrt::fire_and_forget TerminalPage::_windowPropertyChanged (const IInspectable& /* sender*/ ,
0 commit comments