Home Download Buy Blog Forum Support

[Fixed] Storing settings for a view in the session

[Fixed] Storing settings for a view in the session

Postby glycerine on Wed Oct 31, 2012 10:03 am

Hi,

Is there a way to detect that ST2 is reopening tabs / continuing a session (hot exit)?
I've made the code below (somewhat simplified) but it crashes.

Code: Select all
   def on_load(self,view):
      window = sublime.active_window()
      rightIndex = len(window.views()) - 1
      window.set_view_index(view, window.active_group(), rightIndex)
      window.run_command("select_by_index", {"index": rightIndex})


Apparently, running window.run_command on every reopening tab isn't possible (too fast?).

Is there a way to detect that ST2 is reopening tabs / continuing a session (hot exit)? My code does not need to run in that case. Or, if that is not possible, could anyone give me advice on how to prevent this code from crashing ST2?

Thanks!
Last edited by glycerine on Tue Nov 06, 2012 9:51 pm, edited 1 time in total.
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby bizoo on Wed Oct 31, 2012 1:52 pm

Do you want to open new tab at right ?
https://github.com/stylishmedia/SublimeText-Tabright
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby glycerine on Wed Oct 31, 2012 6:45 pm

Hi,

This is the plugin I created. The problem I describe above is a problem that is currently with the plugin. I would like to fix it, but I need some help from the community...
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby bizoo on Wed Oct 31, 2012 7:59 pm

Oops, didn't know :oops:

Do you mean your code crash ST2 or there's only an exception in the console ?

I don't remember well, but I think that for my plugin I use the on_activated event to solve this issue.
When you enter the on_load event, the view is not yet assigned to a window, so I store a flag in the settings to tell the on_activated event to do the job (https://github.com/bizoo/SortTabs/blob/master/auto_sort_tabs.py).
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby glycerine on Wed Oct 31, 2012 8:23 pm

:D

No problem, thanks for taking the time to help! I'm not sure I understand what you mean yet.

The problem I am facing now, is that I use the on_load event to change the order of the tabs, every time a person opens a new file.
But the on_load event also fires, when you start SublimeText2 and the program automatically loads all files that were open in the previous session. (This is a feature called Hot Exit / Remember Open Files. I personally do not use this feature, but some users of course do.)
In this case, the on_load event fires but I would not like to change the order of the tabs in that case.

Maybe I should think of another solution?

I hope I explained well...

Thanks, once again!
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby bizoo on Thu Nov 01, 2012 7:49 am

From memory, settings are stored in the session.
I think that you can add a settings for each view you processed:
Code: Select all
self.view.settings().set('Tabright_processed', True)


So next time you enter the on_load event, you first checked the settings and do nothing if it's already processed:
Code: Select all
if not self.view.settings().get('Tabright_processed', False):
  self.view.settings().set('Tabright_processed', True):
  # your processing code


Settings will be discarded when you close the file.

This is totally hypothetical and not tested...
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Can I detect reopening tabs / continuing session (hot exit)?

Postby glycerine on Tue Nov 06, 2012 6:32 pm

Thanks! That was really helpful, I learned something about Sublimetext!

I implemented your solution and I'm waiting to find out if it works for the user reporting the problem in the first place. Thanks for helping me improve this tiny plugin!
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests