diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 8770f6037dc3..4860b9d9135e 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -320,7 +320,8 @@ namespace winrt::TerminalApp::implementation if (auto activeControl = activeTab->GetActiveTerminalControl()) { auto controlSettings = activeControl.Settings(); - if (_settings->ApplyColorScheme(controlSettings, realArgs.SchemeName())) + const auto settingsImpl{ winrt::get_self(_settings) }; + if (settingsImpl->ApplyColorScheme(controlSettings, realArgs.SchemeName())) { activeControl.UpdateSettings(controlSettings); args.Handled(true); diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 6e3490fba9be..ded323ba4e58 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -165,6 +165,17 @@ namespace winrt::TerminalApp::implementation return nullptr; } + // Method Description: + // - Returns the settings currently in use by the entire Terminal application. + // Throws: + // - HR E_INVALIDARG if the app isn't up and running. + const TerminalApp::CascadiaSettings AppLogic::CurrentAppSettings() + { + auto appLogic{ ::winrt::TerminalApp::implementation::AppLogic::Current() }; + THROW_HR_IF_NULL(E_INVALIDARG, appLogic); + return appLogic->GetSettings(); + } + AppLogic::AppLogic() : _dialogLock{}, _loadedInitialSettings{ false }, @@ -238,7 +249,7 @@ namespace winrt::TerminalApp::implementation // so this setting is overridden to false no matter what the preference is. if (_isUwp) { - _settings->GlobalSettings().ShowTabsInTitlebar(false); + _settings.GlobalSettings().ShowTabsInTitlebar(false); } _root->SetSettings(_settings, false); @@ -256,14 +267,14 @@ namespace winrt::TerminalApp::implementation }); _root->Create(); - _ApplyTheme(_settings->GlobalSettings().Theme()); + _ApplyTheme(_settings.GlobalSettings().Theme()); _ApplyStartupTaskStateChange(); TraceLoggingWrite( g_hTerminalAppProvider, "AppCreated", TraceLoggingDescription("Event emitted when the application is started"), - TraceLoggingBool(_settings->GlobalSettings().ShowTabsInTitlebar(), "TabsInTitlebar"), + TraceLoggingBool(_settings.GlobalSettings().ShowTabsInTitlebar(), "TabsInTitlebar"), TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance)); } @@ -310,7 +321,7 @@ namespace winrt::TerminalApp::implementation // details here, but it does have the desired effect. // It's not enough to set the theme on the dialog alone. auto themingLambda{ [this](const Windows::Foundation::IInspectable& sender, const RoutedEventArgs&) { - auto theme{ _settings->GlobalSettings().Theme() }; + auto theme{ _settings.GlobalSettings().Theme() }; auto element{ sender.try_as() }; while (element) { @@ -400,7 +411,8 @@ namespace winrt::TerminalApp::implementation // Make sure the lines of text wrap warningsTextBlock.TextWrapping(TextWrapping::Wrap); - const auto& warnings = _settings->GetWarnings(); + const auto settingsImpl{ winrt::get_self(_settings) }; + const auto& warnings = settingsImpl->GetWarnings(); for (const auto& warning : warnings) { // Try looking up the warning message key for each warning. @@ -483,7 +495,8 @@ namespace winrt::TerminalApp::implementation } // Use the default profile to determine how big of a window we need. - const auto [_, settings] = _settings->BuildSettings(nullptr); + const auto settingsImpl{ winrt::get_self(_settings) }; + const auto [_, settings] = settingsImpl->BuildSettings(nullptr); auto proposedSize = TermControl::GetProposedDimensions(settings, dpi); @@ -492,7 +505,7 @@ namespace winrt::TerminalApp::implementation // GH#2061 - If the global setting "Always show tab bar" is // set or if "Show tabs in title bar" is set, then we'll need to add // the height of the tab bar here. - if (_settings->GlobalSettings().ShowTabsInTitlebar()) + if (_settings.GlobalSettings().ShowTabsInTitlebar()) { // If we're showing the tabs in the titlebar, we need to use a // TitlebarControl here to calculate how much space to reserve. @@ -506,7 +519,7 @@ namespace winrt::TerminalApp::implementation titlebar.Measure({ SHRT_MAX, SHRT_MAX }); proposedSize.Height += (titlebar.DesiredSize().Height) * scale; } - else if (_settings->GlobalSettings().AlwaysShowTabs()) + else if (_settings.GlobalSettings().AlwaysShowTabs()) { // Otherwise, let's use a TabRowControl to calculate how much extra // space we'll need. @@ -544,7 +557,7 @@ namespace winrt::TerminalApp::implementation // GH#4620/#5801 - If the user passed --maximized or --fullscreen on the // commandline, then use that to override the value from the settings. - const auto valueFromSettings = _settings->GlobalSettings().LaunchMode(); + const auto valueFromSettings = _settings.GlobalSettings().LaunchMode(); const auto valueFromCommandlineArgs = _appArgs.GetLaunchMode(); return valueFromCommandlineArgs.has_value() ? valueFromCommandlineArgs.value() : @@ -569,7 +582,7 @@ namespace winrt::TerminalApp::implementation LoadSettings(); } - const auto initialPosition{ _settings->GlobalSettings().InitialPosition() }; + const auto initialPosition{ _settings.GlobalSettings().InitialPosition() }; return { initialPosition.X ? initialPosition.X.Value() : defaultInitialX, initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY @@ -584,7 +597,7 @@ namespace winrt::TerminalApp::implementation LoadSettings(); } - return _settings->GlobalSettings().Theme(); + return _settings.GlobalSettings().Theme(); } bool AppLogic::GetShowTabsInTitlebar() @@ -595,7 +608,7 @@ namespace winrt::TerminalApp::implementation LoadSettings(); } - return _settings->GlobalSettings().ShowTabsInTitlebar(); + return _settings.GlobalSettings().ShowTabsInTitlebar(); } // Method Description: @@ -616,9 +629,9 @@ namespace winrt::TerminalApp::implementation try { auto newSettings = _isUwp ? CascadiaSettings::LoadUniversal() : CascadiaSettings::LoadAll(); - _settings.copy_from(winrt::get_self(newSettings)); + _settings = newSettings; - auto settingsImpl = _settings.as(); + const auto settingsImpl{ winrt::get_self(_settings) }; const auto& warnings = settingsImpl->GetWarnings(); hr = warnings.size() == 0 ? S_OK : S_FALSE; } @@ -677,7 +690,7 @@ namespace winrt::TerminalApp::implementation if (FAILED(_settingsLoadedResult)) { - _settings.copy_from(winrt::get_self(CascadiaSettings::LoadDefaults())); + _settings = CascadiaSettings::LoadDefaults(); } auto end = std::chrono::high_resolution_clock::now(); @@ -773,7 +786,7 @@ namespace winrt::TerminalApp::implementation co_await winrt::resume_foreground(_root->Dispatcher()); // Refresh the UI theme - _ApplyTheme(_settings->GlobalSettings().Theme()); + _ApplyTheme(_settings.GlobalSettings().Theme()); } fire_and_forget AppLogic::_ApplyStartupTaskStateChange() @@ -792,7 +805,7 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { StartupTaskState state; - bool tryEnableStartupTask = _settings->GlobalSettings().StartOnUserLogin(); + bool tryEnableStartupTask = _settings.GlobalSettings().StartOnUserLogin(); StartupTask task = co_await StartupTask::GetAsync(StartupTaskName); state = task.State(); @@ -859,7 +872,7 @@ namespace winrt::TerminalApp::implementation // - Returns a pointer to the global shared settings. [[nodiscard]] TerminalApp::CascadiaSettings AppLogic::GetSettings() const noexcept { - return *_settings; + return _settings; } // Method Description: diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 620da276bf39..351247d22941 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -16,6 +16,7 @@ namespace winrt::TerminalApp::implementation { public: static AppLogic* Current() noexcept; + static const TerminalApp::CascadiaSettings CurrentAppSettings(); AppLogic(); ~AppLogic() = default; @@ -68,7 +69,7 @@ namespace winrt::TerminalApp::implementation // updated in _ApplyTheme. The root currently is _root. winrt::com_ptr _root{ nullptr }; - winrt::com_ptr _settings{ nullptr }; + TerminalApp::CascadiaSettings _settings{ nullptr }; HRESULT _settingsLoadedResult; winrt::hstring _settingsLoadExceptionText{}; diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index 8205cd2dd963..28912e7858a1 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -364,8 +364,7 @@ void CascadiaSettings::_ReorderProfilesToMatchUserSettingsOrder() // - void CascadiaSettings::_RemoveHiddenProfiles() { - uint32_t i = 0; - while (i < _profiles.Size()) + for (uint32_t i{}; i < _profiles.Size();) { if (_profiles.GetAt(i).Hidden()) { @@ -701,7 +700,7 @@ std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::strin std::string finalSettings{ settingsTemplate }; std::wstring defaultProfileGuid{ DEFAULT_WINDOWS_POWERSHELL_GUID }; - if (const auto psCoreProfileGuid{ _GetProfileGuidByName(PowershellCoreProfileGenerator::GetPreferredPowershellProfileName().data()) }) + if (const auto psCoreProfileGuid{ _GetProfileGuidByName(hstring{ PowershellCoreProfileGenerator::GetPreferredPowershellProfileName() }) }) { defaultProfileGuid = Utils::GuidToString(*psCoreProfileGuid); } diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index 54d4ef8f6b2f..d02704e30c68 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.h +++ b/src/cascadia/TerminalApp/CascadiaSettings.h @@ -60,7 +60,7 @@ namespace winrt::TerminalApp::implementation { public: CascadiaSettings(); - CascadiaSettings(const bool addDynamicProfiles); + explicit CascadiaSettings(const bool addDynamicProfiles); static TerminalApp::CascadiaSettings LoadDefaults(); static TerminalApp::CascadiaSettings LoadAll(); diff --git a/src/cascadia/TerminalApp/CascadiaSettings.idl b/src/cascadia/TerminalApp/CascadiaSettings.idl index 2d9010c53bc4..58695b9dc31a 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.idl +++ b/src/cascadia/TerminalApp/CascadiaSettings.idl @@ -1,22 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import "TerminalSettings.idl"; import "GlobalAppSettings.idl"; import "Profile.idl"; namespace TerminalApp { [default_interface] runtimeclass CascadiaSettings { - CascadiaSettings(); - CascadiaSettings(Boolean addDynamicProfiles); - static CascadiaSettings LoadDefaults(); static CascadiaSettings LoadAll(); static CascadiaSettings LoadUniversal(); - TerminalSettings BuildSettings(Guid profileGuid); - GlobalAppSettings GlobalSettings { get; }; Windows.Foundation.Collections.IObservableVector Profiles { get; }; @@ -25,8 +19,5 @@ namespace TerminalApp Profile FindProfile(Guid profileGuid); ColorScheme GetColorSchemeForProfile(Guid profileGuid); - - Boolean ApplyColorScheme(Microsoft.Terminal.TerminalControl.IControlSettings settings, String schemeName); - } } diff --git a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp index 60128f022430..e34d10e25e8c 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -264,7 +264,7 @@ winrt::TerminalApp::CascadiaSettings CascadiaSettings::LoadUniversal() // If this throws, the app will catch it and use the default settings resultPtr->_ValidateSettings(); - return resultPtr.as(); + return *resultPtr; } // Function Description: @@ -620,7 +620,7 @@ void CascadiaSettings::_LayerOrCreateProfile(const Json::Value& profileJson) } profile->LayerJson(profileJson); - _profiles.Append(profile.as()); + _profiles.Append(*profile); } } } diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 95c27e4336cf..c58de58b59d2 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -319,9 +319,7 @@ void Pane::_ControlConnectionStateChangedHandler(const TermControl& /*sender*/, return; } - const auto appLogic{ winrt::TerminalApp::implementation::AppLogic::Current() }; - THROW_HR_IF_NULL(E_INVALIDARG, appLogic); - auto settings = appLogic->GetSettings(); + const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() }; auto paneProfile = settings.FindProfile(_profile.value()); if (paneProfile) { diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 9932872a682a..5cb886406d73 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -101,8 +101,7 @@ namespace winrt::TerminalApp::implementation } } - winrt::fire_and_forget TerminalPage::SetSettings(winrt::com_ptr settings, - bool needRefreshUI) + winrt::fire_and_forget TerminalPage::SetSettings(TerminalApp::CascadiaSettings settings, bool needRefreshUI) { _settings = settings; if (needRefreshUI) @@ -115,14 +114,14 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { _UpdateCommandsForPalette(); - CommandPalette().SetKeyBindings(_settings->Keybindings()); + CommandPalette().SetKeyBindings(_settings.Keybindings()); } } void TerminalPage::Create() { // Hookup the key bindings - _HookupKeyBindings(_settings->Keybindings()); + _HookupKeyBindings(_settings.Keybindings()); _tabContent = this->TabContent(); _tabRow = this->TabRow(); @@ -178,7 +177,7 @@ namespace winrt::TerminalApp::implementation auto tabRowImpl = winrt::get_self(_tabRow); _newTabButton = tabRowImpl->NewTabButton(); - if (_settings->GlobalSettings().ShowTabsInTitlebar()) + if (_settings.GlobalSettings().ShowTabsInTitlebar()) { // Remove the TabView from the page. We'll hang on to it, we need to // put it in the titlebar. @@ -207,7 +206,7 @@ namespace winrt::TerminalApp::implementation WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); // Check for DebugTap - bool debugTap = page->_settings->GlobalSettings().DebugFeaturesEnabled() && + bool debugTap = page->_settings.GlobalSettings().DebugFeaturesEnabled() && WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); @@ -449,14 +448,14 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_CreateNewTabFlyout() { auto newTabFlyout = WUX::Controls::MenuFlyout{}; - auto keyBindings = _settings->Keybindings(); + auto keyBindings = _settings.Keybindings(); - const winrt::guid defaultProfileGuid = _settings->GlobalSettings().DefaultProfile(); + const auto defaultProfileGuid = _settings.GlobalSettings().DefaultProfile(); // the number of profiles should not change in the loop for this to work - auto const profileCount = gsl::narrow_cast(_settings->Profiles().Size()); + auto const profileCount = gsl::narrow_cast(_settings.Profiles().Size()); for (int profileIndex = 0; profileIndex < profileCount; profileIndex++) { - const auto& profile = _settings->Profiles().GetAt(profileIndex); + const auto profile = _settings.Profiles().GetAt(profileIndex); auto profileMenuItem = WUX::Controls::MenuFlyoutItem{}; // Add the keyboard shortcuts based on the number of profiles defined @@ -512,7 +511,7 @@ namespace winrt::TerminalApp::implementation WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); // Check for DebugTap - bool debugTap = page->_settings->GlobalSettings().DebugFeaturesEnabled() && + bool debugTap = page->_settings.GlobalSettings().DebugFeaturesEnabled() && WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) && WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down); @@ -617,7 +616,8 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_OpenNewTab(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) try { - const auto [profileGuid, settings] = _settings.as()->BuildSettings(newTerminalArgs); + const auto settingsImpl{ winrt::get_self(_settings) }; + const auto [profileGuid, settings] = settingsImpl->BuildSettings(newTerminalArgs); _CreateNewTabFromSettings(profileGuid, settings); @@ -627,7 +627,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(profileGuid); // 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"; @@ -669,7 +669,7 @@ namespace winrt::TerminalApp::implementation auto connection = _CreateConnectionFromSettings(profileGuid, settings); TerminalConnection::ITerminalConnection debugConnection{ nullptr }; - if (_settings->GlobalSettings().DebugFeaturesEnabled()) + if (_settings.GlobalSettings().DebugFeaturesEnabled()) { const CoreWindow window = CoreWindow::GetForCurrentThread(); const auto rAltState = window.GetKeyState(VirtualKey::RightMenu); @@ -725,7 +725,7 @@ namespace winrt::TerminalApp::implementation } // Set this tab's icon to the icon from the user's profile - const auto profile = _settings->FindProfile(profileGuid); + const auto profile = _settings.FindProfile(profileGuid); if (profile != nullptr && !profile.IconPath().empty()) { newTabImpl->UpdateIcon(profile.GetExpandedIconPath()); @@ -764,7 +764,7 @@ namespace winrt::TerminalApp::implementation TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(GUID profileGuid, TerminalApp::TerminalSettings settings) { - const auto profile = _settings->FindProfile(profileGuid); + const auto profile = _settings.FindProfile(profileGuid); TerminalConnection::ITerminalConnection connection{ nullptr }; @@ -948,7 +948,7 @@ namespace winrt::TerminalApp::implementation { auto newTabTitle = tab.GetActiveTitle(); - if (_settings->GlobalSettings().ShowTitleInTitlebar() && + if (_settings.GlobalSettings().ShowTitleInTitlebar() && tab.IsFocused()) { _titleChangeHandlers(*this, newTabTitle); @@ -966,7 +966,7 @@ namespace winrt::TerminalApp::implementation if (lastFocusedProfileOpt.has_value()) { const auto lastFocusedProfile = lastFocusedProfileOpt.value(); - const auto matchingProfile = _settings->FindProfile(lastFocusedProfile); + const auto matchingProfile = _settings.FindProfile(lastFocusedProfile); if (matchingProfile) { tab.UpdateIcon(matchingProfile.GetExpandedIconPath()); @@ -982,7 +982,7 @@ namespace winrt::TerminalApp::implementation // - Handle changes to the tab width set by the user void TerminalPage::_UpdateTabWidthMode() { - _tabView.TabWidthMode(_settings->GlobalSettings().TabWidthMode()); + _tabView.TabWidthMode(_settings.GlobalSettings().TabWidthMode()); } // Method Description: @@ -993,9 +993,9 @@ namespace winrt::TerminalApp::implementation // Show tabs when there's more than 1, or the user has chosen to always // show the tab bar. const bool isVisible = (!_isFullscreen && !_isInFocusMode) && - (_settings->GlobalSettings().ShowTabsInTitlebar() || + (_settings.GlobalSettings().ShowTabsInTitlebar() || (_tabs.Size() > 1) || - _settings->GlobalSettings().AlwaysShowTabs()); + _settings.GlobalSettings().AlwaysShowTabs()); // collapse/show the tabs themselves _tabView.Visibility(isVisible ? Visibility::Visible : Visibility::Collapsed); @@ -1030,7 +1030,8 @@ namespace winrt::TerminalApp::implementation const auto& profileGuid = focusedTab->GetFocusedProfile(); if (profileGuid.has_value()) { - const auto settings = _settings->BuildSettings(profileGuid.value()); + const auto settingsImpl{ winrt::get_self(_settings) }; + const auto settings = settingsImpl->BuildSettings(profileGuid.value()); _CreateNewTabFromSettings(profileGuid.value(), settings); } } @@ -1197,7 +1198,7 @@ namespace winrt::TerminalApp::implementation // leftward from 0 to tabCount - 1. const auto newTabIndex = ((tabCount + *index + (bMoveRight ? 1 : -1)) % tabCount); - if (_settings->GlobalSettings().UseTabSwitcher()) + if (_settings.GlobalSettings().UseTabSwitcher()) { if (CommandPalette().Visibility() == Visibility::Visible) { @@ -1385,7 +1386,7 @@ namespace winrt::TerminalApp::implementation // than one tab opened, show a warning dialog. void TerminalPage::CloseWindow() { - if (_tabs.Size() > 1 && _settings->GlobalSettings().ConfirmCloseAllTabs()) + if (_tabs.Size() > 1 && _settings.GlobalSettings().ConfirmCloseAllTabs()) { _ShowCloseWarningDialog(); } @@ -1463,7 +1464,8 @@ namespace winrt::TerminalApp::implementation if (current_guid) { profileFound = true; - controlSettings = _settings->BuildSettings(current_guid.value()); + const auto settingsImpl{ winrt::get_self(_settings) }; + controlSettings = settingsImpl->BuildSettings(current_guid.value()); realGuid = current_guid.value(); } // TODO: GH#5047 - In the future, we should get the Profile of @@ -1481,7 +1483,8 @@ namespace winrt::TerminalApp::implementation } if (!profileFound) { - std::tie(realGuid, controlSettings) = _settings.as()->BuildSettings(newTerminalArgs); + const auto settingsImpl{ winrt::get_self(_settings) }; + std::tie(realGuid, controlSettings) = settingsImpl->BuildSettings(newTerminalArgs); } const auto controlConnection = _CreateConnectionFromSettings(realGuid, controlSettings); @@ -1565,7 +1568,7 @@ namespace winrt::TerminalApp::implementation // - the title of the focused control if there is one, else "Windows Terminal" hstring TerminalPage::Title() { - if (_settings->GlobalSettings().ShowTitleInTitlebar()) + if (_settings.GlobalSettings().ShowTitleInTitlebar()) { auto selectedIndex = _tabView.SelectedIndex(); if (selectedIndex >= 0) @@ -1660,7 +1663,7 @@ namespace winrt::TerminalApp::implementation // - See Pane::CalcSnappedDimension float TerminalPage::CalcSnappedDimension(const bool widthOrHeight, const float dimension) const { - if (_settings->GlobalSettings().SnapToGridOnResize()) + if (_settings.GlobalSettings().SnapToGridOnResize()) { if (auto index{ _GetFocusedTabIndex() }) { @@ -1688,7 +1691,7 @@ namespace winrt::TerminalApp::implementation // iff it is set bool useGlobal = copiedData.Formats() == nullptr; auto copyFormats = useGlobal ? - _settings->GlobalSettings().CopyFormatting() : + _settings.GlobalSettings().CopyFormatting() : copiedData.Formats().Value(); // copy text to dataPack @@ -1762,11 +1765,11 @@ namespace winrt::TerminalApp::implementation } const bool hasNewLine = std::find(text.cbegin(), text.cend(), L'\n') != text.cend(); - const bool warnMultiLine = hasNewLine && _settings->GlobalSettings().WarnAboutMultiLinePaste(); + const bool warnMultiLine = hasNewLine && _settings.GlobalSettings().WarnAboutMultiLinePaste(); constexpr const std::size_t minimumSizeForWarning = 1024 * 5; // 5 KiB const bool warnLargeText = text.size() > minimumSizeForWarning && - _settings->GlobalSettings().WarnAboutLargePaste(); + _settings.GlobalSettings().WarnAboutLargePaste(); if (warnMultiLine || warnLargeText) { @@ -1998,11 +2001,11 @@ namespace winrt::TerminalApp::implementation { // Re-wire the keybindings to their handlers, as we'll have created a // new AppKeyBindings object. - _HookupKeyBindings(_settings->Keybindings()); + _HookupKeyBindings(_settings.Keybindings()); // Refresh UI elements - auto profiles = _settings->Profiles(); - for (auto profile : profiles) + auto profiles = _settings.Profiles(); + for (const auto& profile : profiles) { const auto profileGuid = profile.Guid(); @@ -2010,7 +2013,8 @@ namespace winrt::TerminalApp::implementation { // BuildSettings can throw an exception if the profileGuid does // not belong to an actual profile in the list of profiles. - const auto settings = _settings->BuildSettings(profileGuid); + const auto settingsImpl{ winrt::get_self(_settings) }; + const auto settings = settingsImpl->BuildSettings(profileGuid); for (auto tab : _tabs) { @@ -2050,7 +2054,7 @@ namespace winrt::TerminalApp::implementation // Reload the current value of alwaysOnTop from the settings file. This // will let the user hot-reload this setting, but any runtime changes to // the alwaysOnTop setting will be lost. - _isAlwaysOnTop = _settings->GlobalSettings().AlwaysOnTop(); + _isAlwaysOnTop = _settings.GlobalSettings().AlwaysOnTop(); _alwaysOnTopChangedHandlers(*this, nullptr); } @@ -2108,11 +2112,11 @@ namespace winrt::TerminalApp::implementation // - void TerminalPage::_UpdateCommandsForPalette() { - IMap copyOfCommands = _ExpandCommands(_settings->GlobalSettings().GetCommands(), - _settings->Profiles().GetView(), - _settings->GlobalSettings().GetColorSchemes()); + IMap copyOfCommands = _ExpandCommands(_settings.GlobalSettings().GetCommands(), + _settings.Profiles().GetView(), + _settings.GlobalSettings().GetColorSchemes()); - _recursiveUpdateCommandKeybindingLabels(_settings.as(), copyOfCommands.GetView()); + _recursiveUpdateCommandKeybindingLabels(_settings, copyOfCommands.GetView()); _recursiveUpdateCommandIcons(copyOfCommands.GetView()); // Update the command palette when settings reload diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 04c20e702183..730568321bdf 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -33,7 +33,7 @@ namespace winrt::TerminalApp::implementation public: TerminalPage(); - winrt::fire_and_forget SetSettings(com_ptr settings, bool needRefreshUI); + winrt::fire_and_forget SetSettings(TerminalApp::CascadiaSettings settings, bool needRefreshUI); void Create(); @@ -86,7 +86,7 @@ namespace winrt::TerminalApp::implementation Windows::UI::Xaml::Controls::Grid _tabContent{ nullptr }; Microsoft::UI::Xaml::Controls::SplitButton _newTabButton{ nullptr }; - com_ptr _settings{ nullptr }; + TerminalApp::CascadiaSettings _settings{ nullptr }; Windows::Foundation::Collections::IObservableVector _tabs; winrt::com_ptr _GetStrongTabImpl(const uint32_t index) const;