Skip to content

Commit 16f7ab4

Browse files
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
1 parent 5ae95d7 commit 16f7ab4

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@
452452
<value>Open windows from a previous session</value>
453453
<comment>An option to choose from for the "First window preference" setting. Reopen the layouts from the last session.</comment>
454454
</data>
455+
<data name="Globals_FirstWindowPreferencePersistedLayoutAndContent.Content" xml:space="preserve">
456+
<value>Open windows from a previous session (layout and content)</value>
457+
<comment>An option to choose from for the "First window preference" setting. Reopen the layouts from the last session and preserve the content.</comment>
458+
</data>
459+
<data name="Globals_FirstWindowPreferencePersistedLayout.Content" xml:space="preserve">
460+
<value>Open windows from a previous session (layout only)</value>
461+
<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>
462+
</data>
455463
<data name="Globals_LaunchMode.Header" xml:space="preserve">
456464
<value>Launch mode</value>
457465
<comment>Header for a control to select what mode to launch the terminal in.</comment>

src/cascadia/TerminalSettingsModel/EnumMappings.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
3434
DEFINE_ENUM_MAP(Model::NewTabPosition, NewTabPosition);
3535
DEFINE_ENUM_MAP(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabViewWidthMode);
3636
DEFINE_ENUM_MAP(Microsoft::Terminal::Control::DefaultInputScope, DefaultInputScope);
37-
DEFINE_ENUM_MAP(Model::FirstWindowPreference, FirstWindowPreference);
3837
DEFINE_ENUM_MAP(Model::LaunchMode, LaunchMode);
3938
DEFINE_ENUM_MAP(Model::TabSwitcherMode, TabSwitcherMode);
4039
DEFINE_ENUM_MAP(Microsoft::Terminal::Control::CopyFormat, CopyFormat);
@@ -84,4 +83,21 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
8483
}();
8584
return enumMap;
8685
}
86+
87+
winrt::Windows::Foundation::Collections::IMap<winrt::hstring, Model::FirstWindowPreference> EnumMappings::FirstWindowPreference()
88+
{
89+
static auto enumMap = []() {
90+
auto map = single_threaded_map<winrt::hstring, Model::FirstWindowPreference>();
91+
for (auto [enumStr, enumVal] : JsonUtils::ConversionTrait<Model::FirstWindowPreference>::mappings)
92+
{
93+
// exclude legacy value from enum map
94+
if (enumStr != "persistedWindowLayout")
95+
{
96+
map.Insert(winrt::to_hstring(enumStr), enumVal);
97+
}
98+
}
99+
return map;
100+
}();
101+
return enumMap;
102+
}
87103
}

src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ static constexpr std::string_view KeybindingsKey{ "keybindings" };
2323
static constexpr std::string_view ActionsKey{ "actions" };
2424
static constexpr std::string_view ThemeKey{ "theme" };
2525
static constexpr std::string_view DefaultProfileKey{ "defaultProfile" };
26+
static constexpr std::string_view FirstWindowPreferenceKey{ "firstWindowPreference" };
2627
static constexpr std::string_view LegacyUseTabSwitcherModeKey{ "useTabSwitcher" };
2728
static constexpr std::string_view LegacyReloadEnvironmentVariablesKey{ "compatibility.reloadEnvironmentVariables" };
2829
static constexpr std::string_view LegacyForceVTInputKey{ "experimental.input.forceVT" };
2930
static constexpr std::string_view LegacyInputServiceWarningKey{ "inputServiceWarning" };
3031
static constexpr std::string_view LegacyWarnAboutLargePasteKey{ "largePasteWarning" };
3132
static constexpr std::string_view LegacyWarnAboutMultiLinePasteKey{ "multiLinePasteWarning" };
3233
static constexpr std::string_view LegacyConfirmCloseAllTabsKey{ "confirmCloseAllTabs" };
34+
static constexpr std::string_view LegacyPersistedWindowLayout{ "persistedWindowLayout" };
3335

3436
// Method Description:
3537
// - 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
196198
_logSettingSet(LegacyForceVTInputKey);
197199
}
198200

201+
// GLOBAL_SETTINGS_LAYER_JSON above should have already loaded this value properly.
202+
// We just need to detect if the legacy value was used and mark it for fixup, if so.
203+
if (const auto firstWindowPreferenceValue = json[FirstWindowPreferenceKey.data()])
204+
{
205+
_fixupsAppliedDuringLoad |= firstWindowPreferenceValue == LegacyPersistedWindowLayout.data();
206+
}
207+
199208
// Remove settings included in userDefaults
200209
static constexpr std::array<std::pair<std::string_view, std::string_view>, 2> userDefaultSettings{ { { "copyOnSelect", "false" },
201210
{ "copyFormatting", "false" } } };
@@ -377,7 +386,7 @@ void GlobalAppSettings::ExpandCommands(const winrt::Windows::Foundation::Collect
377386

378387
bool GlobalAppSettings::ShouldUsePersistedLayout() const
379388
{
380-
return FirstWindowPreference() == FirstWindowPreference::PersistedWindowLayout;
389+
return FirstWindowPreference() != FirstWindowPreference::DefaultProfile;
381390
}
382391

383392
void GlobalAppSettings::ResolveMediaResources(const Model::MediaResourceResolver& resolver)

src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ namespace Microsoft.Terminal.Settings.Model
4040
enum FirstWindowPreference
4141
{
4242
DefaultProfile,
43-
PersistedWindowLayout,
43+
PersistedLayout,
44+
PersistedLayoutAndContent,
4445
};
4546

4647
enum NewTabPosition

src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,13 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::NewTabPosition)
260260

261261
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FirstWindowPreference)
262262
{
263-
JSON_MAPPINGS(2) = {
263+
JSON_MAPPINGS(4) = {
264264
pair_type{ "defaultProfile", ValueType::DefaultProfile },
265-
pair_type{ "persistedWindowLayout", ValueType::PersistedWindowLayout },
265+
pair_type{ "persistedLayoutAndContent", ValueType::PersistedLayoutAndContent },
266+
pair_type{ "persistedLayout", ValueType::PersistedLayout },
267+
268+
// Keep deprecated keys last, so when they get serialized again they aren't written out
269+
pair_type{ "persistedWindowLayout", ValueType::PersistedLayoutAndContent },
266270
};
267271
};
268272

src/cascadia/WindowsTerminal/WindowEmperor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ void WindowEmperor::_finalizeSessionPersistence() const
10751075

10761076
const auto state = ApplicationState::SharedInstance();
10771077

1078-
_persistState(state, true);
1078+
_persistState(state, _app.Logic().Settings().GlobalSettings().FirstWindowPreference() == FirstWindowPreference::PersistedLayoutAndContent);
10791079

10801080
if (_needsPersistenceCleanup)
10811081
{

0 commit comments

Comments
 (0)