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
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
[quote=“khrizt”]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[/quote]
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]curr_view = self.view
self.window.focus_view(curr_view)
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.
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
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
We don’t switch to a different Window, we activate a different View within a Window.
[code]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
win.run_command(“next_view”)
Or you can consider running the ‘select_by_index’ command.
[quote=“khrizt”]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[/quote]
If you are on windows, there is the window.hwnd() api, which you can then feed to the win32 api, SetForegroundWindow()
>>> from ctypes import windll
>>> windll.user32.SetForegroundWindow(window.hwnd())