From 2a41f8a57c9a9b28a1e35487a1a294b954b4d0ee Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Mon, 3 Nov 2025 11:48:36 -0800 Subject: [PATCH] improve index --- .../TerminalSettingsEditor/MainPage.cpp | 28 +-- .../TerminalSettingsEditor/MainPage.h | 5 +- tools/GenerateSettingsIndex.ps1 | 171 +++++++++++++----- 3 files changed, 142 insertions(+), 62 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index a06e56b7e8..59e4999ba4 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -1074,6 +1074,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation co_await winrt::resume_foreground(Dispatcher()); if (searchGeneration != _filteredSearchIndex.generation()) { + // TODO CARLOS: look into til::throttled_func (winrt version and non-winrt version) for debounce (used in BellSound and TaskbarProgressUpdates) // search index was updated while we were searching, discard results co_return; } @@ -1099,18 +1100,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } // TODO CARLOS: use the macro below for runtime objects once everything is verified to be working right -#define APPEND_RUNTIME_OBJECT_RESULTS(runtimeObjectList, runtimeObjectIdentifier, filteredSearchIndex, navigationArgOverride) \ - for (const auto& runtimeObj : runtimeObjectList) \ - { \ - if (til::contains_linguistic_insensitive(runtimeObjectIdentifier, sanitizedQuery)) \ - { \ - /*results.push_back(winrt::make(, profile));*/ \ - } \ - \ - for (const auto* indexEntry : filteredSearchIndex) \ - { \ - results.push_back(winrt::make(indexEntry, navigationArgOverride)); \ - } \ +#define APPEND_RUNTIME_OBJECT_RESULTS(runtimeObjectList, runtimeObjectIdentifier, filteredSearchIndex, navigationArgOverride) \ + for (const auto& runtimeObj : runtimeObjectList) \ + { \ + if (til::contains_linguistic_insensitive(runtimeObjectIdentifier, sanitizedQuery)) \ + { \ + /*results.push_back(winrt::make(, runtimeObj, runtimeObjectIdentifier));*/ \ + } \ + \ + for (const auto* indexEntry : filteredSearchIndex) \ + { \ + results.push_back(winrt::make(indexEntry, navigationArgOverride)); \ + } \ } // Profiles @@ -1122,7 +1123,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { // TODO CARLOS: if name matches, link the top-level page // can't do that rn because I need a LocalizedIndexEntry stored somewhere for that - //results.push_back(winrt::make(, profile)); + // SPECIFICALLY, I NEED TO CONVERT PartialProfileIndexEntry into a LocalizedIndexEntry (which is dumb, because there's nothing to localize) + //results.push_back(winrt::make(&PartialProfileIndexEntry(), profile));//, std::optional{ profile.Name() })); } for (const auto* indexEntry : _filteredSearchProfileIndex) diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index 06994d581e..7b23bab9b7 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -42,9 +42,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation FilteredSearchResult(const winrt::hstring& label) : _overrideLabel{ label } {} - FilteredSearchResult(const LocalizedIndexEntry* entry, const Windows::Foundation::IInspectable& navigationArgOverride = nullptr) : + FilteredSearchResult(const LocalizedIndexEntry* entry, const Windows::Foundation::IInspectable& navigationArgOverride = nullptr, const std::optional& label = std::nullopt) : _SearchIndexEntry{ entry }, - _NavigationArgOverride{ navigationArgOverride } {} + _NavigationArgOverride{ navigationArgOverride }, + _overrideLabel{ label } {} hstring ToString() { return Label(); } diff --git a/tools/GenerateSettingsIndex.ps1 b/tools/GenerateSettingsIndex.ps1 index 6519206e0c..fa3b431e2e 100644 --- a/tools/GenerateSettingsIndex.ps1 +++ b/tools/GenerateSettingsIndex.ps1 @@ -93,58 +93,126 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object { $subPage += 'None' } - if ($filename -eq 'ColorSchemes.xaml') + # Register top-level pages + if ($filename -eq 'Launch.xaml') { - # ColorSchemes.xaml doesn't have any SettingContainers! - - # TODO CARLOS: remove from script; hard code in MainPage instead - # Register the page itself - # $entries += [pscustomobject]@{ - # DisplayText = 'vm' - # ParentPage = "winrt::xaml_typename()" - # NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})" - # SubPage = 'BreadcrumbSubPage::ColorSchemes_Edit' - # ElementName = 'L""' - # File = $filename - # } + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Launch/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Launch_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'Interaction.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Interaction/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Interaction_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'GlobalAppearance.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Appearance/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Appearance_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'ColorSchemes.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_ColorSchemes/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } - # TODO CARLOS: remove from script; hard code in MainPage instead # Manually register the "add new" button - # $entries += [pscustomobject]@{ - # DisplayText = 'RS_(L"ColorScheme_AddNewButton/Text")' - # ParentPage = "winrt::xaml_typename()" - # NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})" - # SubPage = 'BreadcrumbSubPage::None' - # ElementName = 'L"AddNewButton"' - # File = $filename - # } - return + $entries += [pscustomobject]@{ + DisplayTextLocalized = 'RS_(L"ColorScheme_AddNewButton/Text")' + HelpTextLocalized = 'std::nullopt' + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})" + SubPage = 'BreadcrumbSubPage::None' + ElementName = 'L"AddNewButton"' + File = $filename + } + + } + elseif ($filename -eq 'Rendering.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Rendering/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Rendering_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'Compatibility.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Compatibility/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Compatibility_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'Actions.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Actions/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Actions_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } + } + elseif ($filename -eq 'NewTabMenu.xaml') + { + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_NewTabMenu/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"NewTabMenu_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } } elseif ($filename -eq 'Extensions.xaml') { - - # TODO CARLOS: remove from script; hard code in MainPage instead - # Register the main extension page - # $entries += [pscustomobject]@{ - # DisplayText = 'RS_(L"Nav_Extensions/Content")' - # ParentPage = "winrt::xaml_typename()" - # NavigationParam = "nullptr" - # SubPage = 'BreadcrumbSubPage::None' - # ElementName = 'L""' - # File = $filename - # } - - # TODO CARLOS: remove from script; hard code in MainPage instead - # Register the extension view - # $entries += [pscustomobject]@{ - # DisplayText = 'vm.Package().DisplayName()' - # ParentPage = "winrt::xaml_typename()" - # NavigationParam = "vm" - # SubPage = 'BreadcrumbSubPage::Extensions_Extension' - # ElementName = 'L""' - # File = $filename - # } - return + $entries += [pscustomobject]@{ + DisplayTextLocalized = "RS_(L`"Nav_Extensions/Content`")" + HelpTextLocalized = "std::nullopt" + ParentPage = "winrt::xaml_typename<$($pageClass)>()" + NavigationParam = "winrt::box_value(hstring{L`"Extensions_Nav`"})" + SubPage = "BreadcrumbSubPage::None" + ElementName = 'L""' + File = $filename + } } # Find all local:SettingContainer start tags @@ -286,7 +354,7 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object { } # Ensure there aren't any duplicate entries -$entries = $entries | Sort-Object RootUid, ParentPage, NavigationParam, SubPage, ElementName, File -Unique +$entries = $entries | Sort-Object DisplayTextLocalized, HelpTextLocalized, ParentPage, NavigationParam, SubPage, ElementName, File -Unique $buildTimeEntries = @() $profileEntries = @() @@ -340,6 +408,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // May not exist for all entries std::optional HelpTextLocalized; + // TODO CARLOS: this might not be necessary; remove // x:Class of the parent Page (i.e. winrt::xaml_typename()) winrt::Windows::UI::Xaml::Interop::TypeName ParentPage; @@ -357,6 +426,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation const std::array& LoadProfileIndex(); const std::array& LoadNTMFolderIndex(); const std::array& LoadColorSchemeIndex(); + + const IndexEntry& PartialProfileIndexEntry(); } "@ @@ -406,6 +477,12 @@ $( ($schemeEntries -join "`r`n") ) }; return entries; } + + const IndexEntry& PartialProfileIndexEntry() + { + static IndexEntry entry{ L"", std::nullopt, winrt::xaml_typename(), nullptr, BreadcrumbSubPage::None, L"" }; + return entry; + } } "@