Skip to content

Commit cff62cc

Browse files
committed
update selected item
1 parent 82536fd commit cff62cc

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.cpp

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
402402
if (stringTag == breadcrumbStringTag)
403403
{
404404
// found the one that was selected before the refresh
405-
SettingsNav().SelectedItem(item);
406405
_Navigate(*breadcrumbStringTag, crumb->SubPage());
406+
SettingsNav().SelectedItem(item);
407407
return;
408408
}
409409
}
@@ -413,8 +413,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
413413
{
414414
// navigate to the NewTabMenu page,
415415
// _Navigate() will handle trying to find the right subpage
416-
SettingsNav().SelectedItem(item);
417416
_Navigate(breadcrumbFolderEntry, BreadcrumbSubPage::NewTabMenu_Folder);
417+
SettingsNav().SelectedItem(item);
418418
return;
419419
}
420420
}
@@ -424,8 +424,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
424424
{
425425
// navigate to the Extensions page,
426426
// _Navigate() will handle trying to find the right subpage
427-
SettingsNav().SelectedItem(item);
428427
_Navigate(breadcrumbExtensionPackage, BreadcrumbSubPage::Extensions_Extension);
428+
SettingsNav().SelectedItem(item);
429429
return;
430430
}
431431
}
@@ -437,8 +437,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
437437
if (profileTag->OriginalProfileGuid() == breadcrumbProfileTag->OriginalProfileGuid())
438438
{
439439
// found the one that was selected before the refresh
440-
SettingsNav().SelectedItem(item);
441440
_Navigate(*profileTag, crumb->SubPage());
441+
SettingsNav().SelectedItem(item);
442442
return;
443443
}
444444
}
@@ -452,8 +452,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
452452
// This happens when the selected item was a profile which doesn't exist in the new configuration
453453
// We can use menuItemsSTL here because the only things they miss are profile entries.
454454
const auto& firstItem{ _menuItemSource.GetAt(0).as<MUX::Controls::NavigationViewItem>() };
455-
SettingsNav().SelectedItem(firstItem);
456455
_Navigate(unbox_value<hstring>(firstItem.Tag()), BreadcrumbSubPage::None);
456+
SettingsNav().SelectedItem(firstItem);
457457

458458
_UpdateSearchIndex();
459459
}
@@ -658,30 +658,35 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
658658
contentFrame().Navigate(xaml_typename<Editor::Launch>(), winrt::make<NavigateToLaunchArgs>(winrt::make<LaunchViewModel>(_settingsClone), elementToFocus));
659659
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Launch/Content"), BreadcrumbSubPage::None);
660660
_breadcrumbs.Append(crumb);
661+
SettingsNav().SelectedItem(LaunchNavItem());
661662
}
662663
else if (clickedItemTag == interactionTag)
663664
{
664665
contentFrame().Navigate(xaml_typename<Editor::Interaction>(), winrt::make<NavigateToInteractionArgs>(winrt::make<InteractionViewModel>(_settingsClone.GlobalSettings()), elementToFocus));
665666
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Interaction/Content"), BreadcrumbSubPage::None);
666667
_breadcrumbs.Append(crumb);
668+
SettingsNav().SelectedItem(InteractionNavItem());
667669
}
668670
else if (clickedItemTag == renderingTag)
669671
{
670672
contentFrame().Navigate(xaml_typename<Editor::Rendering>(), winrt::make<NavigateToRenderingArgs>(winrt::make<RenderingViewModel>(_settingsClone), elementToFocus));
671673
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Rendering/Content"), BreadcrumbSubPage::None);
672674
_breadcrumbs.Append(crumb);
675+
SettingsNav().SelectedItem(RenderingNavItem());
673676
}
674677
else if (clickedItemTag == compatibilityTag)
675678
{
676679
contentFrame().Navigate(xaml_typename<Editor::Compatibility>(), winrt::make<NavigateToCompatibilityArgs>(winrt::make<CompatibilityViewModel>(_settingsClone), elementToFocus));
677680
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Compatibility/Content"), BreadcrumbSubPage::None);
678681
_breadcrumbs.Append(crumb);
682+
SettingsNav().SelectedItem(CompatibilityNavItem());
679683
}
680684
else if (clickedItemTag == actionsTag)
681685
{
682686
contentFrame().Navigate(xaml_typename<Editor::Actions>(), winrt::make<NavigateToActionsArgs>(winrt::make<ActionsViewModel>(_settingsClone)));
683687
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Actions/Content"), BreadcrumbSubPage::None);
684688
_breadcrumbs.Append(crumb);
689+
SettingsNav().SelectedItem(ActionsNavItem());
685690
}
686691
else if (clickedItemTag == newTabMenuTag)
687692
{
@@ -698,6 +703,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
698703
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_NewTabMenu/Content"), BreadcrumbSubPage::None);
699704
_breadcrumbs.Append(crumb);
700705
}
706+
SettingsNav().SelectedItem(NewTabMenuNavItem());
701707
}
702708
else if (clickedItemTag == extensionsTag)
703709
{
@@ -713,6 +719,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
713719
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Extensions/Content"), BreadcrumbSubPage::None);
714720
_breadcrumbs.Append(crumb);
715721
}
722+
SettingsNav().SelectedItem(ExtensionsNavItem());
716723
}
717724
else if (clickedItemTag == globalProfileTag)
718725
{
@@ -725,6 +732,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
725732
contentFrame().Navigate(xaml_typename<Editor::Profiles_Base>(), winrt::make<implementation::NavigateToProfileArgs>(profileVM, *this, elementToFocus));
726733
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_ProfileDefaults/Content"), BreadcrumbSubPage::None);
727734
_breadcrumbs.Append(crumb);
735+
SettingsNav().SelectedItem(BaseLayerMenuItem());
728736

729737
// If we were given a label, make sure we are on the correct sub-page
730738
if (subPage == BreadcrumbSubPage::Profile_Appearance)
@@ -745,6 +753,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
745753
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_ColorSchemes/Content"), BreadcrumbSubPage::None);
746754
_breadcrumbs.Append(crumb);
747755
contentFrame().Navigate(xaml_typename<Editor::ColorSchemes>(), winrt::make<NavigateToColorSchemesArgs>(_colorSchemesPageVM, elementToFocus));
756+
SettingsNav().SelectedItem(ColorSchemesNavItem());
748757

749758
if (subPage == BreadcrumbSubPage::ColorSchemes_Edit)
750759
{
@@ -756,6 +765,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
756765
contentFrame().Navigate(xaml_typename<Editor::GlobalAppearance>(), winrt::make<NavigateToGlobalAppearanceArgs>(winrt::make<GlobalAppearanceViewModel>(_settingsClone.GlobalSettings()), elementToFocus));
757766
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Appearance/Content"), BreadcrumbSubPage::None);
758767
_breadcrumbs.Append(crumb);
768+
SettingsNav().SelectedItem(GlobalAppearanceNavItem());
759769
}
760770
else if (clickedItemTag == addProfileTag)
761771
{
@@ -764,6 +774,27 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
764774
contentFrame().Navigate(xaml_typename<Editor::AddProfile>(), addProfileState);
765775
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_AddNewProfile/Content"), BreadcrumbSubPage::None);
766776
_breadcrumbs.Append(crumb);
777+
778+
// Find the "Add new profile" menu item and select it
779+
// It's likely at the very end of the list, so we'll search backwards
780+
for (auto i = _menuItemSource.Size() - 1; i > 0; --i)
781+
{
782+
const auto& item = _menuItemSource.GetAt(i);
783+
if (const auto& menuItem{ item.try_as<MUX::Controls::NavigationViewItem>() })
784+
{
785+
if (const auto& tag{ menuItem.Tag() })
786+
{
787+
if (const auto& stringTag{ tag.try_as<hstring>() })
788+
{
789+
if (*stringTag == addProfileTag)
790+
{
791+
SettingsNav().SelectedItem(item);
792+
break;
793+
}
794+
}
795+
}
796+
}
797+
}
767798
}
768799
}
769800

@@ -790,6 +821,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
790821
contentFrame().Navigate(xaml_typename<Editor::Profiles_Base>(), winrt::make<implementation::NavigateToProfileArgs>(profile, *this, elementToFocus));
791822
const auto crumb = winrt::make<Breadcrumb>(box_value(profile), profile.Name(), BreadcrumbSubPage::None);
792823
_breadcrumbs.Append(crumb);
824+
if (const auto profileNavItem = _FindProfileNavItem(profile.OriginalProfileGuid()))
825+
{
826+
SettingsNav().SelectedItem(profileNavItem);
827+
}
793828

794829
// Set the profile's 'CurrentPage' to the correct one, if this requires further navigation, the
795830
// event handler will do it
@@ -818,6 +853,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
818853
contentFrame().Navigate(xaml_typename<Editor::NewTabMenu>(), winrt::make<NavigateToNewTabMenuArgs>(_newTabMenuPageVM, elementToFocus));
819854
const auto crumb = winrt::make<Breadcrumb>(box_value(newTabMenuTag), RS_(L"Nav_NewTabMenu/Content"), BreadcrumbSubPage::None);
820855
_breadcrumbs.Append(crumb);
856+
SettingsNav().SelectedItem(NewTabMenuNavItem());
821857

822858
if (subPage == BreadcrumbSubPage::None)
823859
{
@@ -851,6 +887,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
851887
contentFrame().Navigate(xaml_typename<Editor::Extensions>(), winrt::make<NavigateToExtensionsArgs>(_extensionsVM, elementToFocus));
852888
const auto crumb = winrt::make<Breadcrumb>(box_value(extensionsTag), RS_(L"Nav_Extensions/Content"), BreadcrumbSubPage::None);
853889
_breadcrumbs.Append(crumb);
890+
SettingsNav().SelectedItem(ExtensionsNavItem());
854891

855892
if (subPage == BreadcrumbSubPage::None)
856893
{
@@ -1004,8 +1041,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
10041041
}
10051042

10061043
// Select and navigate to the new profile
1007-
SettingsNav().SelectedItem(navItem);
10081044
_Navigate(profileViewModel, BreadcrumbSubPage::None);
1045+
SettingsNav().SelectedItem(navItem);
10091046
}
10101047

10111048
static MUX::Controls::InfoBadge _createGlyphIconBadge(wil::zwstring_view glyph)
@@ -1097,7 +1134,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
10971134

10981135
// navigate to the profile next to this one
10991136
const auto newSelectedItem{ _menuItemSource.GetAt(index < _menuItemSource.Size() - 1 ? index : index - 1) };
1100-
SettingsNav().SelectedItem(newSelectedItem);
11011137
const auto newTag = newSelectedItem.as<MUX::Controls::NavigationViewItem>().Tag();
11021138
if (const auto profileViewModel = newTag.try_as<ProfileViewModel>())
11031139
{
@@ -1110,6 +1146,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
11101146
}
11111147
// Since we are navigating to a new profile after deletion, scroll up to the top
11121148
SettingsMainPage_ScrollViewer().ChangeView(nullptr, 0.0, nullptr);
1149+
SettingsNav().SelectedItem(newSelectedItem);
11131150
}
11141151
}
11151152

@@ -1119,6 +1156,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
11191156
}
11201157

11211158
void MainPage::_NavigateToProfileHandler(const IInspectable& /*sender*/, winrt::guid profileGuid)
1159+
{
1160+
if (const auto profileNavItem = _FindProfileNavItem(profileGuid))
1161+
{
1162+
_Navigate(profileNavItem.Tag().as<Editor::ProfileViewModel>(), BreadcrumbSubPage::None);
1163+
}
1164+
// Silently fail if the profile wasn't found
1165+
}
1166+
1167+
MUX::Controls::NavigationViewItem MainPage::_FindProfileNavItem(winrt::guid profileGuid) const
11221168
{
11231169
for (auto&& menuItem : _menuItemSource)
11241170
{
@@ -1130,21 +1176,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
11301176
{
11311177
if (profileTag->OriginalProfileGuid() == profileGuid)
11321178
{
1133-
SettingsNav().SelectedItem(menuItem);
1134-
_Navigate(*profileTag, BreadcrumbSubPage::None);
1135-
return;
1179+
return navViewItem;
11361180
}
11371181
}
11381182
}
11391183
}
11401184
}
1141-
// Silently fail if the profile wasn't found
1185+
return nullptr;
11421186
}
11431187

11441188
void MainPage::_NavigateToColorSchemeHandler(const IInspectable& /*sender*/, const IInspectable& /*args*/)
11451189
{
1146-
SettingsNav().SelectedItem(ColorSchemesNavItem());
11471190
_Navigate(hstring{ colorSchemesTag }, BreadcrumbSubPage::ColorSchemes_Edit);
1191+
SettingsNav().SelectedItem(ColorSchemesNavItem());
11481192
}
11491193

11501194
winrt::Windows::UI::Xaml::Media::Brush MainPage::BackgroundBrush()
@@ -1366,9 +1410,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
13661410
const auto& navigationArg{ chosenResult->NavigationArg() };
13671411
const auto& subpage{ indexEntry.Entry->SubPage };
13681412
const auto& elementToFocus{ indexEntry.Entry->ElementName };
1369-
if (navigationArg.try_as<hstring>())
1413+
if (const auto navArgString = navigationArg.try_as<hstring>())
13701414
{
1371-
_Navigate(navigationArg.as<hstring>(), subpage, elementToFocus);
1415+
_Navigate(*navArgString, subpage, elementToFocus);
13721416
}
13731417
else if (const auto profileVM = navigationArg.try_as<ProfileViewModel>())
13741418
{
@@ -1382,6 +1426,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
13821426
{
13831427
_Navigate(*extPkgVM, subpage, elementToFocus);
13841428
}
1429+
// TODO CARLOS:
1430+
// - update selected item
1431+
// - clear text box
13851432
}
13861433
}
13871434

src/cascadia/TerminalSettingsEditor/MainPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
114114
void _Navigate(const Editor::ExtensionPackageViewModel& extPkgVM, BreadcrumbSubPage subPage, hstring elementToFocus = {});
115115
void _NavigateToProfileHandler(const IInspectable& sender, winrt::guid profileGuid);
116116
void _NavigateToColorSchemeHandler(const IInspectable& sender, const IInspectable& args);
117+
Microsoft::UI::Xaml::Controls::NavigationViewItem _FindProfileNavItem(winrt::guid profileGuid) const;
117118

118119
void _UpdateBackgroundForMica();
119120
void _MoveXamlParsedNavItemsIntoItemSource();

src/cascadia/TerminalSettingsEditor/MainPage.xaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,24 @@
129129

130130
<muxc:NavigationView.MenuItems>
131131

132-
<muxc:NavigationViewItem x:Uid="Nav_Launch"
132+
<muxc:NavigationViewItem x:Name="LaunchNavItem"
133+
x:Uid="Nav_Launch"
133134
Tag="Launch_Nav">
134135
<muxc:NavigationViewItem.Icon>
135136
<FontIcon Glyph="&#xE7B5;" />
136137
</muxc:NavigationViewItem.Icon>
137138
</muxc:NavigationViewItem>
138139

139-
<muxc:NavigationViewItem x:Uid="Nav_Interaction"
140+
<muxc:NavigationViewItem x:Name="InteractionNavItem"
141+
x:Uid="Nav_Interaction"
140142
Tag="Interaction_Nav">
141143
<muxc:NavigationViewItem.Icon>
142144
<FontIcon Glyph="&#xE7C9;" />
143145
</muxc:NavigationViewItem.Icon>
144146
</muxc:NavigationViewItem>
145147

146-
<muxc:NavigationViewItem x:Uid="Nav_Appearance"
148+
<muxc:NavigationViewItem x:Name="GlobalAppearanceNavItem"
149+
x:Uid="Nav_Appearance"
147150
Tag="GlobalAppearance_Nav">
148151
<muxc:NavigationViewItem.Icon>
149152
<FontIcon Glyph="&#xE771;" />
@@ -158,35 +161,40 @@
158161
</muxc:NavigationViewItem.Icon>
159162
</muxc:NavigationViewItem>
160163

161-
<muxc:NavigationViewItem x:Uid="Nav_Rendering"
164+
<muxc:NavigationViewItem x:Name="RenderingNavItem"
165+
x:Uid="Nav_Rendering"
162166
Tag="Rendering_Nav">
163167
<muxc:NavigationViewItem.Icon>
164168
<FontIcon Glyph="&#xE7F8;" />
165169
</muxc:NavigationViewItem.Icon>
166170
</muxc:NavigationViewItem>
167171

168-
<muxc:NavigationViewItem x:Uid="Nav_Compatibility"
172+
<muxc:NavigationViewItem x:Name="CompatibilityNavItem"
173+
x:Uid="Nav_Compatibility"
169174
Tag="Compatibility_Nav">
170175
<muxc:NavigationViewItem.Icon>
171176
<FontIcon Glyph="&#xEC7A;" />
172177
</muxc:NavigationViewItem.Icon>
173178
</muxc:NavigationViewItem>
174179

175-
<muxc:NavigationViewItem x:Uid="Nav_Actions"
180+
<muxc:NavigationViewItem x:Name="ActionsNavItem"
181+
x:Uid="Nav_Actions"
176182
Tag="Actions_Nav">
177183
<muxc:NavigationViewItem.Icon>
178184
<FontIcon Glyph="&#xE765;" />
179185
</muxc:NavigationViewItem.Icon>
180186
</muxc:NavigationViewItem>
181187

182-
<muxc:NavigationViewItem x:Uid="Nav_NewTabMenu"
188+
<muxc:NavigationViewItem x:Name="NewTabMenuNavItem"
189+
x:Uid="Nav_NewTabMenu"
183190
Tag="NewTabMenu_Nav">
184191
<muxc:NavigationViewItem.Icon>
185192
<FontIcon Glyph="&#xE71d;" />
186193
</muxc:NavigationViewItem.Icon>
187194
</muxc:NavigationViewItem>
188195

189-
<muxc:NavigationViewItem x:Uid="Nav_Extensions"
196+
<muxc:NavigationViewItem x:Name="ExtensionsNavItem"
197+
x:Uid="Nav_Extensions"
190198
Tag="Extensions_Nav">
191199
<muxc:NavigationViewItem.Icon>
192200
<FontIcon Glyph="&#xEA86;" />

0 commit comments

Comments
 (0)