Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember/Restore multiple projects #17

Closed
uberbrady opened this issue Sep 21, 2014 · 14 comments
Closed

Remember/Restore multiple projects #17

uberbrady opened this issue Sep 21, 2014 · 14 comments

Comments

@uberbrady
Copy link

I had two 'projects' open at the same time - windows each with an array of tabs. When I quit and relaunched Atom, only the frontmost window was restored.

So I tend to have multiple projects open at the same time. So I am very excited to get this functionality back that I miss from Sublime Text!!! (I, in fact, continue to run Sublime just to have the Untitled File support. Perhaps no longer, now that I've found this!).

Here's how I was able to reproduce the issue -

cd folder1
atom .
cd ../folder2
atom .

Then quit, and re-launch Atom. Only the folder2 'project' will be reopened.

@mpeterson2
Copy link
Owner

I like the idea, but I'm not sure if this is going to be possible to do. From what I can tell Atom handles separate windows almost like separate applications, so I have no way of knowing whether you are closing the window or closing the application.

The way that I can think of solving this (which I don't believe is possible at the time), would be to save the open projects whenever you open/close a project, and do nothing when you close the application with cmd + q or the Atom -> Quit Atom. I haven't found a way to determine whether you are closing just a window or closing the entire application, so I don't believe there is a very good way to handle this with Atom's current API.

If you have any ideas or interest in implementing them, let me know or send a pull request/update the issue with some useful information!

@uberbrady
Copy link
Author

I've been rolling this around in my head, too.

I was imagining an algorithm something like this (and some of these things won't directly be possible, but I think it could be the right track) -

On Quit, do:

If there is no flag file, add a flag file, truncate the save file to zero bytes.
If there is a flag file, and the flag file is from within the last...minute? or so? then just be prepared to append to it. Else truncate as above.

Now, as each atom 'process' (window?) closes, it follows the above algorithm. Thus it should write the save data to the file, and exit (without closing the file?! Not sure). The end result is a save-file with all of the current open workspaces as Atom was quit.

On Reopen:

Open the save file. For each entry, open that project. Once all of the files are open, delete the flag file.

So, I guess - if you just 'close' one of the windows - you don't do anything.

Another thing to note is that you might be able to wrap the 'flag' and the 'save-file' into just one logical file; not sure.

A problem with this setup would be that, in the event of a crash, you get nothing. That would suck.

If this sounds like a direction that might work, let me know. I don't know anything about developing for Atom, but I'm a pretty seasoned coffeescript developer and should be able to at least take a rough swing at it to get started.

@mpeterson2
Copy link
Owner

My thoughts

I think they're pretty similar, but here's my thoughts after reading your's.

Saving

I think open projects could just be saved in ~/.atom/packages/save-session/projects/open-projects.json. I have a few thoughts on how the json could be stored. The first would allow for more to be saved in the future, but I'm not sure if that's to worth it for now.

Json Version 1

The json could just contain a list of open projects that have a key of their path and contain a time value since the last closing. If the project is still open, exclude the time since last closing.

open.json example:

[
    {
        "path": "path/to/closed/project",
        "closeTime": 123456
    },
    {
        "path": "path/to/open/project"
    }
]

Json Version 2

Or, it could just be a map with a key of the project and a value of the time since closed. The time is just undefined if the project is open.

open.json example:

{
  "path/to/closed/project": 123456,
  "path/to/open/project": "undefined"
}

On open

  • Read the json file
  • Overwrite the current project to say it's open
  • Reopen projects if every project contains a closedTime

By only reopening projects if they all contain a closedTime, we avoid restoring projects if the user just opens a new Atom window/project.

On close

  • Read the file
  • Overwrite the current project with a closedTime, to say it's closed
  • Remove all the old projects from the json
  • Rewrite the open-projects.json file

Settings

Everything should be optional, including this feature. How long after a project has closed to be considered open should also be an option. The location of the open-projects.json file should also be a setting.

Developing for Atom

Atom has a pretty simple API, I've never used CoffeeScript before this project, so it was all new to me and I picked it up pretty quickly. The documentation is fairly good, and there is a nice guide for building a simple Atom package.

Anyway, let me know what you think.

@prometheas
Copy link

Yea, this is huge. The plugin is frankly incomplete until all open projects can be restored.

@uberbrady
Copy link
Author

Here's another thought I had - you can make it even simpler, perhaps -

Every time you open a project, you append that to the re-opening file.
Every time you close a project, you remove that project from the re-opening file.

On crash or quit - just read that file and open those projects. The problem - in my cursory examination - looked like it was going to be hard to hook in to the close-button on the window, and the close project menu item in the menus. You'd basically want to override those, right? Everything else might stay the same.

@mpeterson2
Copy link
Owner

It would be nice to have it that simple, but the problem with that is there is no way that I've found to tell whether you're closing a project or closing Atom itself. I suppose hooking into the UI buttons to close projects would work, but like you said, that's not an easy task to do.

Also if you did this on open, than each project that is opened, will try to open all the projects that are saved in that file. We don't want that to happen.

@swrobel
Copy link

swrobel commented Nov 5, 2014

I think https://github.com/norio-nomura/restore-windows claims to do this ... perhaps some clues in there

@mpeterson2
Copy link
Owner

Looks like it works pretty similar to what's been said on here previously. I think we have the ability to do it, I just don't have the time for it right now unfortunately.

@inteist
Copy link

inteist commented Nov 27, 2014

+1 having this feature!
Please keep in mind that you can have an open window through CMD SHIFT N too, not just from the command line

@mpeterson2 mpeterson2 changed the title Only one project seems to be getting restored? Remember/Restore multiple projects Feb 3, 2015
@Santinell
Copy link

Now with version 0.182 of Atom feature of multiple projects became necessary (Multi root in one window)

@dmsimard
Copy link

Agreed, would love to have this work properly with the Atom feature of multiple root folders in the same window. It only re-opens one of the root folders.

@mpeterson2
Copy link
Owner

This should be in Atom core now.

@Goddard
Copy link

Goddard commented Jul 31, 2015

This feature is still not working in Atom latest build on Windows and Linux. It only works in OSX.

@Santinell
Copy link

I thought so too, but after deleting all atom files and installing atom again - it works for me on Linux and Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants