terminal/src/cascadia/TerminalSettingsModel
Schuyler Rosefield 13e9546bab
Persist window layout on window close (#10972)
This commit adds initial support for saving window layout on application
close.

Done:
- Add user setting for if tabs should be maintained.
- Added events to track the number of open windows for the monarch, and
  then save if you are the last window closing.
- Saves layout when the user explicitly hits the "Close Window" button.
- If the user manually closed all of their tabs (through the tab x
  button or through closing all panes on the tab) then remove any saved
  state.
- Saves in the ApplicationState file a list of actions the terminal can
  perform to restore its layout and the window size/position
  information.
- This saves an action to focus the correct pane, but this won't
  actually work without #10978. Note that if you have a pane zoomed, it
  does still zoom the correct pane, but when you unzoom it will have a
  different pane selected.

Todo:
- multiple windows? Right now it can only handle loading/saving one
  window.
   - PR #11083 will save multiple windows.
- This also sometimes runs into the existing bug where multiple tabs
  appear to be focused on opening.

Next Steps:
- The business logic of when the save is triggered can be adjusted as
  necessary.
- Right now I am taking the pragmatic approach and just saving the state
  as an array of objects, but only ever populate it with 1, that way
  saving multiple windows in the future could be added without breaking
  schema compatibility. Selfishly I'm hoping that handling multiple
  windows could be spun off into another pr/feature for now.
- One possible thing that can maybe be done is that the commandline can
  be augmented with a "--saved ##" attribute that would load from the
  nth saved state if it exists. e.g. if there are 3 saved windows, on
  first load it can spawn three wt --saved {0,1,2} that would reopen the
  windows? This way there also exists a way to load a copy of a previous
  window (if it is in the saved state).
- Is the application state something that is planned to be public/user
  editable? In theory the user could since it is just json, but I don't
  know what it buys them over just modifying their settings and
  startupActions.

Validation Steps Performed:
- The happy path: open terminal -> set setting to true -> close terminal
  -> reopen and see tabs. Tested with powershell/cmd/wsl windows.
- That closing all panes/tabs on their own will remove the saved
  session.
- Open multiple windows, close windows and confirm that the last window
  closed saves its state.

The generated file stores a sequence of actions that will be executed to
restore the terminal to its saved form.

References #8324
This is also one of the items on microsoft/terminal#5000
Closes #766
2021-09-08 22:44:53 +00:00
..
dll Revert "Upgrade to Microsoft.UI.Xaml 2.6.2 (or equivalent) (#10996)" (#11031) 2021-08-24 17:46:12 -05:00
Resources/en-US Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
ActionAndArgs.cpp Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
ActionAndArgs.h Add action to run multiple actions. (#11045) 2021-08-31 19:35:51 +00:00
ActionArgs.cpp Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
ActionArgs.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
ActionArgs.idl Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
ActionMap.cpp Make ActionMap compatible with ScanCode-only KeyChords (#10945) 2021-08-20 00:21:33 +00:00
ActionMap.h Make ActionMap compatible with ScanCode-only KeyChords (#10945) 2021-08-20 00:21:33 +00:00
ActionMap.idl Adding/fixing Alt+Space handling (#10799) 2021-08-10 19:53:07 +00:00
ActionMapSerialization.cpp Use WinRT VirtualKeyModifiers instead of a custom enum (#10603) 2021-07-12 21:24:26 +00:00
AllShortcutActions.h Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
AppearanceConfig.cpp Add an ENUM setting for disabling rendering "intense" text as bold (#10759) 2021-08-16 13:45:56 +00:00
AppearanceConfig.h Render "intense" text as bright by default (#10958) 2021-08-16 19:59:37 +00:00
AppearanceConfig.idl Add support for a profile to specify an "unfocused" appearance (#8392) 2021-04-08 22:46:16 +00:00
ApplicationState.cpp Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
ApplicationState.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
ApplicationState.idl Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
AzureCloudShellGenerator.cpp Add support for a profile to specify an "unfocused" appearance (#8392) 2021-04-08 22:46:16 +00:00
AzureCloudShellGenerator.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
CascadiaSettings.cpp Use the "base" profile for incoming handoff and new commands (#11022) 2021-08-25 22:41:42 +00:00
CascadiaSettings.h Allow generated profiles to be deleted (#11007) 2021-08-23 22:00:08 +00:00
CascadiaSettings.idl Rely more on profile objects and less on GUIDs (#10982) 2021-08-23 12:11:53 -05:00
CascadiaSettingsSerialization.cpp Allow generated profiles to be deleted (#11007) 2021-08-23 22:00:08 +00:00
ColorScheme.cpp Introduce MS.Term.Core.Color to replace W.U.Color for Core/Control/TSM (#9658) 2021-03-30 20:15:49 +00:00
ColorScheme.h Introduce MS.Term.Core.Color to replace W.U.Color for Core/Control/TSM (#9658) 2021-03-30 20:15:49 +00:00
ColorScheme.idl Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
Command.cpp Bugfix: serialize iterable commands (#10373) 2021-06-10 18:25:27 +00:00
Command.h Introduce serialization for actions (#9926) 2021-05-20 18:44:04 +00:00
Command.idl Introduce ActionMap to Terminal Settings Model (#9621) 2021-05-04 21:50:13 -07:00
DefaultProfileUtils.cpp Introduce setting override tracking and update SettingContainer (#9079) 2021-02-19 23:50:52 +00:00
DefaultProfileUtils.h Make Global and Profile settings inheritable (#7923) 2020-10-27 17:35:09 +00:00
defaults-universal.json Introduce vk() and sc() key chord specifiers (#10666) 2021-07-20 22:34:51 +00:00
defaults.json Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
DefaultTerminal.cpp Prevent crashes in Settings UI launch on OS versions before package management extensions (#10238) 2021-05-27 17:53:00 +00:00
DefaultTerminal.h Prevent crashes in Settings UI launch on OS versions before package management extensions (#10238) 2021-05-27 17:53:00 +00:00
DefaultTerminal.idl Implement UI for choosing default terminal inside Settings page (#9907) 2021-04-28 10:43:30 +00:00
EnumMappings.cpp Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
EnumMappings.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
EnumMappings.idl Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
FileUtils.cpp Fix WriteUTF8FileAtomic to preserve symlinks (#10908) 2021-08-12 16:47:16 +00:00
FileUtils.h Introduce a basic ApplicationState class (#10513) 2021-06-30 02:25:44 +02:00
FontConfig.cpp Allow users to set font features and font axes (#10525) 2021-07-22 23:15:44 +00:00
FontConfig.h Allow users to set font features and font axes (#10525) 2021-07-22 23:15:44 +00:00
FontConfig.idl Allow users to set font features and font axes (#10525) 2021-07-22 23:15:44 +00:00
GlobalAppSettings.cpp Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
GlobalAppSettings.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
GlobalAppSettings.idl Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
HashUtils.h Introduce ActionMap to Terminal Settings Model (#9621) 2021-05-04 21:50:13 -07:00
IAppearanceConfig.idl Add an ENUM setting for disabling rendering "intense" text as bold (#10759) 2021-08-16 13:45:56 +00:00
IconPathConverter.cpp Revert "Add the profile, page icons to the page headers (#10046)" (#10124) 2021-05-18 17:35:50 -05:00
IconPathConverter.h Move IconSourceConverter from TerminalApp to TSM 2020-12-11 13:17:22 -08:00
IconPathConverter.idl Move IconSourceConverter from TerminalApp to TSM 2020-12-11 13:17:22 -08:00
IDynamicProfileGenerator.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
IInheritable.h Move TerminalSettings from TermApp to TerminalSettingsModel (#9318) 2021-03-15 23:15:25 +00:00
IInheritable.idl.h Introduce setting override tracking and update SettingContainer (#9079) 2021-02-19 23:50:52 +00:00
init.cpp Hook up the WIL fallback error tracer in Terminal (#7864) 2020-10-09 22:20:12 +00:00
JsonUtils.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
KeyChordSerialization.cpp Fix: Multimedia Key Hotkey Support (#10801) 2021-07-27 17:11:51 +00:00
KeyChordSerialization.h Introduce ActionMap to Terminal Settings Model (#9621) 2021-05-04 21:50:13 -07:00
KeyChordSerialization.idl Rename Microsoft.Terminal.TerminalControl to .Control; Split into dll & lib (#9472) 2021-03-17 20:47:24 +00:00
LegacyProfileGeneratorNamespaces.h From orbit, nuke the Telnet connection and all supporting infra. (#7840) 2020-10-09 18:59:58 +00:00
Microsoft.Terminal.Settings.ModelLib.vcxproj Revert "Upgrade to Microsoft.UI.Xaml 2.6.2 (or equivalent) (#10996)" (#11031) 2021-08-24 17:46:12 -05:00
Microsoft.Terminal.Settings.ModelLib.vcxproj.filters Enable /Zc:preprocessor (#10593) 2021-07-13 23:00:11 +00:00
packages.config Update C++/WinRT to 2.0.210309.3 (#9437) 2021-03-10 16:04:59 -06:00
pch.cpp Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
pch.h Fix crash when unpackaged due to PrimaryLanguageOverride (#10434) 2021-06-16 21:08:14 +00:00
PowershellCoreProfileGenerator.cpp Add support for a profile to specify an "unfocused" appearance (#8392) 2021-04-08 22:46:16 +00:00
PowershellCoreProfileGenerator.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
Profile.cpp Allow generated profiles to be deleted (#11007) 2021-08-23 22:00:08 +00:00
Profile.h Allow generated profiles to be deleted (#11007) 2021-08-23 22:00:08 +00:00
Profile.idl Allow generated profiles to be deleted (#11007) 2021-08-23 22:00:08 +00:00
SettingsTypes.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
TerminalSettings.cpp Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
TerminalSettings.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
TerminalSettings.idl Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
TerminalSettingsSerializationHelpers.h Persist window layout on window close (#10972) 2021-09-08 22:44:53 +00:00
TerminalWarnings.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
TerminalWarnings.idl Invalidate nested command with no valid subcommands (#9495) 2021-03-15 16:34:06 +00:00
userDefaults.json Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00
WslDistroGenerator.cpp Lookup WSL distros in the registry (#10967) 2021-08-24 13:10:36 +00:00
WslDistroGenerator.h Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00