Add firstWindowPreference value for layout only (#19341)

## Summary of the Pull Request
Updates the "firstWindowPreference" global setting to take 3 values:
"defaultProfile", "persistedLayout", and "persistedLayoutAndContent".

The legacy "persistedWindowLayout" is being interpreted as
"persistedLayoutAndContent".

The tricky part here is that we need to maintain support for the legacy
value as persisting the layout and content, even though the value's name
suggests that it should just support the layout and no content. To get
around this, I added "persistedLayout" and "persistedLayoutAndContent".

The enum map is manually constructed for `FirstWindowPreference` to
exclude the deprecated value. This prevents the legacy value from
leaking into the settings UI.

Functionally, the change to serialize the contents is simple.
`WindowEmperor::_persistState()`'s second parameter is used to serialize
the buffer. Rather than having it set to `true`, we set it to
`GlobalSettings().FirstWindowPreference() ==
FirstWindowPreference::PersistedLayoutAndContent`.

## Validation Steps Performed
 "persistedWindowLayout" is changed to "persistedLayoutAndContent"

 Closes #18757
This commit is contained in:
Carlos Zamora 2025-10-27 13:55:54 -07:00 committed by GitHub
parent 5ae95d7df0
commit 16f7ab4185
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 6 deletions

View File

@ -452,6 +452,14 @@
<value>Open windows from a previous session</value>
<comment>An option to choose from for the "First window preference" setting. Reopen the layouts from the last session.</comment>
</data>
<data name="Globals_FirstWindowPreferencePersistedLayoutAndContent.Content" xml:space="preserve">
<value>Open windows from a previous session (layout and content)</value>
<comment>An option to choose from for the "First window preference" setting. Reopen the layouts from the last session and preserve the content.</comment>
</data>
<data name="Globals_FirstWindowPreferencePersistedLayout.Content" xml:space="preserve">
<value>Open windows from a previous session (layout only)</value>
<comment>An option to choose from for the "First window preference" setting. Reopen the layouts from the last session, but don't preserve the content.</comment>
</data>
<data name="Globals_LaunchMode.Header" xml:space="preserve">
<value>Launch mode</value>
<comment>Header for a control to select what mode to launch the terminal in.</comment>

View File

@ -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<winrt::hstring, Model::FirstWindowPreference> EnumMappings::FirstWindowPreference()
{
static auto enumMap = []() {
auto map = single_threaded_map<winrt::hstring, Model::FirstWindowPreference>();
for (auto [enumStr, enumVal] : JsonUtils::ConversionTrait<Model::FirstWindowPreference>::mappings)
{
// exclude legacy value from enum map
if (enumStr != "persistedWindowLayout")
{
map.Insert(winrt::to_hstring(enumStr), enumVal);
}
}
return map;
}();
return enumMap;
}
}

View File

@ -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 |= firstWindowPreferenceValue == LegacyPersistedWindowLayout.data();
}
// Remove settings included in userDefaults
static constexpr std::array<std::pair<std::string_view, std::string_view>, 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)

View File

@ -40,7 +40,8 @@ namespace Microsoft.Terminal.Settings.Model
enum FirstWindowPreference
{
DefaultProfile,
PersistedWindowLayout,
PersistedLayout,
PersistedLayoutAndContent,
};
enum NewTabPosition

View File

@ -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 },
};
};

View File

@ -1075,7 +1075,7 @@ void WindowEmperor::_finalizeSessionPersistence() const
const auto state = ApplicationState::SharedInstance();
_persistState(state, true);
_persistState(state, _app.Logic().Settings().GlobalSettings().FirstWindowPreference() == FirstWindowPreference::PersistedLayoutAndContent);
if (_needsPersistenceCleanup)
{