Skip to content

Commit be2b1d3

Browse files
committed
fix color schemes; convert APPEND_RUNTIME_OBJECT_RESULTS to lambda
1 parent 6fbf953 commit be2b1d3

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.cpp

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
7979
{
8080
runtimeObjLabel = profileVM.Name();
8181
}
82+
else if (const auto colorSchemeVM = runtimeObj.try_as<Editor::ColorSchemeViewModel>())
83+
{
84+
runtimeObjLabel = colorSchemeVM.Name();
85+
}
8286
else if (const auto ntmFolderEntryVM = runtimeObj.try_as<Editor::FolderEntryViewModel>())
8387
{
8488
runtimeObjLabel = ntmFolderEntryVM.Name();
@@ -163,6 +167,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
163167
icon.Height(iconSize);
164168
return icon;
165169
}
170+
else if (const auto colorSchemeVM = navigationArg.try_as<Editor::ColorSchemeViewModel>())
171+
{
172+
WUX::Controls::FontIcon icon{};
173+
icon.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
174+
icon.FontSize(iconSize);
175+
icon.Glyph(L"\xE790");
176+
return icon;
177+
}
166178
else if (const auto ntmFolderEntryVM = navigationArg.try_as<Editor::FolderEntryViewModel>())
167179
{
168180
auto icon = UI::IconPathConverter::IconWUX(ntmFolderEntryVM.Icon());
@@ -846,6 +858,28 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
846858
}
847859
}
848860

861+
void MainPage::_Navigate(const Editor::ColorSchemeViewModel& colorSchemeVM, BreadcrumbSubPage subPage, hstring elementToFocus)
862+
{
863+
_PreNavigateHelper();
864+
865+
const auto crumb = winrt::make<Breadcrumb>(box_value(colorSchemesTag), RS_(L"Nav_ColorSchemes/Content"), BreadcrumbSubPage::None);
866+
_breadcrumbs.Append(crumb);
867+
contentFrame().Navigate(xaml_typename<Editor::ColorSchemes>(), winrt::make<NavigateToColorSchemesArgs>(_colorSchemesPageVM, elementToFocus));
868+
SettingsNav().SelectedItem(ColorSchemesNavItem());
869+
870+
// Set CurrentScheme BEFORE the CurrentPage!
871+
if (subPage == BreadcrumbSubPage::None)
872+
{
873+
_colorSchemesPageVM.CurrentScheme(nullptr);
874+
_colorSchemesPageVM.CurrentPage(ColorSchemesSubPage::Base);
875+
}
876+
else
877+
{
878+
_colorSchemesPageVM.CurrentScheme(colorSchemeVM);
879+
_colorSchemesPageVM.CurrentPage(ColorSchemesSubPage::EditColorScheme);
880+
}
881+
}
882+
849883
void MainPage::_Navigate(const Editor::NewTabMenuEntryViewModel& ntmEntryVM, BreadcrumbSubPage subPage, hstring elementToFocus)
850884
{
851885
_PreNavigateHelper();
@@ -1304,33 +1338,32 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
13041338
results.push_back(winrt::make<FilteredSearchResult>(indexEntry));
13051339
}
13061340

1307-
#define APPEND_RUNTIME_OBJECT_RESULTS(runtimeObjectList, nameAccessor, filteredSearchIndex, partialSearchIndexEntry, navigationArgTransform) \
1308-
for (const auto& runtimeObj : runtimeObjectList) \
1309-
{ \
1310-
const auto& objName = nameAccessor; \
1311-
const bool nameMatches = til::contains_linguistic_insensitive(objName, sanitizedQuery); \
1312-
\
1313-
if (nameMatches) \
1314-
{ \
1315-
/* navigates to runtime object main page (i.e. "PowerShell" Profiles_Base page) */ \
1316-
results.push_back(FilteredSearchResult::CreateRuntimeObjectItem(&partialSearchIndexEntry, runtimeObj)); \
1317-
} \
1318-
\
1319-
for (const auto* indexEntry : filteredSearchIndex) \
1320-
{ \
1321-
/* navigates to runtime object's setting (i.e. "PowerShell: Command line" ) */ \
1322-
results.push_back(FilteredSearchResult::CreateRuntimeObjectItem(indexEntry, navigationArgTransform)); \
1323-
} \
1324-
}
1341+
auto appendRuntimeObjectResults = [&](const auto& runtimeObjectList, const auto& filteredSearchIndex, const auto& partialSearchIndexEntry) {
1342+
for (const auto& runtimeObj : runtimeObjectList)
1343+
{
1344+
const auto& objName = runtimeObj.Name();
1345+
const bool nameMatches = til::contains_linguistic_insensitive(objName, sanitizedQuery);
1346+
if (nameMatches)
1347+
{
1348+
// navigates to runtime object main page (i.e. "PowerShell" Profiles_Base page)
1349+
results.push_back(FilteredSearchResult::CreateRuntimeObjectItem(&partialSearchIndexEntry, runtimeObj));
1350+
}
1351+
for (const auto* indexEntry : filteredSearchIndex)
1352+
{
1353+
// navigates to runtime object's setting (i.e. "PowerShell: Command line" )
1354+
results.push_back(FilteredSearchResult::CreateRuntimeObjectItem(indexEntry, runtimeObj));
1355+
}
1356+
}
1357+
};
13251358

13261359
// Profiles
1327-
APPEND_RUNTIME_OBJECT_RESULTS(_profileVMs, runtimeObj.Name(), _filteredSearchIndex->profileIndex, _searchIndex->profileIndexEntry, runtimeObj);
1360+
appendRuntimeObjectResults(_profileVMs, _filteredSearchIndex->profileIndex, _searchIndex->profileIndexEntry);
13281361

13291362
// New Tab Menu (Folder View)
1330-
APPEND_RUNTIME_OBJECT_RESULTS(get_self<implementation::NewTabMenuViewModel>(_newTabMenuPageVM)->FolderTreeFlatList(), runtimeObj.Name(), _filteredSearchIndex->ntmFolderIndex, _searchIndex->ntmFolderIndexEntry, runtimeObj);
1363+
appendRuntimeObjectResults(get_self<implementation::NewTabMenuViewModel>(_newTabMenuPageVM)->FolderTreeFlatList(), _filteredSearchIndex->ntmFolderIndex, _searchIndex->ntmFolderIndexEntry);
13311364

13321365
// Color schemes
1333-
APPEND_RUNTIME_OBJECT_RESULTS(_colorSchemesPageVM.AllColorSchemes(), runtimeObj.Name(), _filteredSearchIndex->colorSchemeIndex, _searchIndex->colorSchemeIndexEntry, winrt::box_value(runtimeObj.Name()));
1366+
appendRuntimeObjectResults(_colorSchemesPageVM.AllColorSchemes(), _filteredSearchIndex->colorSchemeIndex, _searchIndex->colorSchemeIndexEntry);
13341367

13351368
// Extensions
13361369
for (const auto& extension : _extensionsVM.ExtensionPackages())
@@ -1414,17 +1447,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
14141447
{
14151448
_Navigate(*navArgString, subpage, elementToFocus);
14161449
}
1417-
else if (const auto profileVM = navigationArg.try_as<ProfileViewModel>())
1450+
else if (const auto& profileVM = navigationArg.try_as<Editor::ProfileViewModel>())
1451+
{
1452+
_Navigate(profileVM, subpage, elementToFocus);
1453+
}
1454+
else if (const auto& colorSchemeVM = navigationArg.try_as<Editor::ColorSchemeViewModel>())
14181455
{
1419-
_Navigate(*profileVM, subpage, elementToFocus);
1456+
_Navigate(colorSchemeVM, subpage, elementToFocus);
14201457
}
1421-
else if (const auto ntmEntryVM = navigationArg.try_as<NewTabMenuEntryViewModel>())
1458+
else if (const auto& ntmEntryVM = navigationArg.try_as<Editor::NewTabMenuEntryViewModel>())
14221459
{
1423-
_Navigate(*ntmEntryVM, subpage, elementToFocus);
1460+
_Navigate(ntmEntryVM, subpage, elementToFocus);
14241461
}
1425-
else if (const auto extPkgVM = navigationArg.try_as<ExtensionPackageViewModel>())
1462+
else if (const auto& extPkgVM = navigationArg.try_as<Editor::ExtensionPackageViewModel>())
14261463
{
1427-
_Navigate(*extPkgVM, subpage, elementToFocus);
1464+
_Navigate(extPkgVM, subpage, elementToFocus);
14281465
}
14291466
SettingsSearchBox().Text(L"");
14301467
}

src/cascadia/TerminalSettingsEditor/MainPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
110110
void _PreNavigateHelper();
111111
void _Navigate(hstring clickedItemTag, BreadcrumbSubPage subPage, hstring elementToFocus = {});
112112
void _Navigate(const Editor::ProfileViewModel& profile, BreadcrumbSubPage subPage, hstring elementToFocus = {});
113+
void _Navigate(const Editor::ColorSchemeViewModel& colorSchemeVM, BreadcrumbSubPage subPage, hstring elementToFocus = {});
113114
void _Navigate(const Editor::NewTabMenuEntryViewModel& ntmEntryVM, BreadcrumbSubPage subPage, hstring elementToFocus = {});
114115
void _Navigate(const Editor::ExtensionPackageViewModel& extPkgVM, BreadcrumbSubPage subPage, hstring elementToFocus = {});
115116
void _NavigateToProfileHandler(const IInspectable& sender, winrt::guid profileGuid);

0 commit comments

Comments
 (0)