Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 17 additions & 1 deletion src/cascadia/TerminalSettingsModel/EnumMappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
11 changes: 10 additions & 1 deletion src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ 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" };
static constexpr std::string_view LegacyInputServiceWarningKey{ "inputServiceWarning" };
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
Expand Down Expand Up @@ -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<std::pair<std::string_view, std::string_view>, 2> userDefaultSettings{ { { "copyOnSelect", "false" },
{ "copyFormatting", "false" } } };
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace Microsoft.Terminal.Settings.Model
enum FirstWindowPreference
{
DefaultProfile,
PersistedWindowLayout,
PersistedLayout,
PersistedLayoutAndContent,
};

enum NewTabPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading