Home Download Buy Blog Forum Support

Get view instance from ID

Get view instance from ID

Postby khrizt on Mon Mar 05, 2012 8:28 pm

Hi,

Is there a way to get the View object using its ID? I can't find anything like that in the documentation and would be great to be able to store just the ID and the use the object.

Thanks
khrizt
 
Posts: 14
Joined: Thu Feb 23, 2012 8:08 am

Re: Get view instance from ID

Postby agibsonsw on Mon Mar 05, 2012 8:55 pm

khrizt wrote:Hi,

Is there a way to get the View object using its ID? I can't find anything like that in the documentation and would be great to be able to store just the ID and the use the object.

Thanks


Hello. The id doesn't really help for this. You can store a reference to the view and then, for example, use this reference later to focus the view, or run a command in it:

Code: Select all
curr_view = self.view
# later..
self.window.focus_view(curr_view)
# or similar..

In my recent example, the id was useful to store information about a particular view, and then to later retrieve this information based on the id.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Get view instance from ID

Postby khrizt on Mon Mar 05, 2012 10:17 pm

Man! You're everywhere ;)

Thanks for the tip, it was very useful
khrizt
 
Posts: 14
Joined: Thu Feb 23, 2012 8:08 am

Re: Get view instance from ID

Postby sublimator on Tue Mar 06, 2012 1:34 pm

sublime.windows()
window.views()
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Get view instance from ID

Postby khrizt on Tue Mar 06, 2012 2:39 pm

Yeah, that's a possibility too, but I wanted to know if there was a function that could get the instance using only the ID, although these functions would also work and I wouldn't need to keep the references for all the views.

Thanks, I'll try that
khrizt
 
Posts: 14
Joined: Thu Feb 23, 2012 8:08 am

Re: Get view instance from ID

Postby khrizt on Sun Mar 18, 2012 2:14 pm

All your advices worked really well... but I have another doubt, does someone knows how to switch to a different window from the current one? I haven't seen anything like that in the API Reference.

Thanks
khrizt
 
Posts: 14
Joined: Thu Feb 23, 2012 8:08 am

Re: Get view instance from ID

Postby agibsonsw on Sun Mar 18, 2012 4:39 pm

We don't switch to a different Window, we activate a different View within a Window.

Code: Select all
win = sublime.active_window()

new_view = win.new_file()    # or
open_view = win.open_file('somefile.txt')
win.focus_view(new_view)    # or open_view
# or..
win.run_command("next_view")
# win.run_command("prev_view")

Or you can consider running the 'select_by_index' command.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Get view instance from ID

Postby sublimator on Mon Mar 19, 2012 3:07 am

khrizt wrote:All your advices worked really well... but I have another doubt, does someone knows how to switch to a different window from the current one? I haven't seen anything like that in the API Reference.

Thanks


If you are on windows, there is the window.hwnd() api, which you can then feed to the win32 api, SetForegroundWindow()

Code: Select all
>>> from ctypes import windll
>>> windll.user32.SetForegroundWindow(window.hwnd())
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 8 guests