@@ -59,18 +59,18 @@ namespace winrt::TerminalApp::implementation
5959 HRESULT TerminalPage::_OpenNewTab (const NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection)
6060 try
6161 {
62- const auto profileGuid { _settings.GetProfileForArgs (newTerminalArgs) };
62+ const auto profile { _settings.GetProfileForArgs (newTerminalArgs) };
6363 const auto settings{ TerminalSettings::CreateWithNewTerminalArgs (_settings, newTerminalArgs, *_bindings) };
6464
65- _CreateNewTabFromSettings (profileGuid , settings, existingConnection);
65+ _CreateNewTabWithProfileAndSettings (profile , settings, existingConnection);
6666
6767 const uint32_t tabCount = _tabs.Size ();
6868 const bool usedManualProfile = (newTerminalArgs != nullptr ) &&
6969 (newTerminalArgs.ProfileIndex () != nullptr ||
7070 newTerminalArgs.Profile ().empty ());
7171
7272 // Lookup the name of the color scheme used by this profile.
73- const auto scheme = _settings.GetColorSchemeForProfile (profileGuid );
73+ const auto scheme = _settings.GetColorSchemeForProfile (profile );
7474 // If they explicitly specified `null` as the scheme (indicating _no_ scheme), log
7575 // that as the empty string.
7676 const auto schemeName = scheme ? scheme.Name () : L" \0 " ;
@@ -82,7 +82,7 @@ namespace winrt::TerminalApp::implementation
8282 TraceLoggingUInt32 (1u , " EventVer" , " Version of this event" ),
8383 TraceLoggingUInt32 (tabCount, " TabCount" , " Count of tabs currently opened in TerminalApp" ),
8484 TraceLoggingBool (usedManualProfile, " ProfileSpecified" , " Whether the new tab specified a profile explicitly" ),
85- TraceLoggingGuid (profileGuid , " ProfileGuid" , " The GUID of the profile spawned in the new tab" ),
85+ TraceLoggingGuid (profile. Guid () , " ProfileGuid" , " The GUID of the profile spawned in the new tab" ),
8686 TraceLoggingBool (settings.DefaultSettings ().UseAcrylic (), " UseAcrylic" , " The acrylic preference from the settings" ),
8787 TraceLoggingFloat64 (settings.DefaultSettings ().TintOpacity (), " TintOpacity" , " Opacity preference from the settings" ),
8888 TraceLoggingWideString (settings.DefaultSettings ().FontFace ().c_str (), " FontFace" , " Font face chosen in the settings" ),
@@ -175,10 +175,9 @@ namespace winrt::TerminalApp::implementation
175175 _tabView.TabItems ().Append (tabViewItem);
176176
177177 // Set this tab's icon to the icon from the user's profile
178- if (const auto profileGuid = newTabImpl->GetFocusedProfile ())
178+ if (const auto profile{ newTabImpl->GetFocusedProfile () } )
179179 {
180- const auto profile = _settings.FindProfile (profileGuid.value ());
181- if (profile != nullptr && !profile.Icon ().empty ())
180+ if (!profile.Icon ().empty ())
182181 {
183182 newTabImpl->UpdateIcon (profile.Icon ());
184183 }
@@ -233,14 +232,14 @@ namespace winrt::TerminalApp::implementation
233232 // - Creates a new tab with the given settings. If the tab bar is not being
234233 // currently displayed, it will be shown.
235234 // Arguments:
236- // - profileGuid: ID to use to lookup profile settings for this connection
235+ // - profile: profile settings for this connection
237236 // - settings: the TerminalSettings object to use to create the TerminalControl with.
238237 // - existingConnection: optionally receives a connection from the outside world instead of attempting to create one
239- void TerminalPage::_CreateNewTabFromSettings (GUID profileGuid , const TerminalSettingsCreateResult& settings, TerminalConnection::ITerminalConnection existingConnection)
238+ void TerminalPage::_CreateNewTabWithProfileAndSettings ( const Profile& profile , const TerminalSettingsCreateResult& settings, TerminalConnection::ITerminalConnection existingConnection)
240239 {
241240 // Initialize the new tab
242241 // Create a connection based on the values in our settings object if we weren't given one.
243- auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings (profileGuid , settings.DefaultSettings ());
242+ auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings (profile , settings.DefaultSettings ());
244243
245244 // If we had an `existingConnection`, then this is an inbound handoff from somewhere else.
246245 // We need to tell it about our size information so it can match the dimensions of what
@@ -268,7 +267,7 @@ namespace winrt::TerminalApp::implementation
268267 // This way, when we do a settings reload we just update the parent and the overrides remain
269268 auto term = _InitControl (settings, connection);
270269
271- auto newTabImpl = winrt::make_self<TerminalTab>(profileGuid , term);
270+ auto newTabImpl = winrt::make_self<TerminalTab>(profile , term);
272271 _RegisterTerminalEvents (term);
273272 _InitializeTab (newTabImpl);
274273
@@ -277,7 +276,7 @@ namespace winrt::TerminalApp::implementation
277276 auto newControl = _InitControl (settings, debugConnection);
278277 _RegisterTerminalEvents (newControl);
279278 // Split (auto) with the debug tap.
280- newTabImpl->SplitPane (SplitState::Automatic, 0 .5f , profileGuid , newControl);
279+ newTabImpl->SplitPane (SplitState::Automatic, 0 .5f , profile , newControl);
281280 }
282281 }
283282
@@ -288,19 +287,9 @@ namespace winrt::TerminalApp::implementation
288287 // - tab: the Tab to update the title for.
289288 void TerminalPage::_UpdateTabIcon (TerminalTab& tab)
290289 {
291- const auto lastFocusedProfileOpt = tab.GetFocusedProfile ();
292- if (lastFocusedProfileOpt.has_value ())
290+ if (const auto profile = tab.GetFocusedProfile ())
293291 {
294- const auto lastFocusedProfile = lastFocusedProfileOpt.value ();
295- const auto matchingProfile = _settings.FindProfile (lastFocusedProfile);
296- if (matchingProfile)
297- {
298- tab.UpdateIcon (matchingProfile.Icon ());
299- }
300- else
301- {
302- tab.UpdateIcon ({});
303- }
292+ tab.UpdateIcon (profile.Icon ());
304293 }
305294 }
306295
@@ -354,31 +343,24 @@ namespace winrt::TerminalApp::implementation
354343 {
355344 try
356345 {
357- // TODO: GH#5047 - In the future, we should get the Profile of
358- // the focused pane, and use that to build a new instance of the
359- // settings so we can duplicate this tab/pane.
360- //
361- // Currently, if the profile doesn't exist anymore in our
362- // settings, we'll silently do nothing.
346+ // TODO: GH#5047 - We're duplicating the whole profile, which might
347+ // be a dangling reference to old settings.
363348 //
364- // In the future, it will be preferable to just duplicate the
365- // current control's settings, but we can't do that currently,
366- // because we won't be able to create a new instance of the
367- // connection without keeping an instance of the original Profile
368- // object around.
369-
370- const auto & profileGuid = tab.GetFocusedProfile ();
371- if (profileGuid.has_value ())
349+ // In the future, it may be preferable to just duplicate the
350+ // current control's live settings (which will include changes
351+ // made through VT).
352+
353+ if (const auto profile = tab.GetFocusedProfile ())
372354 {
373- const auto settingsCreateResult{ TerminalSettings::CreateWithProfileByID (_settings, profileGuid. value () , *_bindings) };
355+ const auto settingsCreateResult{ TerminalSettings::CreateWithProfile (_settings, profile , *_bindings) };
374356 const auto workingDirectory = tab.GetActiveTerminalControl ().WorkingDirectory ();
375357 const auto validWorkingDirectory = !workingDirectory.empty ();
376358 if (validWorkingDirectory)
377359 {
378360 settingsCreateResult.DefaultSettings ().StartingDirectory (workingDirectory);
379361 }
380362
381- _CreateNewTabFromSettings (profileGuid. value () , settingsCreateResult);
363+ _CreateNewTabWithProfileAndSettings (profile , settingsCreateResult);
382364
383365 const auto runtimeTabText{ tab.GetTabText () };
384366 if (!runtimeTabText.empty ())
0 commit comments