@@ -233,6 +233,7 @@ void AppHost::Initialize()
233233 _revokers.AlwaysOnTopChanged = _windowLogic.AlwaysOnTopChanged (winrt::auto_revoke, { this , &AppHost::_AlwaysOnTopChanged });
234234 _revokers.RaiseVisualBell = _windowLogic.RaiseVisualBell (winrt::auto_revoke, { this , &AppHost::_RaiseVisualBell });
235235 _revokers.SystemMenuChangeRequested = _windowLogic.SystemMenuChangeRequested (winrt::auto_revoke, { this , &AppHost::_SystemMenuChangeRequested });
236+ _revokers.SystemMenuNewTabProfilesChanged = _windowLogic.SystemMenuNewTabProfilesChanged (winrt::auto_revoke, { this , &AppHost::_SystemMenuNewTabProfilesChanged });
236237 _revokers.ChangeMaximizeRequested = _windowLogic.ChangeMaximizeRequested (winrt::auto_revoke, { this , &AppHost::_ChangeMaximizeRequested });
237238 _revokers.RequestLaunchPosition = _windowLogic.RequestLaunchPosition (winrt::auto_revoke, { this , &AppHost::_HandleRequestLaunchPosition });
238239
@@ -304,8 +305,6 @@ void AppHost::Initialize()
304305 // set that content as well.
305306 _window->SetContent (_windowLogic.GetRoot ());
306307 _window->OnAppInitialized ();
307-
308- _PopulateNewTabSubmenu ();
309308}
310309
311310void AppHost::Close ()
@@ -1024,9 +1023,6 @@ void AppHost::_HandleSettingsChanged(const winrt::Windows::Foundation::IInspecta
10241023 _window->SetAutoHideWindow (_windowLogic.AutoHideWindow ());
10251024 _window->SetShowTabsFullscreen (_windowLogic.ShowTabsFullscreen ());
10261025 _updateTheme ();
1027-
1028- // Rebuild the "New Tab" submenu in the system menu to reflect any profile changes
1029- _PopulateNewTabSubmenu ();
10301026}
10311027
10321028void AppHost::_IsQuakeWindowChanged (const winrt::Windows::Foundation::IInspectable&,
@@ -1097,67 +1093,42 @@ void AppHost::_SystemMenuChangeRequested(const winrt::Windows::Foundation::IInsp
10971093}
10981094
10991095// Method Description:
1100- // - Populates a "New Tab" submenu in the system menu (Alt+Space) with
1101- // the user's active profiles.
1096+ // - Handles the SystemMenuNewTabProfilesChanged event from the TerminalPage.
1097+ // Rebuilds the "New Tab" submenu in the system menu (Alt+Space) with items
1098+ // driven by the app layer's action engine.
11021099// Arguments:
1103- // - <none>
1100+ // - args: The SystemMenuNewTabProfilesArgs containing the new list of
1101+ // profiles to show in the "New Tab" submenu.
11041102// Return Value:
11051103// - <none>
1106- void AppHost::_PopulateNewTabSubmenu ( )
1104+ void AppHost::_SystemMenuNewTabProfilesChanged ( const winrt::Windows::Foundation::IInspectable&, const winrt::TerminalApp::SystemMenuNewTabProfilesArgs& args )
11071105{
1108- if (!_window || !_windowLogic )
1106+ if (!_window)
11091107 {
11101108 return ;
11111109 }
11121110
11131111 _window->RemoveSystemSubMenu (L" New Tab" );
11141112
1115- const auto settings = _appLogic.Settings ();
1116- if (!settings)
1117- {
1118- return ;
1119- }
1120-
1121- const auto activeProfiles = settings.ActiveProfiles ();
1122- if (!activeProfiles || activeProfiles.Size () == 0 )
1113+ if (!args || !args.Profiles () || args.Profiles ().Size () == 0 )
11231114 {
11241115 return ;
11251116 }
11261117
1127- const auto defaultProfileGuid = settings.GlobalSettings ().DefaultProfile ();
1128-
11291118 std::vector<std::pair<winrt::hstring, winrt::delegate<void ()>>> profileItems;
1130- profileItems.reserve (activeProfiles .Size ());
1119+ profileItems.reserve (args. Profiles () .Size ());
11311120
1132- for (uint32_t i = 0 ; i < activeProfiles. Size (); i++ )
1121+ for (const auto & item : args. Profiles () )
11331122 {
1134- const auto profile = activeProfiles.GetAt (i);
1135- auto profileName = profile.Name ();
1136-
1137- if (profile.Guid () == defaultProfileGuid)
1138- {
1139- profileName = profileName + L" (default)" ;
1140- }
1141-
1142- auto callback = winrt::delegate<void ()>([weakThis = weak_from_this (), name = winrt::hstring{ profileName }]() {
1143- if (auto strongThis = weakThis.lock ())
1123+ auto handler = item.Handler ();
1124+ auto callback = winrt::delegate<void ()>([handler]() {
1125+ if (handler)
11441126 {
1145- if (strongThis->_windowLogic )
1146- {
1147- const std::array<winrt::hstring, 4 > args{
1148- winrt::hstring{ L" wt.exe" },
1149- winrt::hstring{ L" new-tab" },
1150- winrt::hstring{ L" --profile" },
1151- name,
1152- };
1153- winrt::TerminalApp::CommandlineArgs cmdArgs;
1154- cmdArgs.Commandline (args);
1155- strongThis->_windowLogic .ExecuteCommandline (std::move (cmdArgs));
1156- }
1127+ handler ();
11571128 }
11581129 });
11591130
1160- profileItems.emplace_back (std::move (profileName ), std::move (callback));
1131+ profileItems.emplace_back (item. DisplayName ( ), std::move (callback));
11611132 }
11621133
11631134 _window->AddSystemSubMenu (L" New Tab" , profileItems);
0 commit comments