Home Download Buy Blog Forum Support

storing per window settings

storing per window settings

Postby farfromrefuge on Fri Jan 17, 2014 12:02 pm

Hi

I am developing a plugin and i want to store per-window (project actually) settings. Those settings only need to be persistent during the session.
They can be cleared every time the plugin is reloaded.
Right now i use "global" but then my settings are shared between all windows.

Does anyone know how to do it?

Thanks
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: storing per window settings

Postby tito on Mon Jan 20, 2014 6:37 pm

http://www.sublimetext.com/docs/3/api_reference.html
Code: Select all
Class sublime.Window
Methods   Return Value   Description
id()   int   Returns a number that uniquely identifies this window.

Then...

Code: Select all
import sublime

my_session_settings = {}

def settings(name, value = 'Nopennada'):
    if value == "Nopennada":
       return my_session_settings[name]
    else:
       my_session_settings[name] = value


settings('something_global', 2+2)

print(settings('something_global')) # prints 4

settings('something_per_window_'+str(sublime.active_window().id()), 2+3)

print(settings('something_per_window_'+str(sublime.active_window().id()))) # prints 5

print(settings('something_global')) # prints 4
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 864
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: storing per window settings

Postby farfromrefuge on Wed Jan 22, 2014 2:30 pm

It works perfectly!!!!!
Thank you so much tito!
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 5 guests