diff --git a/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp b/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp index d0eadb9c22f..e274767d3d0 100644 --- a/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp @@ -37,7 +37,7 @@ namespace SettingsModelLocalTests TEST_METHOD(TestTerminalArgsForBinding); - TEST_METHOD(MakeSettingsForProfileThatDoesntExist); + TEST_METHOD(MakeSettingsForProfile); TEST_METHOD(MakeSettingsForDefaultProfileThatDoesntExist); TEST_METHOD(TestLayerProfileOnColorScheme); @@ -126,10 +126,10 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid0, guid); + VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(1, termSettings.HistorySize()); } @@ -148,10 +148,10 @@ namespace SettingsModelLocalTests VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid1, guid); + VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(2, termSettings.HistorySize()); } @@ -170,10 +170,10 @@ namespace SettingsModelLocalTests VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid1, guid); + VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(2, termSettings.HistorySize()); } @@ -192,10 +192,10 @@ namespace SettingsModelLocalTests VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(profile2Guid, guid); + VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(3, termSettings.HistorySize()); } @@ -214,10 +214,10 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"foo.exe", realArgs.TerminalArgs().Commandline()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid0, guid); + VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(1, termSettings.HistorySize()); } @@ -237,10 +237,10 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); VERIFY_ARE_EQUAL(L"foo.exe", realArgs.TerminalArgs().Commandline()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid1, guid); + VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(2, termSettings.HistorySize()); } @@ -257,10 +257,10 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid0, guid); + VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(1, termSettings.HistorySize()); } @@ -278,10 +278,10 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"c:\\foo", realArgs.TerminalArgs().StartingDirectory()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid0, guid); + VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"c:\\foo", termSettings.StartingDirectory()); VERIFY_ARE_EQUAL(1, termSettings.HistorySize()); @@ -301,10 +301,10 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(L"c:\\foo", realArgs.TerminalArgs().StartingDirectory()); VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(profile2Guid, guid); + VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"c:\\foo", termSettings.StartingDirectory()); VERIFY_ARE_EQUAL(3, termSettings.HistorySize()); @@ -323,10 +323,10 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid0, guid); + VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"bar", termSettings.StartingTitle()); VERIFY_ARE_EQUAL(1, termSettings.HistorySize()); @@ -346,10 +346,10 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(profile2Guid, guid); + VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"bar", termSettings.StartingTitle()); VERIFY_ARE_EQUAL(3, termSettings.HistorySize()); @@ -371,10 +371,10 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - const auto guid{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; + const auto profile{ settings.GetProfileForArgs(realArgs.TerminalArgs()) }; const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); - VERIFY_ARE_EQUAL(guid1, guid); + VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(L"bar", termSettings.StartingTitle()); VERIFY_ARE_EQUAL(L"c:\\foo", termSettings.StartingDirectory()); @@ -382,9 +382,9 @@ namespace SettingsModelLocalTests } } - void TerminalSettingsTests::MakeSettingsForProfileThatDoesntExist() + void TerminalSettingsTests::MakeSettingsForProfile() { - // Test that making settings throws when the GUID doesn't exist + // Test that making settings generally works. const std::string settingsString{ R"( { "defaultProfile": "{6239a42c-1111-49a3-80bd-e8fdd045185c}", @@ -405,32 +405,32 @@ namespace SettingsModelLocalTests const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); const auto guid2 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); - const auto guid3 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); + + const auto profile1 = settings.FindProfile(guid1); + const auto profile2 = settings.FindProfile(guid2); try { - auto terminalSettings{ TerminalSettings::CreateWithProfileByID(settings, guid1, nullptr) }; + auto terminalSettings{ TerminalSettings::CreateWithProfile(settings, profile1, nullptr) }; VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings); VERIFY_ARE_EQUAL(1, terminalSettings.DefaultSettings().HistorySize()); } catch (...) { - VERIFY_IS_TRUE(false, L"This call to CreateWithProfileByID should succeed"); + VERIFY_IS_TRUE(false, L"This call to CreateWithProfile should succeed"); } try { - auto terminalSettings{ TerminalSettings::CreateWithProfileByID(settings, guid2, nullptr) }; + auto terminalSettings{ TerminalSettings::CreateWithProfile(settings, profile2, nullptr) }; VERIFY_ARE_NOT_EQUAL(nullptr, terminalSettings); VERIFY_ARE_EQUAL(2, terminalSettings.DefaultSettings().HistorySize()); } catch (...) { - VERIFY_IS_TRUE(false, L"This call to CreateWithProfileByID should succeed"); + VERIFY_IS_TRUE(false, L"This call to CreateWithProfile should succeed"); } - VERIFY_THROWS(auto terminalSettings = TerminalSettings::CreateWithProfileByID(settings, guid3, nullptr), wil::ResultException, L"This call to constructor should fail"); - try { const auto termSettings{ TerminalSettings::CreateWithNewTerminalArgs(settings, nullptr, nullptr) }; diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp index 7ae93e093c3..07323750bfa 100644 --- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp @@ -430,7 +430,7 @@ namespace TerminalAppLocalTests Log::Comment(L"Duplicate the tab, and don't crash"); result = RunOnUIThread([&page]() { page->_DuplicateFocusedTab(); - VERIFY_ARE_EQUAL(2u, page->_tabs.Size(), L"We should gracefully do nothing here - the profile no longer exists."); + VERIFY_ARE_EQUAL(3u, page->_tabs.Size(), L"We should successfully duplicate a tab hosting a deleted profile."); }); VERIFY_SUCCEEDED(result); } @@ -530,9 +530,9 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(1u, page->_tabs.Size()); auto tab = page->_GetTerminalTabImpl(page->_tabs.GetAt(0)); - VERIFY_ARE_EQUAL(2, + VERIFY_ARE_EQUAL(3, tab->GetLeafPaneCount(), - L"We should gracefully do nothing here - the profile no longer exists."); + L"We should successfully duplicate a pane hosting a deleted profile."); }); VERIFY_SUCCEEDED(result); diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 9aabdc24868..ee62b60c825 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 f78a1c61e3f..c8e2c5ca9b6 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(); + const 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)); } } } @@ -947,18 +943,18 @@ void Pane::SetActive() } // Method Description: -// - Returns nullopt if no children of this pane were the last control to be -// focused, or the GUID of the profile of the last control to be focused (if -// there was one). +// - Returns nullptr if no children of this pane were the last control to be +// focused, or the profile of the last control to be focused (if there was +// one). // Arguments: // - // 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() +// - nullptr if no children of this pane were the last control to be +// focused, else the profile of the last control to be focused +Profile Pane::GetFocusedProfile() { auto lastFocused = GetActivePane(); - return lastFocused ? lastFocused->_profile : std::nullopt; + return lastFocused ? lastFocused->_profile : nullptr; } // Method Description: @@ -1059,10 +1055,10 @@ void Pane::_FocusFirstChild() // * If we're not a leaf, we'll recurse on our children. // Arguments: // - settings: The new TerminalSettings to apply to any matching controls -// - profile: The GUID of the profile these settings should apply to. +// - profile: The profile from which these settings originated. // 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 @@ -1879,13 +1880,13 @@ std::optional Pane::PreCalculateCanSplit(const std::shared_ptr targe // we'll create two new children, and place them side-by-side in our Grid. // Arguments: // - splitType: what type of split we want to create. -// - profile: The profile GUID to associate with the newly created pane. +// - profile: The profile to associate with the newly created pane. // - control: A TermControl to use in the new pane. // Return Value: // - 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 510229cbc58..681fd7ba93e 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 62d67d2603b..16149d5504d 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 558b71b8748..0910e9a9622 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -733,7 +733,12 @@ 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.GetProfileForArgs(newTerminalArgs); + if (profile) + { + newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); + } } this->_OpenNewWindow(false, newTerminalArgs); } @@ -756,14 +761,18 @@ 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) + { + // Use the default profile if we didn't get one as an argument. + profile = _settings.FindProfile(_settings.GlobalSettings().DefaultProfile()); + } TerminalConnection::ITerminalConnection connection{ nullptr }; @@ -788,7 +797,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 +847,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 +1316,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 +1344,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 +1375,7 @@ namespace winrt::TerminalApp::implementation _UnZoomIfNeeded(); - tab.SplitPane(realSplitType, splitSize, realGuid, newControl); + tab.SplitPane(realSplitType, splitSize, profile, newControl); } CATCH_LOG(); } @@ -1954,19 +1961,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 13e4007eeb1..ae3b8c01211 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 2fbca6c5606..c3fc2324219 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 f22d7e646c6..b72372d18c2 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 f2a6c9326d2..03b05a76617 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 5bb37b3097d..5a5735831fd 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 85882ec08c0..2f3248fbc1f 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 d5202f1d2ff..f547e27d248 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -83,25 +83,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return winrt::make(*settings, child); } - // Method Description: - // - Create a TerminalSettingsCreateResult for the provided profile guid. We'll - // use the guid to look up the profile that should be used to - // create these TerminalSettings. Then, we'll apply settings contained in the - // global and profile settings to the instance. - // Arguments: - // - appSettings: the set of settings being used to construct the new terminal - // - profileGuid: the unique identifier (guid) of the profile - // - keybindings: the keybinding handler - // Return Value: - // - A TerminalSettingsCreateResult, which contains a pair of TerminalSettings objects, - // one for when the terminal is focused and the other for when the terminal is unfocused - Model::TerminalSettingsCreateResult TerminalSettings::CreateWithProfileByID(const Model::CascadiaSettings& appSettings, winrt::guid profileGuid, const IKeyBindings& keybindings) - { - const auto profile = appSettings.FindProfile(profileGuid); - THROW_HR_IF_NULL(E_INVALIDARG, profile); - return CreateWithProfile(appSettings, profile, keybindings); - } - // Method Description: // - Create a TerminalSettings object for the provided newTerminalArgs. We'll // use the newTerminalArgs to look up the profile that should be used to @@ -124,8 +105,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) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index bda1f24cd65..3744c10573a 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -60,10 +60,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation const Model::Profile& profile, const Control::IKeyBindings& keybindings); - static Model::TerminalSettingsCreateResult CreateWithProfileByID(const Model::CascadiaSettings& appSettings, - guid profileGuid, - const Control::IKeyBindings& keybindings); - static Model::TerminalSettingsCreateResult CreateWithNewTerminalArgs(const Model::CascadiaSettings& appSettings, const Model::NewTerminalArgs& newTerminalArgs, const Control::IKeyBindings& keybindings); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.idl b/src/cascadia/TerminalSettingsModel/TerminalSettings.idl index a28c6ab81a8..c40aba55557 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.idl +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.idl @@ -27,7 +27,6 @@ namespace Microsoft.Terminal.Settings.Model TerminalSettings(); static TerminalSettingsCreateResult CreateWithProfile(CascadiaSettings appSettings, Profile profile, Microsoft.Terminal.Control.IKeyBindings keybindings); - static TerminalSettingsCreateResult CreateWithProfileByID(CascadiaSettings appSettings, Guid profileGuid, Microsoft.Terminal.Control.IKeyBindings keybindings); static TerminalSettingsCreateResult CreateWithNewTerminalArgs(CascadiaSettings appSettings, NewTerminalArgs newTerminalArgs, Microsoft.Terminal.Control.IKeyBindings keybindings); static TerminalSettingsCreateResult CreateWithParent(TerminalSettingsCreateResult parent);