Home Download Buy Blog Forum Support

Save and restore all opened windows

Save and restore all opened windows

Postby guillermo.carrasco on Fri Apr 19, 2013 1:54 pm

Hi everybody,

I'm developing a plugin to save different sessions in Sublime Text 2. The idea of "saving a session" is to (in some way) save all the currently opened windows and its contents to a file. Then, to load a session you just need to load that file.

This plugin is quite easy to develop for one window: To save the current window, just save the content (file name, for example) of all its views. To load, just close all views and open a view for each file specified in the session file.

The problem comes when I want to save/load more than one window. I cannot find a way to close windows that are not the active one, and I also cannot open new windows programatically... I'm managing several options:

    - Save the info of the current windows in a file (for each window, save all its views. This should be enough)
    - Just serialize (pickle) the content of sublime.windows(), and load it when loading a session
    - Either modify or create several Session.sublime_session files and load/save

Any of this options seems to be valid, however as I said before, I cannot find a way to programatically open/close new windows. Can anyone help me please?

Thanks a lot!
guillermo.carrasco
 
Posts: 2
Joined: Fri Apr 19, 2013 1:39 pm

Re: Save and restore all opened windows

Postby adzenith on Sun Apr 21, 2013 8:30 pm

sublime.active_window().run_command('close_window')
sublime.active_window().run_command('new_window')

Discovered using sublime.log_commands(True)
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Save and restore all opened windows

Postby guillermo.carrasco on Mon Apr 22, 2013 7:17 am

Hi adzenith,

Thanks! This works fine :-). I also discovered that you can do the same with sublime.run_command('new_window'). The only problem with these two is that they don't return anything, like for example a reference to the new window created:

Code: Select all
>>> w = sublime.active_window().run_command('new_window')
>>> type(w)
<type 'NoneType'>


I can figure out a way to know where is the recently opened widow (it is appended to sublime.windows()), but I was just wandering if there is a more standard/official way to do this.

Thanks for your help!
guillermo.carrasco
 
Posts: 2
Joined: Fri Apr 19, 2013 1:39 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests