Skip to content

Commit e84e8d4

Browse files
committed
add language neutral search
1 parent 532343f commit e84e8d4

File tree

2 files changed

+75
-65
lines changed

2 files changed

+75
-65
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.cpp

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,12 +1124,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
11241124
if (results.empty())
11251125
{
11261126
// Explicitly show "no results"
1127-
1128-
// TODO CARLOS: use RS_switchable_fmt from ActionArgs.cpp
1129-
const hstring noResultsText{ fmt::format(fmt::runtime(std::wstring{ RS_(L"Search_NoResults") }), sanitizedQuery) };
1130-
11311127
results.reserve(1);
1132-
results.push_back(winrt::make<FilteredSearchResult>(noResultsText));
1128+
results.push_back(winrt::make<FilteredSearchResult>(fmt::format(fmt::runtime(std::wstring{ RS_(L"Search_NoResults") }), sanitizedQuery)));
11331129
}
11341130
#undef APPEND_RUNTIME_OBJECT_RESULTS
11351131

@@ -1228,7 +1224,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
12281224
// Don't actually modify the members until we're completely done here.
12291225
SearchIndex searchIndex;
12301226

1231-
// TODO CARLOS: actually use this
12321227
// copied from CommandPaletteItems.h
12331228
static bool shouldIncludeLanguageNeutralResources = [] {
12341229
try
@@ -1247,38 +1242,34 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
12471242
return false;
12481243
}();
12491244

1250-
const auto& buildIndex = LoadBuildTimeIndex();
1251-
searchIndex.mainIndex.reserve(buildIndex.size());
1252-
for (const auto& entry : buildIndex)
1253-
{
1254-
// TODO CARLOS: properly populate LocalizedIndexEntry
1255-
LocalizedIndexEntry localizedEntry;
1256-
localizedEntry.Entry = &entry;
1257-
searchIndex.mainIndex.push_back(localizedEntry);
1258-
}
1245+
#define REGISTER_INDEX(index, storage) \
1246+
{ \
1247+
const auto& indexRef = index; \
1248+
storage.reserve(indexRef.size()); \
1249+
for (const auto& entry : indexRef) \
1250+
{ \
1251+
LocalizedIndexEntry localizedEntry; \
1252+
localizedEntry.Entry = &entry; \
1253+
if (shouldIncludeLanguageNeutralResources) \
1254+
{ \
1255+
localizedEntry.DisplayTextNeutral = EnglishOnlyResourceLoader().GetLocalizedString(entry.DisplayTextUid); \
1256+
if (entry.HelpTextUid) \
1257+
{ \
1258+
localizedEntry.HelpTextNeutral = EnglishOnlyResourceLoader().GetLocalizedString(entry.HelpTextUid.value()); \
1259+
} \
1260+
} \
1261+
storage.push_back(localizedEntry); \
1262+
} \
1263+
}
1264+
1265+
REGISTER_INDEX(LoadBuildTimeIndex(), searchIndex.mainIndex);
12591266

12601267
// Load profiles
1261-
const auto& profileIndex = LoadProfileIndex();
1262-
searchIndex.profileIndex.reserve(profileIndex.size());
1263-
for (const auto& entry : profileIndex)
1264-
{
1265-
// TODO CARLOS: properly populate LocalizedIndexEntry
1266-
LocalizedIndexEntry localizedEntry;
1267-
localizedEntry.Entry = &entry;
1268-
searchIndex.profileIndex.push_back(localizedEntry);
1269-
}
1268+
REGISTER_INDEX(LoadProfileIndex(), searchIndex.profileIndex);
12701269
searchIndex.profileIndexEntry.Entry = &PartialProfileIndexEntry();
12711270

12721271
// Load new tab menu
1273-
const auto& ntmFolderIndex = LoadNTMFolderIndex();
1274-
searchIndex.ntmFolderIndex.reserve(ntmFolderIndex.size());
1275-
for (const auto& entry : ntmFolderIndex)
1276-
{
1277-
// TODO CARLOS: properly populate LocalizedIndexEntry
1278-
LocalizedIndexEntry localizedEntry;
1279-
localizedEntry.Entry = &entry;
1280-
searchIndex.ntmFolderIndex.push_back(localizedEntry);
1281-
}
1272+
REGISTER_INDEX(LoadNTMFolderIndex(), searchIndex.ntmFolderIndex);
12821273
searchIndex.ntmFolderIndexEntry.Entry = &PartialNTMFolderIndexEntry();
12831274

12841275
// Load extensions
@@ -1287,15 +1278,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
12871278
searchIndex.extensionIndexEntry.Entry = &PartialExtensionIndexEntry();
12881279

12891280
// Load color schemes
1290-
const auto& colorSchemesIndex = LoadColorSchemeIndex();
1291-
searchIndex.colorSchemeIndex.reserve(colorSchemesIndex.size());
1292-
for (const auto& entry : colorSchemesIndex)
1293-
{
1294-
// TODO CARLOS: properly populate LocalizedIndexEntry
1295-
LocalizedIndexEntry localizedEntry;
1296-
localizedEntry.Entry = &entry;
1297-
searchIndex.colorSchemeIndex.push_back(localizedEntry);
1298-
}
1281+
REGISTER_INDEX(LoadColorSchemeIndex(), searchIndex.colorSchemeIndex)
12991282
searchIndex.colorSchemeIndexEntry.Entry = &PartialColorSchemeIndexEntry();
13001283

13011284
// Load actions

tools/GenerateSettingsIndex.ps1

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
9797
if ($filename -eq 'Launch.xaml')
9898
{
9999
$entries += [pscustomobject]@{
100+
DisplayTextUid = "L`"Nav_Launch/Content`""
100101
DisplayTextLocalized = "RS_(L`"Nav_Launch/Content`")"
102+
HelpTextUid = "std::nullopt"
101103
HelpTextLocalized = "std::nullopt"
102-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
104+
ParentPage = $pageClass
103105
NavigationParam = "winrt::box_value(hstring{L`"Launch_Nav`"})"
104106
SubPage = "BreadcrumbSubPage::None"
105107
ElementName = 'L""'
@@ -109,9 +111,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
109111
elseif ($filename -eq 'Interaction.xaml')
110112
{
111113
$entries += [pscustomobject]@{
114+
DisplayTextUid = "L`"Nav_Interaction/Content`""
112115
DisplayTextLocalized = "RS_(L`"Nav_Interaction/Content`")"
116+
HelpTextUid = "std::nullopt"
113117
HelpTextLocalized = "std::nullopt"
114-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
118+
ParentPage = $pageClass
115119
NavigationParam = "winrt::box_value(hstring{L`"Interaction_Nav`"})"
116120
SubPage = "BreadcrumbSubPage::None"
117121
ElementName = 'L""'
@@ -121,9 +125,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
121125
elseif ($filename -eq 'GlobalAppearance.xaml')
122126
{
123127
$entries += [pscustomobject]@{
128+
DisplayTextUid = "L`"Nav_Appearance/Content`""
124129
DisplayTextLocalized = "RS_(L`"Nav_Appearance/Content`")"
130+
HelpTextUid = "std::nullopt"
125131
HelpTextLocalized = "std::nullopt"
126-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
132+
ParentPage = $pageClass
127133
NavigationParam = "winrt::box_value(hstring{L`"Appearance_Nav`"})"
128134
SubPage = "BreadcrumbSubPage::None"
129135
ElementName = 'L""'
@@ -133,9 +139,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
133139
elseif ($filename -eq 'ColorSchemes.xaml')
134140
{
135141
$entries += [pscustomobject]@{
142+
DisplayTextUid = "L`"Nav_ColorSchemes/Content`""
136143
DisplayTextLocalized = "RS_(L`"Nav_ColorSchemes/Content`")"
144+
HelpTextUid = "std::nullopt"
137145
HelpTextLocalized = "std::nullopt"
138-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
146+
ParentPage = $pageClass
139147
NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})"
140148
SubPage = "BreadcrumbSubPage::None"
141149
ElementName = 'L""'
@@ -144,9 +152,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
144152

145153
# Manually register the "add new" button
146154
$entries += [pscustomobject]@{
155+
DisplayTextUid = "L`"ColorScheme_AddNewButton/Text`""
147156
DisplayTextLocalized = 'RS_(L"ColorScheme_AddNewButton/Text")'
157+
HelpTextUid = 'std::nullopt'
148158
HelpTextLocalized = 'std::nullopt'
149-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
159+
ParentPage = $pageClass
150160
NavigationParam = "winrt::box_value(hstring{L`"ColorSchemes_Nav`"})"
151161
SubPage = 'BreadcrumbSubPage::None'
152162
ElementName = 'L"AddNewButton"'
@@ -157,9 +167,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
157167
elseif ($filename -eq 'Rendering.xaml')
158168
{
159169
$entries += [pscustomobject]@{
170+
DisplayTextUid = "L`"Nav_Rendering/Content`""
160171
DisplayTextLocalized = "RS_(L`"Nav_Rendering/Content`")"
172+
HelpTextUid = "std::nullopt"
161173
HelpTextLocalized = "std::nullopt"
162-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
174+
ParentPage = $pageClass
163175
NavigationParam = "winrt::box_value(hstring{L`"Rendering_Nav`"})"
164176
SubPage = "BreadcrumbSubPage::None"
165177
ElementName = 'L""'
@@ -169,9 +181,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
169181
elseif ($filename -eq 'Compatibility.xaml')
170182
{
171183
$entries += [pscustomobject]@{
184+
DisplayTextUid = "L`"Nav_Compatibility/Content`""
172185
DisplayTextLocalized = "RS_(L`"Nav_Compatibility/Content`")"
186+
HelpTextUid = "std::nullopt"
173187
HelpTextLocalized = "std::nullopt"
174-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
188+
ParentPage = $pageClass
175189
NavigationParam = "winrt::box_value(hstring{L`"Compatibility_Nav`"})"
176190
SubPage = "BreadcrumbSubPage::None"
177191
ElementName = 'L""'
@@ -181,9 +195,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
181195
elseif ($filename -eq 'Actions.xaml')
182196
{
183197
$entries += [pscustomobject]@{
198+
DisplayTextUid = "L`"Nav_Actions/Content`""
184199
DisplayTextLocalized = "RS_(L`"Nav_Actions/Content`")"
200+
HelpTextUid = "std::nullopt"
185201
HelpTextLocalized = "std::nullopt"
186-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
202+
ParentPage = $pageClass
187203
NavigationParam = "winrt::box_value(hstring{L`"Actions_Nav`"})"
188204
SubPage = "BreadcrumbSubPage::None"
189205
ElementName = 'L""'
@@ -193,9 +209,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
193209
elseif ($filename -eq 'NewTabMenu.xaml')
194210
{
195211
$entries += [pscustomobject]@{
212+
DisplayTextUid = "L`"Nav_NewTabMenu/Content`""
196213
DisplayTextLocalized = "RS_(L`"Nav_NewTabMenu/Content`")"
214+
HelpTextUid = "std::nullopt"
197215
HelpTextLocalized = "std::nullopt"
198-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
216+
ParentPage = $pageClass
199217
NavigationParam = "winrt::box_value(hstring{L`"NewTabMenu_Nav`"})"
200218
SubPage = "BreadcrumbSubPage::None"
201219
ElementName = 'L""'
@@ -205,9 +223,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
205223
elseif ($filename -eq 'Extensions.xaml')
206224
{
207225
$entries += [pscustomobject]@{
226+
DisplayTextUid = "L`"Nav_Extensions/Content`""
208227
DisplayTextLocalized = "RS_(L`"Nav_Extensions/Content`")"
228+
HelpTextUid = "std::nullopt"
209229
HelpTextLocalized = "std::nullopt"
210-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
230+
ParentPage = $pageClass
211231
NavigationParam = "winrt::box_value(hstring{L`"Extensions_Nav`"})"
212232
SubPage = "BreadcrumbSubPage::None"
213233
ElementName = 'L""'
@@ -328,9 +348,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
328348
}
329349

330350
$entries += [pscustomobject]@{
351+
DisplayTextUid = "L`"$($uid)/Header`""
331352
DisplayTextLocalized = "RS_(L`"$($uid)/Header`")"
332-
HelpTextLocalized = $resourceKeys -contains "$($uid)/HelpText" ? "std::optional<hstring>{ RS_(L`"$($uid)/HelpText`") }" : "std::nullopt"
333-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
353+
HelpTextUid = $resourceKeys -contains "$($uid).HelpText" ? "std::optional<hstring>{ L`"$($uid)/HelpText`" }" : "std::nullopt"
354+
HelpTextLocalized = $resourceKeys -contains "$($uid).HelpText" ? "std::optional<hstring>{ RS_(L`"$($uid)/HelpText`") }" : "std::nullopt"
355+
ParentPage = $pageClass
334356
NavigationParam = $navigationParam -eq "nullptr" ? $navigationParam : "winrt::box_value(hstring{L`"$($navigationParam)`"})"
335357
SubPage = $subPage
336358
ElementName = "L`"$($name)`""
@@ -341,9 +363,11 @@ Get-ChildItem -Path $SourceDir -Recurse -Filter *.xaml | ForEach-Object {
341363
if ($duplicateForVM)
342364
{
343365
$entries += [pscustomobject]@{
366+
DisplayTextUid = "L`"$($uid)/Header`""
344367
DisplayTextLocalized = "RS_(L`"$($uid)/Header`")"
345-
HelpTextLocalized = $resourceKeys -contains "$($uid)/HelpText" ? "std::optional<hstring>{ RS_(L`"$($uid)/HelpText`") }" : "std::nullopt"
346-
ParentPage = "winrt::xaml_typename<$($pageClass)>()"
368+
HelpTextUid = $resourceKeys -contains "$($uid).HelpText" ? "std::optional<hstring>{ L`"$($uid)/HelpText`" }" : "std::nullopt"
369+
HelpTextLocalized = $resourceKeys -contains "$($uid).HelpText" ? "std::optional<hstring>{ RS_(L`"$($uid)/HelpText`") }" : "std::nullopt"
370+
ParentPage = $pageClass
347371
NavigationParam = 'nullptr' # VM param at runtime
348372
SubPage = $navigationParam -eq 'NewTabMenu_Nav' ? 'BreadcrumbSubPage::NewTabMenu_Folder' : $subPage
349373
ElementName = "L`"$($name)`""
@@ -362,7 +386,7 @@ $schemeEntries = @()
362386
$ntmEntries = @()
363387
foreach ($e in $entries)
364388
{
365-
$formattedEntry = " IndexEntry{ $($e.DisplayTextLocalized), $($e.HelpTextLocalized), $($e.ParentPage), $($e.NavigationParam), $($e.SubPage), $($e.ElementName) }, // $($e.File)"
389+
$formattedEntry = " IndexEntry{ $($e.DisplayTextUid), $($e.DisplayTextLocalized), $($e.HelpTextUid), $($e.HelpTextLocalized), $($e.NavigationParam), $($e.SubPage), $($e.ElementName) }, // $($e.File)"
366390

367391
if ($e.NavigationParam -eq 'nullptr' -and
368392
($e.ParentPage -match 'Profiles_Base' -or
@@ -401,17 +425,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
401425
{
402426
struct IndexEntry
403427
{
428+
// x:Uid of the SettingContainer's Header (i.e. "Globals_DefaultProfile/Header")
429+
hstring DisplayTextUid;
430+
404431
// Localized display text shown in the SettingContainer (i.e. RS_(L"Globals_DefaultProfile/Header"))
405432
hstring DisplayTextLocalized;
406433
434+
// x:Uid of the SettingContainer's HelpText (i.e. "Globals_DefaultProfile/HelpText")
435+
// May not exist for all entries
436+
std::optional<hstring> HelpTextUid;
437+
407438
// Localized help text shown in the SettingContainer (i.e. RS_(L"Globals_DefaultProfile/HelpText"))
408439
// May not exist for all entries
409440
std::optional<hstring> HelpTextLocalized;
410441
411-
// TODO CARLOS: this might not be necessary; remove
412-
// x:Class of the parent Page (i.e. winrt::xaml_typename<Microsoft::Terminal::Settings::Editor::Launch>())
413-
winrt::Windows::UI::Xaml::Interop::TypeName ParentPage;
414-
415442
// Navigation argument (i.e. winrt::box_value(hstring) or nullptr)
416443
// Use nullptr as placeholder for runtime navigation with a view model object
417444
winrt::Windows::Foundation::IInspectable NavigationArg;
@@ -483,25 +510,25 @@ $( ($schemeEntries -join "`r`n") )
483510
484511
const IndexEntry& PartialProfileIndexEntry()
485512
{
486-
static IndexEntry entry{ L"", std::nullopt, winrt::xaml_typename<Microsoft::Terminal::Settings::Editor::Profiles_Base>(), nullptr, BreadcrumbSubPage::None, L"" };
513+
static IndexEntry entry{ L"", L"", std::nullopt, std::nullopt, nullptr, BreadcrumbSubPage::None, L"" };
487514
return entry;
488515
}
489516
490517
const IndexEntry& PartialNTMFolderIndexEntry()
491518
{
492-
static IndexEntry entry{ L"", std::nullopt, winrt::xaml_typename<Microsoft::Terminal::Settings::Editor::NewTabMenu>(), nullptr, BreadcrumbSubPage::NewTabMenu_Folder, L"" };
519+
static IndexEntry entry{ L"", L"", std::nullopt, std::nullopt, nullptr, BreadcrumbSubPage::NewTabMenu_Folder, L"" };
493520
return entry;
494521
}
495522
496523
const IndexEntry& PartialColorSchemeIndexEntry()
497524
{
498-
static IndexEntry entry{ L"", std::nullopt, winrt::xaml_typename<Microsoft::Terminal::Settings::Editor::EditColorScheme>(), nullptr, BreadcrumbSubPage::ColorSchemes_Edit, L"" };
525+
static IndexEntry entry{ L"", L"", std::nullopt, std::nullopt, nullptr, BreadcrumbSubPage::ColorSchemes_Edit, L"" };
499526
return entry;
500527
}
501528
502529
const IndexEntry& PartialExtensionIndexEntry()
503530
{
504-
static IndexEntry entry{ L"", std::nullopt, winrt::xaml_typename<Microsoft::Terminal::Settings::Editor::Extensions>(), nullptr, BreadcrumbSubPage::Extensions_Extension, L"" };
531+
static IndexEntry entry{ L"", L"", std::nullopt, std::nullopt, nullptr, BreadcrumbSubPage::Extensions_Extension, L"" };
505532
return entry;
506533
}
507534
}

0 commit comments

Comments
 (0)