Skip to content

Hot exit on switching folders #15467

Closed

Description

@Tyriar

Parent issue: #101

Sublime has a feature that allows hot exit to always be allowed on a window provided it has a project associated with it. The initial concern still remains that backups may go missing if we just always enable this, the Sublime project system is nice because the act of creating a project (.sublime-project) is basically an opt in for project-level features.

Interested in people's ideas on this, here are a few:

  • Enabling switching folders all the time?
  • Enable if <project>/.vscode exists?
  • Enable if a setting is toggled?
  • Enable if a setting includes the workspace path? (has issues with multi-folder workspaces)

Activity

  1. added
    feature-request
    workbench-hot-exit
    on Nov 14, 2016
  2. added this to the Backlog milestone on Nov 14, 2016
  3. Tyriar commented on Nov 14, 2016

    @Tyriar
    ContributorAuthor
  4. bpasero commented on Nov 14, 2016

    @bpasero
    Contributor

    Daniel Imms (@Tyriar) can you elaborate on the issue? you say I loose backups if I switch folders with dirty files opened?

  5. Tyriar commented on Nov 14, 2016

    @Tyriar
    ContributorAuthor

    In Sublime you can do this:

    1. Open folder 1
    2. Open folder 2
    3. Create a .sublime-project for folder 2
    4. Dirty folder 2 workspace (creates .sublime-workspace as a sibling to the .sublime-project)
    5. Close folder 2 (it's allowed even though it's not the last window because it's a "project")

    These backups are not restored if Sublime is then fully exited and relaunched.

    We could fairly easily change VS Code to allow this by default, but the concern is that Untitled backups for example could go missing by users accidentally closing the non-last window and not getting it restored.

    How #396 is solved could impact this as we may need to introduce a project concept.

  6. bpasero commented on Nov 14, 2016

    @bpasero
    Contributor

    Daniel Imms (@Tyriar) but is that 2 folders in the same window or in multiple windows? Do you imply that Sublime enables hot exit in this case even though the user did not enable it?

  7. Tyriar commented on Nov 14, 2016

    @Tyriar
    ContributorAuthor

    Benjamin Pasero (@bpasero) folder 1 and folder 2 in the above example are in different windows. Hot exit is enabled by default, I'm assuming this is disabled as well when it's disabled.

  8. bpasero commented on Nov 14, 2016

    @bpasero
    Contributor

    Ah so today for us when you close window 2 we ask for saving even though hot exit is enabled? That is the point I was missing.

  9. Tyriar commented on Nov 14, 2016

    @Tyriar
    ContributorAuthor

    Yeah that's right. I suggest this be deferred until after #396 is figured out.

  10. Tyriar commented on Nov 19, 2016

    @Tyriar
    ContributorAuthor

    Looked at Notepad++, it appears to have the same restrictions as Sublime Text where you can only close the last window. It also has a workspaces concept, however I did the following:

    1. Opened a second window
    2. Opened a folder as a workspace
    3. Dirtied some files
    4. Closed it, it exited without prompt

    But then I couldn't figure out how to restore the old files and hot exit seems to not work at all any more.

  11. added a commit that references this issue on Dec 14, 2016
  12. Tyriar commented on Jan 6, 2017

    @Tyriar
    ContributorAuthor

    Proposal

    I'm proposing the following to allow hot exit to be more flexible on what types of exits trigger a hot exit and also what exactly is restored on initial launch.

    Settings

    {
      // Whether hot exit is enabled which allows changes to unsaved files to be
      // remembered between sessions. Setting this to false will override all other
      // files.hotExit settings.
      "files.hotExit.enabled":
          true (default) | false,
      
      // What windows with backups should be restored when VS Code is launched (on
      // Mac this requires the application to be quit completely).
      "files.hotExit.restoreOnStartUp":
          "none" | "nonFolderWindows" | "folderWindows" | "all" (default),
      
      // What types of workspaces trigger a hot exit when a single window is
      // closed. Note that if VS Code is exited completely via the
      // workbench.action.quit command (via command pallete, keybinding of menu),
      // a hot exit will always trigger.
      "files.hotExit.backupOnWindowClose":
          "all" | "nonFolderWindows" | "folderWindows" | "none" (default),
    }

    The settings are hopefully self-explanatory, this had a number of iterations before posting this and I landed on this instead of a few pre-determined configurations as I believe this is a very personal decision since multiple people I asked wanted different things. Also with the above there is no change in the default behavior (conservative).

    The settings themselves also look much less intimidating when there is only the default value, so power users who want to configure to their desire are free to do so:

    {
      "files.hotExit.enabled": true,
      "files.hotExit.restoreOnStartUp": "all",
      "files.hotExit.backupOnWindowClose": "none",
    }

    This is my personal preference for example:

    {
      "files.hotExit.enabled": true,
      
      // If I explicitly close a folder window I'll restore it when I reopen the folder.
      "files.hotExit.restoreOnStartUp": "nonFolderWindows",
      
      // I'd prefer not to accidentally close non-folder windows but clean up after them.
      "files.hotExit.backupOnWindowClose": "folderWindows",
    }

    This will probably be a common configuration:

    {
      "files.hotExit.enabled": true, // (default)
      "files.hotExit.restoreOnStartUp": "all", // (default)
      "files.hotExit.backupOnWindowClose": "all",
    }

    Menu/command to restore

    Since not everything will potentially be restored on launch anymore, a menu and/or command is necessary to surface the currently backed up windows to the user. This is what I'm thinking for the menu item:

    File > Restore Backed Up Window
      Restore all
      ---
      Non-folder window #1
      Non-folder window #2
      ~/dev/Microsoft/vscode
      ~/dev/Microsoft/vscode
    

    The sub menu looks very similar to the Open Recent menu only with no clear (it's too destructive to have in the menu) and it features "Non-folder window #n" which I can't think of a better name for just yet.

    folderWindows vs nonFolderWindows

    Currently we name VS Code windows with no folder "empty workspaces" and those with a folder open "workspaces", this is confusing to many people and might be even more difficult to get across when multiple root workspaces #396 comes in. In addition it's been suggested we'll move towards identifying windows as windows rather than the workspaces they contain to make multiple windows with the same root #2686. So it makes sense to move the terminology towards something more understandable like this (or similar if there is a better alternative).

    Other considerations

    • We may want to limit the number of backups and/or restores if we allow random window closes to hot exit but all windows to be restored in order to prevent a situation where the PC can't handle launching so many instances at once.
    • Since it's very easy to quit accidentally now (cmd+q/ctrl+q) with no dialogs and things may not restore in their previous state (unless "windows.reopenFolders": "all"), it might be a good idea to introduce a window.promptOnApplicationExit boolean setting which shows a dialog before application exit.
  13. bpasero commented on Jan 6, 2017

    @bpasero
    Contributor

    Wow, I am reading through this and even though I know exactly how hot exit works because I reviewed the code and contributed to it I am having a hard time understanding either the need for the settings or the need for a special menu item to restore backup windows. I am also not seeing these options in other applications that support hot exit. I wonder if here we are going a bit too far with what you can configure and should rather just settle on a default that we think is right and leave it like that...

    Before going much into technical detail of what you want to change, what are the use cases for these changes?

  14. 11 remaining items

  15. Tyriar commented on Jan 9, 2017

    @Tyriar
    ContributorAuthor

    Another case for why the default should stay as is, consider a Mac user who has some unsaved work in a non-folder window and they close the window, expecting a save dialog. The dialog does not appear and they start to freak out, they try:

    • Closing their other windows
    • Opening new windows

    Their work will not restore until they either kill the application completely via cmd+q or restart the computer.

  16. chrmarti commented on Jan 9, 2017

    @chrmarti
    Collaborator

    I like the single setting that offers the three most predictable behaviors. (After talking to you in person.)

  17. Tyriar commented on Jan 15, 2017

    @Tyriar
    ContributorAuthor

    Benjamin Pasero (@bpasero) Christof Marti (@chrmarti) let me know what you think of this approach, using the single setting as proposed in #15467 (comment). It's working fine from what I can see but it would need a little more testing (plus fixing tests) 1af3873

    Note that https://code.visualstudio.com/docs/editor/codebasics#_hot-exit would also go into more detail on what appExit and appExitAndWindowClose do and mention the synergy with "window.reopenFolders": "all".

    My main concern with this approach is trying to briefly and succinctly differentiate the behaviors in the settings and the setting key itself only explains when the hot exit happens, not the change in restore behavior.

  18. bpasero commented on Jan 16, 2017

    @bpasero
    Contributor

    Daniel Imms (@Tyriar) can you explain to me this limitation:

    however only non-folder windows will be restored when the application is restarted (not folder workspaces).

    As for the behaviour, when I have appExitAndWindowClose enabled, does this mean when I open another folder in the same window with dirty files, hot exit kicks in and I am not asked to save? Or does that only work when the window I am in is an empty workspace window (given that limitation warning)?

    +1 for having this as enum inside the hot exit setting. My only concern is that maybe it should follow our files.autoSave naming and get rid of the obvious app in the name, so it would be onExit and on onExitAndWindowClose

  19. Tyriar commented on Jan 16, 2017

    @Tyriar
    ContributorAuthor

    That limitation is so people can close folders whrb they're done and open them again when they resume work on the folder. It's essentially this feature, #15467, so it acts more like sublime. The reason all non-folder workspaces are restored is to avoid needing a file menu by maintaining the "backups always visible" property for them.

    I like the idea of dropped app 👍

  20. bpasero commented on Jan 16, 2017

    @bpasero
    Contributor

    Daniel Imms (@Tyriar) maybe best to see with an example. Let's assume onExitAndWindowClose is set which as far as I understand is the new behaviour we are going to add here.

    Can you fill in the blanks what happens in the following cases, assuming each have dirty files:

    • user closes the window of a folder workspace
    • user closes the window of a non-folder workspace
    • user clicks on File > Close Folder in a folder workspace
    • user selects File > Open Folder in a window of a folder workspace
    • user selects File > Open Folder in a window of a non-folder workspace
  21. Tyriar commented on Jan 16, 2017

    @Tyriar
    ContributorAuthor

    For onExitAndWindowClose:

    user closes the window of a folder workspace
    Always hot exit

    user closes the window of a non-folder workspace
    If app exit: hot exit
    Else: prompt

    user clicks on File > Close Folder in a folder workspace
    Always hot exit

    user selects File > Open Folder in a window of a folder workspace
    Always hot exit

    user selects File > Open Folder in a window of a non-folder workspace
    If app exit: hot exit
    Else: prompt

  22. Tyriar commented on Jan 16, 2017

    @Tyriar
    ContributorAuthor

    Consider the following as an example user flow with onExitAndWindowClose:

    1. Open folder /foo
    2. Do some work in foo, keep some notes in untitled files, have unsaved text files, etc
    3. Open folder /bar in same window (/foo closes and hot exits)
    4. Some time passes, the main process is shutdown.
    5. VS Code is relaunched but only /bar is restored as it was the last opened folder
    6. When user is ready to resume work on /foo they reopen it and get their backed up untitled and text files restored

    Non-folder workspaces act the same as with onExit. We treat them more strictly since it's difficult to identify them and there is no way to restore except for during launch of main process.

  23. bpasero commented on Jan 16, 2017

    @bpasero
    Contributor

    Daniel Imms (@Tyriar) got it, I suggest we give it a try. As a mitigation maybe we could eventually add an entry to the File menu "Show previous sessions with backups" (bad name, but you get it) that opens a picker inside the window to select from? If we find out that people are confused by it.

  24. added
    verification-needed
    on Jan 24, 2017
  25. added
    verified
    on Jan 27, 2017
  26. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestverification-neededverifiedworkbench-hot-exit

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions