diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 7b3ebe85a64..800dd084ed7 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -452,6 +452,14 @@ Open windows from a previous session An option to choose from for the "First window preference" setting. Reopen the layouts from the last session. + + Open windows from a previous session (layout and content) + An option to choose from for the "First window preference" setting. Reopen the layouts from the last session and preserve the content. + + + Open windows from a previous session (layout only) + An option to choose from for the "First window preference" setting. Reopen the layouts from the last session, but don't preserve the content. + Launch mode Header for a control to select what mode to launch the terminal in. diff --git a/src/cascadia/TerminalSettingsModel/EnumMappings.cpp b/src/cascadia/TerminalSettingsModel/EnumMappings.cpp index e6e5d25e74b..2e14d443b86 100644 --- a/src/cascadia/TerminalSettingsModel/EnumMappings.cpp +++ b/src/cascadia/TerminalSettingsModel/EnumMappings.cpp @@ -34,7 +34,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation DEFINE_ENUM_MAP(Model::NewTabPosition, NewTabPosition); DEFINE_ENUM_MAP(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabViewWidthMode); DEFINE_ENUM_MAP(Microsoft::Terminal::Control::DefaultInputScope, DefaultInputScope); - DEFINE_ENUM_MAP(Model::FirstWindowPreference, FirstWindowPreference); DEFINE_ENUM_MAP(Model::LaunchMode, LaunchMode); DEFINE_ENUM_MAP(Model::TabSwitcherMode, TabSwitcherMode); DEFINE_ENUM_MAP(Microsoft::Terminal::Control::CopyFormat, CopyFormat); @@ -84,4 +83,21 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation }(); return enumMap; } + + winrt::Windows::Foundation::Collections::IMap EnumMappings::FirstWindowPreference() + { + static auto enumMap = []() { + auto map = single_threaded_map(); + for (auto [enumStr, enumVal] : JsonUtils::ConversionTrait::mappings) + { + // exclude legacy value from enum map + if (enumStr != "persistedWindowLayout") + { + map.Insert(winrt::to_hstring(enumStr), enumVal); + } + } + return map; + }(); + return enumMap; + } } diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp index afb2a3f187e..e851b00c48c 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp @@ -23,6 +23,7 @@ static constexpr std::string_view KeybindingsKey{ "keybindings" }; static constexpr std::string_view ActionsKey{ "actions" }; static constexpr std::string_view ThemeKey{ "theme" }; static constexpr std::string_view DefaultProfileKey{ "defaultProfile" }; +static constexpr std::string_view FirstWindowPreferenceKey{ "firstWindowPreference" }; static constexpr std::string_view LegacyUseTabSwitcherModeKey{ "useTabSwitcher" }; static constexpr std::string_view LegacyReloadEnvironmentVariablesKey{ "compatibility.reloadEnvironmentVariables" }; static constexpr std::string_view LegacyForceVTInputKey{ "experimental.input.forceVT" }; @@ -30,6 +31,7 @@ static constexpr std::string_view LegacyInputServiceWarningKey{ "inputServiceWar static constexpr std::string_view LegacyWarnAboutLargePasteKey{ "largePasteWarning" }; static constexpr std::string_view LegacyWarnAboutMultiLinePasteKey{ "multiLinePasteWarning" }; static constexpr std::string_view LegacyConfirmCloseAllTabsKey{ "confirmCloseAllTabs" }; +static constexpr std::string_view LegacyPersistedWindowLayout{ "persistedWindowLayout" }; // Method Description: // - Copies any extraneous data from the parent before completing a CreateChild call @@ -196,6 +198,13 @@ void GlobalAppSettings::LayerJson(const Json::Value& json, const OriginTag origi _logSettingSet(LegacyForceVTInputKey); } + // GLOBAL_SETTINGS_LAYER_JSON above should have already loaded this value properly. + // We just need to detect if the legacy value was used and mark it for fixup, if so. + if (const auto firstWindowPreferenceValue = json[FirstWindowPreferenceKey.data()]) + { + _fixupsAppliedDuringLoad = _fixupsAppliedDuringLoad || firstWindowPreferenceValue == LegacyPersistedWindowLayout.data(); + } + // Remove settings included in userDefaults static constexpr std::array, 2> userDefaultSettings{ { { "copyOnSelect", "false" }, { "copyFormatting", "false" } } }; @@ -377,7 +386,7 @@ void GlobalAppSettings::ExpandCommands(const winrt::Windows::Foundation::Collect bool GlobalAppSettings::ShouldUsePersistedLayout() const { - return FirstWindowPreference() == FirstWindowPreference::PersistedWindowLayout; + return FirstWindowPreference() != FirstWindowPreference::DefaultProfile; } void GlobalAppSettings::ResolveMediaResources(const Model::MediaResourceResolver& resolver) diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index e003660f329..0ac7b96db8e 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -40,7 +40,8 @@ namespace Microsoft.Terminal.Settings.Model enum FirstWindowPreference { DefaultProfile, - PersistedWindowLayout, + PersistedLayout, + PersistedLayoutAndContent, }; enum NewTabPosition diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index b2355ce4c73..92a98282085 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -260,9 +260,13 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::NewTabPosition) JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FirstWindowPreference) { - JSON_MAPPINGS(2) = { + JSON_MAPPINGS(4) = { pair_type{ "defaultProfile", ValueType::DefaultProfile }, - pair_type{ "persistedWindowLayout", ValueType::PersistedWindowLayout }, + pair_type{ "persistedLayoutAndContent", ValueType::PersistedLayoutAndContent }, + pair_type{ "persistedLayout", ValueType::PersistedLayout }, + + // Keep deprecated keys last, so when they get serialized again they aren't written out + pair_type{ "persistedWindowLayout", ValueType::PersistedLayoutAndContent }, }; }; diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 5b6c9fd833f..8ab00bb6e57 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -1053,7 +1053,7 @@ void WindowEmperor::_finalizeSessionPersistence() const const auto state = ApplicationState::SharedInstance(); - _persistState(state, true); + _persistState(state, _app.Logic().Settings().GlobalSettings().FirstWindowPreference() == FirstWindowPreference::PersistedLayoutAndContent); if (_needsPersistenceCleanup) {