@@ -1672,8 +1672,6 @@ namespace winrt::TerminalApp::implementation
1672
1672
1673
1673
term.ShowWindowChanged ({ get_weak (), &TerminalPage::_ShowWindowChangedHandler });
1674
1674
1675
- // term.SearchMissingCommand({ get_weak(), &TerminalPage::_SearchMissingCommandHandler });
1676
-
1677
1675
// Don't even register for the event if the feature is compiled off.
1678
1676
if constexpr (Feature_ShellCompletions::IsEnabled ())
1679
1677
{
@@ -2956,191 +2954,6 @@ namespace winrt::TerminalApp::implementation
2956
2954
ShowWindowChanged.raise (*this , args);
2957
2955
}
2958
2956
2959
- void TerminalPage::_SearchMissingCommandHandler (const IInspectable sender, const winrt::Microsoft::Terminal::Control::SearchMissingCommandEventArgs args)
2960
- {
2961
- #if 0
2962
- static constexpr CLSID CLSID_PackageManager = { 0xC53A4F16, 0x787E, 0x42A4, 0xB3, 0x04, 0x29, 0xEF, 0xFB, 0x4B, 0xF5, 0x97 }; //C53A4F16-787E-42A4-B304-29EFFB4BF597
2963
- static constexpr CLSID CLSID_FindPackagesOptions = { 0x572DED96, 0x9C60, 0x4526, { 0x8F, 0x92, 0xEE, 0x7D, 0x91, 0xD3, 0x8C, 0x1A } }; //572DED96-9C60-4526-8F92-EE7D91D38C1A
2964
- static constexpr CLSID CLSID_PackageMatchFilter = { 0xD02C9DAF, 0x99DC, 0x429C, { 0xB5, 0x03, 0x4E, 0x50, 0x4E, 0x4A, 0xB0, 0x00 } }; //D02C9DAF-99DC-429C-B503-4E504E4AB000
2965
-
2966
- static constexpr unsigned int maxSuggestions = 5;
2967
- bool tooManySuggestions = false;
2968
-
2969
- // TODO CARLOS: this is where we fail! "Class not registered" error
2970
- PackageManager pkgManager = winrt::create_instance<PackageManager>(CLSID_PackageManager, CLSCTX_ALL);
2971
- auto catalogRef = pkgManager.GetPredefinedPackageCatalog(PredefinedPackageCatalog::OpenWindowsCatalog);
2972
- auto connectResult = catalogRef.Connect();
2973
- int retryCount = 0;
2974
- while (connectResult.Status() != ConnectResultStatus::Ok && retryCount < 3)
2975
- {
2976
- connectResult = catalogRef.Connect();
2977
- ++retryCount;
2978
- }
2979
- if (connectResult.Status() != ConnectResultStatus::Ok)
2980
- {
2981
- return;
2982
- }
2983
- auto catalog = connectResult.PackageCatalog();
2984
-
2985
- // Perform the query (search by command)
2986
- auto packageMatchFilter = winrt::create_instance<PackageMatchFilter>(CLSID_PackageMatchFilter, CLSCTX_ALL);
2987
- auto findPackagesOptions = winrt::create_instance<FindPackagesOptions>(CLSID_FindPackagesOptions, CLSCTX_ALL);
2988
-
2989
- // Helper lambda to apply a filter to the query
2990
- auto applyPackageMatchFilter = [&packageMatchFilter, &findPackagesOptions](PackageMatchField field, PackageFieldMatchOption matchOption, hstring query) {
2991
- // Configure filter
2992
- packageMatchFilter.Field(field);
2993
- packageMatchFilter.Option(matchOption);
2994
- packageMatchFilter.Value(query);
2995
-
2996
- // Apply filter
2997
- findPackagesOptions.ResultLimit(maxSuggestions + 1u);
2998
- findPackagesOptions.Filters().Clear();
2999
- findPackagesOptions.Filters().Append(packageMatchFilter);
3000
- };
3001
-
3002
- // Helper lambda to retrieve the best matching package(s) from the query's result
3003
- auto tryGetBestMatchingPackage = [&tooManySuggestions](IVectorView<MatchResult> matches) {
3004
- std::vector<CatalogPackage> results;
3005
- results.reserve(std::min(matches.Size(), maxSuggestions));
3006
- if (matches.Size() == 1)
3007
- {
3008
- // One match --> return the package
3009
- results.emplace_back(matches.GetAt(0).CatalogPackage());
3010
- }
3011
- else if (matches.Size() > 1)
3012
- {
3013
- // Multiple matches --> display top 5 matches (prioritize best matches first)
3014
- std::queue<CatalogPackage> bestExactMatches, secondaryMatches, tertiaryMatches;
3015
- for (auto match : matches)
3016
- {
3017
- switch (match.MatchCriteria().Option())
3018
- {
3019
- case PackageFieldMatchOption::EqualsCaseInsensitive:
3020
- case PackageFieldMatchOption::Equals:
3021
- bestExactMatches.push(match.CatalogPackage());
3022
- break;
3023
- case PackageFieldMatchOption::StartsWithCaseInsensitive:
3024
- secondaryMatches.push(match.CatalogPackage());
3025
- break;
3026
- case PackageFieldMatchOption::ContainsCaseInsensitive:
3027
- tertiaryMatches.push(match.CatalogPackage());
3028
- break;
3029
- }
3030
- }
3031
-
3032
- // Now return the top maxSuggestions
3033
- while (results.size() < maxSuggestions)
3034
- {
3035
- if (bestExactMatches.size() > 0)
3036
- {
3037
- results.emplace_back(bestExactMatches.front());
3038
- bestExactMatches.pop();
3039
- }
3040
- else if (secondaryMatches.size() > 0)
3041
- {
3042
- results.emplace_back(secondaryMatches.front());
3043
- secondaryMatches.pop();
3044
- }
3045
- else if (tertiaryMatches.size() > 0)
3046
- {
3047
- results.emplace_back(tertiaryMatches.front());
3048
- tertiaryMatches.pop();
3049
- }
3050
- else
3051
- {
3052
- break;
3053
- }
3054
- }
3055
- }
3056
- tooManySuggestions = matches.Size() > maxSuggestions;
3057
- return results;
3058
- };
3059
-
3060
- // Search by command
3061
- auto missingCmd = args.MissingCommand();
3062
- std::wstring searchOption = L"command";
3063
- applyPackageMatchFilter(PackageMatchField::Command, PackageFieldMatchOption::StartsWithCaseInsensitive, missingCmd);
3064
- auto findPackagesResult = catalog.FindPackages(findPackagesOptions);
3065
- auto matches = findPackagesResult.Matches();
3066
- auto pkgList = tryGetBestMatchingPackage(matches);
3067
- if (pkgList.empty())
3068
- {
3069
- // No matches found --> search by name
3070
- applyPackageMatchFilter(PackageMatchField::Name, PackageFieldMatchOption::ContainsCaseInsensitive, missingCmd);
3071
-
3072
- findPackagesResult = catalog.FindPackages(findPackagesOptions);
3073
- matches = findPackagesResult.Matches();
3074
- pkgList = tryGetBestMatchingPackage(matches);
3075
- searchOption = L"name";
3076
-
3077
- if (pkgList.empty())
3078
- {
3079
- // No matches found --> search by moniker
3080
- applyPackageMatchFilter(PackageMatchField::Moniker, PackageFieldMatchOption::ContainsCaseInsensitive, missingCmd);
3081
-
3082
- // Perform the query (search by name)
3083
- findPackagesResult = catalog.FindPackages(findPackagesOptions);
3084
- matches = findPackagesResult.Matches();
3085
- pkgList = tryGetBestMatchingPackage(matches);
3086
- searchOption = L"moniker";
3087
- }
3088
- }
3089
-
3090
- // Display packages in UI
3091
- if (!pkgList.empty())
3092
- {
3093
- std::vector<std::wstring> suggestions;
3094
- suggestions.reserve(pkgList.size());
3095
- for (auto pkg : pkgList)
3096
- {
3097
- suggestions.emplace_back(fmt::format(L"winget install --id {}", pkg.Id()));
3098
- }
3099
-
3100
- std::wstring footer = tooManySuggestions ?
3101
- fmt::format(L"winget search --{} {}", searchOption, missingCmd) :
3102
- L"";
3103
-
3104
- // TODO CARLOS: no more info bar; replace!
3105
- //ShowCommandNotFoundInfoBar(suggestions, footer);
3106
- }
3107
- #elif defined(DEBUG) || defined(_DEBUG) || defined(DBG)
3108
- //const bool tooManySuggestions = false;
3109
- //const std::wstring searchOption = L"command";
3110
- const std::wstring missingCmd = args.MissingCommand().data();
3111
- std::vector<std::wstring> pkgList = { L"pkg1", L"pkg2", L"pkg3" };
3112
- std::vector<hstring> suggestions;
3113
- suggestions.reserve(pkgList.size());
3114
- for (auto pkg : pkgList)
3115
- {
3116
- suggestions.emplace_back(fmt::format(L"winget install --id {}", pkg));
3117
- }
3118
-
3119
- // This will come in on a background (not-UI, not output) thread.
3120
-
3121
- // Parse the json string into a collection of actions
3122
- try
3123
- {
3124
- //auto commandsCollection = Command::ParsePowerShellMenuComplete(args.MenuJson(),
3125
- // args.ReplacementLength());
3126
-
3127
- auto suggestionsWinRT = winrt::single_threaded_vector<hstring>(std::move(suggestions));
3128
- auto commandsCollection = Command::ToSendInputCommands(suggestionsWinRT);
3129
-
3130
- //auto weakThis{ get_weak() };
3131
- //Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [weakThis, commandsCollection, sender]() {
3132
- // // On the UI thread...
3133
- // if (const auto& page{ weakThis.get() })
3134
- // {
3135
- // // Open the Suggestions UI with the commands from the control
3136
- // page->_OpenSuggestions(sender.try_as<TermControl>(), commandsCollection, SuggestionsMode::Menu, L"");
3137
- // }
3138
- //});
3139
- }
3140
- CATCH_LOG();
3141
- #endif
3142
- }
3143
-
3144
2957
// Method Description:
3145
2958
// - Paste text from the Windows Clipboard to the focused terminal
3146
2959
void TerminalPage::_PasteText ()
0 commit comments