From 9e5fd96781846246ebcd78e8d595f31a221c075a Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Wed, 18 Aug 2021 11:40:46 -0700 Subject: [PATCH] Reduce the number of GUID round trips when looking up profiles. This commit also moves to storing a reference to the active profile inside Pane and propagating it out of Pane through Tab. This lets us duplicate a pane even if its profile is missing, and gives us the freedom in the future to return a "base" profile (;)) Related to #5047. --- .../TerminalApp/AppActionHandlers.cpp | 5 +- src/cascadia/TerminalApp/Pane.cpp | 39 ++++++------ src/cascadia/TerminalApp/Pane.h | 10 +-- src/cascadia/TerminalApp/TabManagement.cpp | 62 +++++++------------ src/cascadia/TerminalApp/TerminalPage.cpp | 45 +++++++------- src/cascadia/TerminalApp/TerminalPage.h | 4 +- src/cascadia/TerminalApp/TerminalTab.cpp | 8 +-- src/cascadia/TerminalApp/TerminalTab.h | 8 +-- .../CascadiaSettings.cpp | 14 ++--- .../TerminalSettingsModel/CascadiaSettings.h | 6 +- .../CascadiaSettings.idl | 4 +- .../TerminalSettings.cpp | 4 +- 12 files changed, 94 insertions(+), 115 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 9aabdc24868e..ee62b60c825c 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -753,11 +753,10 @@ namespace winrt::TerminalApp::implementation newTerminalArgs = NewTerminalArgs(); } - const auto profileGuid{ _settings.GetProfileForArgs(newTerminalArgs) }; - const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) }; + const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) }; // Manually fill in the evaluated profile. - newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profileGuid)); + newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); _OpenNewWindow(false, newTerminalArgs); actionArgs.Handled(true); } diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index f78a1c61e3f7..e75219e6a40a 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -34,7 +34,7 @@ static const Duration AnimationDuration = DurationHelper::FromTimeSpan(winrt::Wi winrt::Windows::UI::Xaml::Media::SolidColorBrush Pane::s_focusedBorderBrush = { nullptr }; winrt::Windows::UI::Xaml::Media::SolidColorBrush Pane::s_unfocusedBorderBrush = { nullptr }; -Pane::Pane(const GUID& profile, const TermControl& control, const bool lastFocused) : +Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFocused) : _control{ control }, _lastActive{ lastFocused }, _profile{ profile } @@ -758,11 +758,9 @@ void Pane::_ControlConnectionStateChangedHandler(const winrt::Windows::Foundatio return; } - const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() }; - auto paneProfile = settings.FindProfile(_profile.value()); - if (paneProfile) + if (_profile) { - auto mode = paneProfile.CloseOnExit(); + auto mode = _profile.CloseOnExit(); if ((mode == CloseOnExitMode::Always) || (mode == CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed)) { @@ -786,27 +784,25 @@ void Pane::_ControlWarningBellHandler(const winrt::Windows::Foundation::IInspect { return; } - const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() }; - auto paneProfile = settings.FindProfile(_profile.value()); - if (paneProfile) + if (_profile) { // We don't want to do anything if nothing is set, so check for that first - if (static_cast(paneProfile.BellStyle()) != 0) + if (static_cast(_profile.BellStyle()) != 0) { - if (WI_IsFlagSet(paneProfile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible)) + if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible)) { // Audible is set, play the sound const auto soundAlias = reinterpret_cast(SND_ALIAS_SYSTEMHAND); PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); } - if (WI_IsFlagSet(paneProfile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window)) + if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window)) { _control.BellLightOn(); } // raise the event with the bool value corresponding to the taskbar flag - _PaneRaiseBellHandlers(nullptr, WI_IsFlagSet(paneProfile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Taskbar)); + _PaneRaiseBellHandlers(nullptr, WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Taskbar)); } } } @@ -955,10 +951,10 @@ void Pane::SetActive() // Return Value: // - nullopt if no children of this pane were the last control to be // focused, else the GUID of the profile of the last control to be focused -std::optional Pane::GetFocusedProfile() +Profile Pane::GetFocusedProfile() { auto lastFocused = GetActivePane(); - return lastFocused ? lastFocused->_profile : std::nullopt; + return lastFocused ? lastFocused->_profile : nullptr; } // Method Description: @@ -1062,7 +1058,7 @@ void Pane::_FocusFirstChild() // - profile: The GUID of the profile these settings should apply to. // Return Value: // - -void Pane::UpdateSettings(const TerminalSettingsCreateResult& settings, const GUID& profile) +void Pane::UpdateSettings(const TerminalSettingsCreateResult& settings, const Profile& profile) { if (!_IsLeaf()) { @@ -1071,8 +1067,13 @@ void Pane::UpdateSettings(const TerminalSettingsCreateResult& settings, const GU } else { - if (profile == _profile) + // Because this call may be coming in with a different settings tree, + // we want to map the incoming profile based on its GUID. + // Failure to find a matching profile will result in a pane holding + // a reference to a deleted profile (which is okay!). + if (profile.Guid() == _profile.Guid()) { + _profile = profile; auto controlSettings = _control.Settings().as(); // Update the parent of the control's settings object (and not the object itself) so // that any overrides made by the control don't get affected by the reload @@ -1885,7 +1886,7 @@ std::optional Pane::PreCalculateCanSplit(const std::shared_ptr targe // - The two newly created Panes std::pair, std::shared_ptr> Pane::Split(SplitState splitType, const float splitSize, - const GUID& profile, + const Profile& profile, const TermControl& control) { if (!_IsLeaf()) @@ -2015,9 +2016,9 @@ std::pair, std::shared_ptr> Pane::_Split(SplitState // Create two new Panes // Move our control, guid into the first one. // Move the new guid, control into the second. - _firstChild = std::make_shared(_profile.value(), _control); + _firstChild = std::make_shared(_profile, _control); _firstChild->_connectionState = std::exchange(_connectionState, ConnectionState::NotConnected); - _profile = std::nullopt; + _profile = nullptr; _control = { nullptr }; _secondChild = newPane; diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index 510229cbc58d..681fd7ba93e9 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -47,13 +47,13 @@ DEFINE_ENUM_FLAG_OPERATORS(Borders); class Pane : public std::enable_shared_from_this { public: - Pane(const GUID& profile, + Pane(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, const winrt::Microsoft::Terminal::Control::TermControl& control, const bool lastFocused = false); std::shared_ptr GetActivePane(); winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl(); - std::optional GetFocusedProfile(); + winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile(); winrt::Windows::UI::Xaml::Controls::Grid GetRootElement(); @@ -63,7 +63,7 @@ class Pane : public std::enable_shared_from_this void SetActive(); void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, - const GUID& profile); + const winrt::Microsoft::Terminal::Settings::Model::Profile& profile); void ResizeContent(const winrt::Windows::Foundation::Size& newSize); void Relayout(); bool ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction); @@ -75,7 +75,7 @@ class Pane : public std::enable_shared_from_this std::pair, std::shared_ptr> Split(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType, const float splitSize, - const GUID& profile, + const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, const winrt::Microsoft::Terminal::Control::TermControl& control); bool ToggleSplitOrientation(); float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const; @@ -160,7 +160,7 @@ class Pane : public std::enable_shared_from_this std::optional _id; bool _lastActive{ false }; - std::optional _profile{ std::nullopt }; + winrt::Microsoft::Terminal::Settings::Model::Profile _profile{ nullptr }; winrt::event_token _connectionStateChangedToken{ 0 }; winrt::event_token _firstClosedToken{ 0 }; winrt::event_token _secondClosedToken{ 0 }; diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 62d67d2603b7..16149d5504d9 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -59,10 +59,10 @@ namespace winrt::TerminalApp::implementation HRESULT TerminalPage::_OpenNewTab(const NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection) try { - const auto profileGuid{ _settings.GetProfileForArgs(newTerminalArgs) }; + const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) }; const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) }; - _CreateNewTabFromSettings(profileGuid, settings, existingConnection); + _CreateNewTabWithProfileAndSettings(profile, settings, existingConnection); const uint32_t tabCount = _tabs.Size(); const bool usedManualProfile = (newTerminalArgs != nullptr) && @@ -70,7 +70,7 @@ namespace winrt::TerminalApp::implementation newTerminalArgs.Profile().empty()); // Lookup the name of the color scheme used by this profile. - const auto scheme = _settings.GetColorSchemeForProfile(profileGuid); + const auto scheme = _settings.GetColorSchemeForProfile(profile); // If they explicitly specified `null` as the scheme (indicating _no_ scheme), log // that as the empty string. const auto schemeName = scheme ? scheme.Name() : L"\0"; @@ -82,7 +82,7 @@ namespace winrt::TerminalApp::implementation TraceLoggingUInt32(1u, "EventVer", "Version of this event"), TraceLoggingUInt32(tabCount, "TabCount", "Count of tabs currently opened in TerminalApp"), TraceLoggingBool(usedManualProfile, "ProfileSpecified", "Whether the new tab specified a profile explicitly"), - TraceLoggingGuid(profileGuid, "ProfileGuid", "The GUID of the profile spawned in the new tab"), + TraceLoggingGuid(profile.Guid(), "ProfileGuid", "The GUID of the profile spawned in the new tab"), TraceLoggingBool(settings.DefaultSettings().UseAcrylic(), "UseAcrylic", "The acrylic preference from the settings"), TraceLoggingFloat64(settings.DefaultSettings().TintOpacity(), "TintOpacity", "Opacity preference from the settings"), TraceLoggingWideString(settings.DefaultSettings().FontFace().c_str(), "FontFace", "Font face chosen in the settings"), @@ -175,10 +175,9 @@ namespace winrt::TerminalApp::implementation _tabView.TabItems().Append(tabViewItem); // Set this tab's icon to the icon from the user's profile - if (const auto profileGuid = newTabImpl->GetFocusedProfile()) + if (const auto profile{ newTabImpl->GetFocusedProfile() }) { - const auto profile = _settings.FindProfile(profileGuid.value()); - if (profile != nullptr && !profile.Icon().empty()) + if (!profile.Icon().empty()) { newTabImpl->UpdateIcon(profile.Icon()); } @@ -233,14 +232,14 @@ namespace winrt::TerminalApp::implementation // - Creates a new tab with the given settings. If the tab bar is not being // currently displayed, it will be shown. // Arguments: - // - profileGuid: ID to use to lookup profile settings for this connection + // - profile: profile settings for this connection // - settings: the TerminalSettings object to use to create the TerminalControl with. // - existingConnection: optionally receives a connection from the outside world instead of attempting to create one - void TerminalPage::_CreateNewTabFromSettings(GUID profileGuid, const TerminalSettingsCreateResult& settings, TerminalConnection::ITerminalConnection existingConnection) + void TerminalPage::_CreateNewTabWithProfileAndSettings(const Profile& profile, const TerminalSettingsCreateResult& settings, TerminalConnection::ITerminalConnection existingConnection) { // Initialize the new tab // Create a connection based on the values in our settings object if we weren't given one. - auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings(profileGuid, settings.DefaultSettings()); + auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings(profile, settings.DefaultSettings()); // If we had an `existingConnection`, then this is an inbound handoff from somewhere else. // 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 // This way, when we do a settings reload we just update the parent and the overrides remain auto term = _InitControl(settings, connection); - auto newTabImpl = winrt::make_self(profileGuid, term); + auto newTabImpl = winrt::make_self(profile, term); _RegisterTerminalEvents(term); _InitializeTab(newTabImpl); @@ -277,7 +276,7 @@ namespace winrt::TerminalApp::implementation auto newControl = _InitControl(settings, debugConnection); _RegisterTerminalEvents(newControl); // Split (auto) with the debug tap. - newTabImpl->SplitPane(SplitState::Automatic, 0.5f, profileGuid, newControl); + newTabImpl->SplitPane(SplitState::Automatic, 0.5f, profile, newControl); } } @@ -288,19 +287,9 @@ namespace winrt::TerminalApp::implementation // - tab: the Tab to update the title for. void TerminalPage::_UpdateTabIcon(TerminalTab& tab) { - const auto lastFocusedProfileOpt = tab.GetFocusedProfile(); - if (lastFocusedProfileOpt.has_value()) + if (const auto profile = tab.GetFocusedProfile()) { - const auto lastFocusedProfile = lastFocusedProfileOpt.value(); - const auto matchingProfile = _settings.FindProfile(lastFocusedProfile); - if (matchingProfile) - { - tab.UpdateIcon(matchingProfile.Icon()); - } - else - { - tab.UpdateIcon({}); - } + tab.UpdateIcon(profile.Icon()); } } @@ -354,23 +343,16 @@ namespace winrt::TerminalApp::implementation { try { - // TODO: GH#5047 - In the future, we should get the Profile of - // the focused pane, and use that to build a new instance of the - // settings so we can duplicate this tab/pane. - // - // Currently, if the profile doesn't exist anymore in our - // settings, we'll silently do nothing. + // TODO: GH#5047 - We're duplicating the whole profile, which might + // be a dangling reference to old settings. // - // In the future, it will be preferable to just duplicate the - // current control's settings, but we can't do that currently, - // because we won't be able to create a new instance of the - // connection without keeping an instance of the original Profile - // object around. - - const auto& profileGuid = tab.GetFocusedProfile(); - if (profileGuid.has_value()) + // In the future, it may be preferable to just duplicate the + // current control's live settings (which will include changes + // made through VT). + + if (const auto profile = tab.GetFocusedProfile()) { - const auto settingsCreateResult{ TerminalSettings::CreateWithProfileByID(_settings, profileGuid.value(), *_bindings) }; + const auto settingsCreateResult{ TerminalSettings::CreateWithProfile(_settings, profile, *_bindings) }; const auto workingDirectory = tab.GetActiveTerminalControl().WorkingDirectory(); const auto validWorkingDirectory = !workingDirectory.empty(); if (validWorkingDirectory) @@ -378,7 +360,7 @@ namespace winrt::TerminalApp::implementation settingsCreateResult.DefaultSettings().StartingDirectory(workingDirectory); } - _CreateNewTabFromSettings(profileGuid.value(), settingsCreateResult); + _CreateNewTabWithProfileAndSettings(profile, settingsCreateResult); const auto runtimeTabText{ tab.GetTabText() }; if (!runtimeTabText.empty()) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 558b71b87485..a3685c2dacbd 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -733,7 +733,9 @@ namespace winrt::TerminalApp::implementation // Manually fill in the evaluated profile. if (newTerminalArgs.ProfileIndex() != nullptr) { - newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(this->_settings.GetProfileForArgs(newTerminalArgs))); + // We want to promote the index to a GUID because there is no "launch to profile index" command. + const auto profile = _settings.ActiveProfiles().GetAt(newTerminalArgs.ProfileIndex().Value()); + newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); } this->_OpenNewWindow(false, newTerminalArgs); } @@ -756,14 +758,17 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Creates a new connection based on the profile settings // Arguments: - // - the profile GUID we want the settings from + // - the profile we want the settings from // - the terminal settings // Return value: // - the desired connection - TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(GUID profileGuid, + TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(Profile profile, TerminalSettings settings) { - const auto profile = _settings.FindProfile(profileGuid); + if (!profile) + { + profile = _settings.ProfileDefaults(); + } TerminalConnection::ITerminalConnection connection{ nullptr }; @@ -788,7 +793,8 @@ namespace winrt::TerminalApp::implementation else { - std::wstring guidWString = Utils::GuidToString(profileGuid); + // profile is guaranteed to exist here + std::wstring guidWString = Utils::GuidToString(profile.Guid()); StringMap envMap{}; envMap.Insert(L"WT_PROFILE_ID", guidWString); @@ -837,7 +843,7 @@ namespace winrt::TerminalApp::implementation "ConnectionCreated", TraceLoggingDescription("Event emitted upon the creation of a connection"), TraceLoggingGuid(connectionType, "ConnectionTypeGuid", "The type of the connection"), - TraceLoggingGuid(profileGuid, "ProfileGuid", "The profile's GUID"), + TraceLoggingGuid(profile.Guid(), "ProfileGuid", "The profile's GUID"), TraceLoggingGuid(sessionGuid, "SessionGuid", "The WT_SESSION's GUID"), TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance)); @@ -1306,23 +1312,20 @@ namespace winrt::TerminalApp::implementation try { TerminalSettingsCreateResult controlSettings{ nullptr }; - GUID realGuid; - bool profileFound = false; + Profile profile{ nullptr }; if (splitMode == SplitType::Duplicate) { - std::optional current_guid = tab.GetFocusedProfile(); - if (current_guid) + profile = tab.GetFocusedProfile(); + if (profile) { - profileFound = true; - controlSettings = TerminalSettings::CreateWithProfileByID(_settings, current_guid.value(), *_bindings); + controlSettings = TerminalSettings::CreateWithProfile(_settings, profile, *_bindings); const auto workingDirectory = tab.GetActiveTerminalControl().WorkingDirectory(); const auto validWorkingDirectory = !workingDirectory.empty(); if (validWorkingDirectory) { controlSettings.DefaultSettings().StartingDirectory(workingDirectory); } - realGuid = current_guid.value(); } // TODO: GH#5047 - In the future, we should get the Profile of // the focused pane, and use that to build a new instance of the @@ -1337,13 +1340,13 @@ namespace winrt::TerminalApp::implementation // connection without keeping an instance of the original Profile // object around. } - if (!profileFound) + if (!profile) { - realGuid = _settings.GetProfileForArgs(newTerminalArgs); + profile = _settings.GetProfileForArgs(newTerminalArgs); controlSettings = TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings); } - const auto controlConnection = _CreateConnectionFromSettings(realGuid, controlSettings.DefaultSettings()); + const auto controlConnection = _CreateConnectionFromSettings(profile, controlSettings.DefaultSettings()); const float contentWidth = ::base::saturated_cast(_tabContent.ActualWidth()); const float contentHeight = ::base::saturated_cast(_tabContent.ActualHeight()); @@ -1368,7 +1371,7 @@ namespace winrt::TerminalApp::implementation _UnZoomIfNeeded(); - tab.SplitPane(realSplitType, splitSize, realGuid, newControl); + tab.SplitPane(realSplitType, splitSize, profile, newControl); } CATCH_LOG(); } @@ -1954,19 +1957,15 @@ namespace winrt::TerminalApp::implementation auto profiles = _settings.ActiveProfiles(); for (const auto& profile : profiles) { - const auto profileGuid = profile.Guid(); - try { - // This can throw an exception if the profileGuid does - // not belong to an actual profile in the list of profiles. - auto settings{ TerminalSettings::CreateWithProfileByID(_settings, profileGuid, *_bindings) }; + auto settings{ TerminalSettings::CreateWithProfile(_settings, profile, *_bindings) }; for (auto tab : _tabs) { if (auto terminalTab = _GetTerminalTabImpl(tab)) { - terminalTab->UpdateSettings(settings, profileGuid); + terminalTab->UpdateSettings(settings, profile); } } } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 13e4007eeb1f..ae3b8c012112 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -189,8 +189,8 @@ namespace winrt::TerminalApp::implementation void _OpenNewTabDropdown(); HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr); void _CreateNewTabFromPane(std::shared_ptr pane); - void _CreateNewTabFromSettings(GUID profileGuid, const Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr); - winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(GUID profileGuid, Microsoft::Terminal::Settings::Model::TerminalSettings settings); + void _CreateNewTabWithProfileAndSettings(const Microsoft::Terminal::Settings::Model::Profile& profile, const Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr); + winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings); winrt::fire_and_forget _OpenNewWindow(const bool elevate, const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs); diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 2fbca6c5606a..c3fc23242195 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -25,7 +25,7 @@ namespace winrt namespace winrt::TerminalApp::implementation { - TerminalTab::TerminalTab(const GUID& profile, const TermControl& control) + TerminalTab::TerminalTab(const Profile& profile, const TermControl& control) { _rootPane = std::make_shared(profile, control, true); @@ -257,7 +257,7 @@ namespace winrt::TerminalApp::implementation // Return Value: // - nullopt if no children of this tab were the last control to be // focused, else the GUID of the profile of the last control to be focused - std::optional TerminalTab::GetFocusedProfile() const noexcept + Profile TerminalTab::GetFocusedProfile() const noexcept { return _activePane->GetFocusedProfile(); } @@ -269,7 +269,7 @@ namespace winrt::TerminalApp::implementation // - profile: The GUID of the profile these settings should apply to. // Return Value: // - - void TerminalTab::UpdateSettings(const TerminalSettingsCreateResult& settings, const GUID& profile) + void TerminalTab::UpdateSettings(const TerminalSettingsCreateResult& settings, const Profile& profile) { _rootPane->UpdateSettings(settings, profile); @@ -451,7 +451,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalTab::SplitPane(SplitState splitType, const float splitSize, - const GUID& profile, + const Profile& profile, TermControl& control) { // Make sure to take the ID before calling Split() - Split() will clear out the active pane's ID diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index f22d7e646c65..b72372d18c29 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -21,14 +21,14 @@ namespace winrt::TerminalApp::implementation struct TerminalTab : TerminalTabT { public: - TerminalTab(const GUID& profile, const winrt::Microsoft::Terminal::Control::TermControl& control); + TerminalTab(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, const winrt::Microsoft::Terminal::Control::TermControl& control); TerminalTab(std::shared_ptr rootPane); // Called after construction to perform the necessary setup, which relies on weak_ptr void Initialize(); winrt::Microsoft::Terminal::Control::TermControl GetActiveTerminalControl() const; - std::optional GetFocusedProfile() const noexcept; + winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile() const noexcept; void Focus(winrt::Windows::UI::Xaml::FocusState focusState) override; @@ -40,7 +40,7 @@ namespace winrt::TerminalApp::implementation void SplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType, const float splitSize, - const GUID& profile, + const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, winrt::Microsoft::Terminal::Control::TermControl& control); void ToggleSplitOrientation(); @@ -62,7 +62,7 @@ namespace winrt::TerminalApp::implementation bool SwapPane(const winrt::Microsoft::Terminal::Settings::Model::FocusDirection& direction); bool FocusPane(const uint32_t id); - void UpdateSettings(const Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, const GUID& profile); + void UpdateSettings(const Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, const winrt::Microsoft::Terminal::Settings::Model::Profile& profile); winrt::fire_and_forget UpdateTitle(); void Shutdown() override; diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index f2a6c9326d22..140401458e1e 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -136,13 +136,12 @@ void CascadiaSettings::_CopyProfileInheritanceTree(winrt::com_ptr profileByIndex, profileByName; if (newTerminalArgs) @@ -818,7 +817,7 @@ winrt::guid CascadiaSettings::GetProfileForArgs(const Model::NewTerminalArgs& ne profileByName = _GetProfileGuidByName(newTerminalArgs.Profile()); } - return til::coalesce_value(profileByName, profileByIndex, _globals->DefaultProfile()); + return FindProfile(til::coalesce_value(profileByName, profileByIndex, _globals->DefaultProfile())); } // Method Description: @@ -1043,9 +1042,8 @@ std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::strin // - profileGuid: the GUID of the profile to find the scheme for. // Return Value: // - a non-owning pointer to the scheme. -winrt::Microsoft::Terminal::Settings::Model::ColorScheme CascadiaSettings::GetColorSchemeForProfile(const winrt::guid profileGuid) const +winrt::Microsoft::Terminal::Settings::Model::ColorScheme CascadiaSettings::GetColorSchemeForProfile(const Model::Profile& profile) const { - auto profile = FindProfile(profileGuid); if (!profile) { return nullptr; diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h index 5bb37b3097d8..5a5735831fd2 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h @@ -86,8 +86,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static winrt::hstring ApplicationVersion(); Model::Profile CreateNewProfile(); - Model::Profile FindProfile(guid profileGuid) const noexcept; - Model::ColorScheme GetColorSchemeForProfile(const guid profileGuid) const; + Model::Profile FindProfile(const guid& profileGuid) const noexcept; + Model::ColorScheme GetColorSchemeForProfile(const Model::Profile& profile) const; void UpdateColorSchemeReferences(const hstring oldName, const hstring newName); Windows::Foundation::Collections::IVectorView Warnings(); @@ -96,7 +96,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Windows::Foundation::IReference GetLoadingError(); hstring GetSerializationErrorMessage(); - winrt::guid GetProfileForArgs(const Model::NewTerminalArgs& newTerminalArgs) const; + Model::Profile GetProfileForArgs(const Model::NewTerminalArgs& newTerminalArgs) const; Model::Profile DuplicateProfile(const Model::Profile& source); void RefreshDefaultTerminals(); diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl b/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl index 85882ec08c07..2f3248fbc1fe 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl @@ -41,10 +41,10 @@ namespace Microsoft.Terminal.Settings.Model Profile CreateNewProfile(); Profile FindProfile(Guid profileGuid); - ColorScheme GetColorSchemeForProfile(Guid profileGuid); + ColorScheme GetColorSchemeForProfile(Profile profile); void UpdateColorSchemeReferences(String oldName, String newName); - Guid GetProfileForArgs(NewTerminalArgs newTerminalArgs); + Profile GetProfileForArgs(NewTerminalArgs newTerminalArgs); void RefreshDefaultTerminals(); static Boolean IsDefaultTerminalAvailable { get; }; diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index d5202f1d2ffa..76780ac6918b 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -124,8 +124,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation const NewTerminalArgs& newTerminalArgs, const IKeyBindings& keybindings) { - const guid profileGuid = appSettings.GetProfileForArgs(newTerminalArgs); - auto settingsPair{ CreateWithProfileByID(appSettings, profileGuid, keybindings) }; + const auto profile = appSettings.GetProfileForArgs(newTerminalArgs); + auto settingsPair{ CreateWithProfile(appSettings, profile, keybindings) }; auto defaultSettings = settingsPair.DefaultSettings(); if (newTerminalArgs)