Sublime Forum

Views with no corresponding file

#1

Hi!
It seems that if I open the Console or the Find bar or any other area where you can input text, a new view is created. I have an EventListener class and I want to implement the on_activated(view) method but I want to ignore views that don’t belong to any file. First I wanted to check if view.file_name() != None but then I wouldn’t include the views of new unsaved files. Do you have an idea how to distinguish between views?
Thanks

0 Likes

#2

There is a setting “is_widget”. Perhaps that will give you what you want?

0 Likes

#3

I can’t find it in the API reference. Is this available in ST2? Because that’s what I’m using. I’m sorry for not mentioning this earlier.

0 Likes

#4

It’s not in the API doc. The easiest way to test this is to create a simple plugin using “on_activated”. Use the following for the plugin.

def on_activated(self, view): print(view.settings().get("is_widget"))

Now open up the console and a quick panel. Click from the quick panel to the view. Note that activating the view results in None. While clicking on the quick panel input results in True.

0 Likes

#5

Works perfectly! Thanks!

0 Likes

#6

Somehow this doesn’t help me though. I know of the ‘is_widget’ setting but I still get many views with their file_name() being None even though I have no unsaved buffers. I only get these when starting though. It seems to be exactly 4 calls for every window and I can say that this is not one of my open views because all of these are called with their file_name being set correctly.

Using this plugin:

import sublime, sublime_plugin

class TestListener(sublime_plugin.EventListener):
    def on_activated(self, view, call=0):
        print("Activated%d ::: %s, File: '%s', Widget: %s, Loading: %s, Scratch: %s, Dirty: %s"
              % (call, view, view.file_name(), view.settings().get('is_widget'),
                 view.is_loading(), view.is_scratch(), view.is_dirty()))
        if call < 1:
            sublime.set_timeout(lambda: self.on_activated(view, call + 1), 20)

I get the following output:

Activated0 ::: <sublime.View object at 0x000000000797D458>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000007A6A8D0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000868ADB0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x00000000086DD528>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x00000000086DD4C0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x00000000086DD938>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841A70>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841AD8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841BA8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841CE0>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841C78>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841D48>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841E18>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008841EE8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E048>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E118>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E1E8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E2B8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E388>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E458>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E528>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E730>, File: 'E:\Development\_Misc\_Misc\ToDo\ToDo.fmd', Widget: None, Loading: True, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E6C8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E868>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889E8D0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EA08>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EAD8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EBA8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000872E730>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889ED48>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EE80>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EF50>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x000000000889EEE8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A26048>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A26118>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A261E8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A262B8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A26388>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated0 ::: <sublime.View object at 0x0000000008A26458>, File: 'None', Widget: None, Loading: True, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000797D458>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x0000000007A6A8D0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000868ADB0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x00000000086DD528>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x00000000086DD4C0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x00000000086DD938>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841A70>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841AD8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841BA8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841CE0>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841C78>, File: 'E:\Development\_Misc\_Misc\ToDo\ToDo.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841D48>, File: 'E:\Dropbox\Public\notes\sleep.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841E18>, File: 'E:\Dropbox\Public\notes\studying.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008841EE8>, File: 'E:\Development\_Misc\_Misc\ToDo\ToSub.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E048>, File: 'E:\Dropbox\Public\notes\soup_tags.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E118>, File: 'E:\Dropbox\Public\notes\danbooru_tags.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E1E8>, File: 'e:\Video\Anime\_AKA\Busou Shinki Moon Angel\progress.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E2B8>, File: 'E:\Dropbox\Public\notes\IRC_Quotes.txt', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E388>, File: 'E:\Dropbox\Public\notes\league_of_legends.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E458>, File: 'E:\Dropbox\Public\notes\aegisub_thoughts.txt', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E528>, File: 'E:\Dropbox\Public\notes\sublime.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E730>, File: 'E:\Development\_Misc\_Misc\ToDo\ToDo.fmd', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889E6C8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000889E868>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000889E8D0>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000889EA08>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x000000000889EAD8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889EBA8>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000872E730>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889ED48>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889EE80>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889EF50>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x000000000889EEE8>, File: 'C:\Users\<user>\AppData\Roaming\Sublime Text 2\Packages\InactivePanes\inactive_pane.py', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008A26048>, File: 'C:\Users\<user>\AppData\Roaming\Sublime Text 2\Packages\User\test.py', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008A26118>, File: 'None', Widget: None, Loading: False, Scratch: True, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008A261E8>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: True
Activated1 ::: <sublime.View object at 0x0000000008A262B8>, File: 'C:\Users\<user>\AppData\Roaming\Sublime Text 2\Packages\Default\Default (Windows).sublime-keymap', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008A26388>, File: 'C:\Users\<user>\AppData\Roaming\Sublime Text 2\Packages\User\Preferences.sublime-settings', Widget: None, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x0000000008A26458>, File: 'None', Widget: None, Loading: False, Scratch: False, Dirty: True
Activated0 ::: <sublime.View object at 0x00000000086DD938>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False
Activated1 ::: <sublime.View object at 0x00000000086DD938>, File: 'None', Widget: True, Loading: False, Scratch: False, Dirty: False

Since we can agree that the Activated0 calls are pretty useless (why?):
All the Activated1 calls together cover all my open views + one scratch + one dirty view, even though there are still numerous (8) calls with “File: ‘None’, Widget: None, Loading: False, Scratch: False, Dirty: False”.

So, this comes down to 2 issues with the API:

  1. When I get a view I expect that view to be accessable at the time I get it passed and not try again after 20ms to be able to read it’s values.
  2. Even when all my actually existing views are passed there are still 8 (probably 4 per window) “shadow views” that I can’t assign.

So, if I had to fix issue 1. by re-calling the function again with the same view object in order to wait for Sublime Text to fill it with values I’ll automatically encounter issue 2.: there will always be void views. Because I obviously have to check for 1. dynamically with a variable time interval I’d have to set a maximum iteration counter to not run into 2. and an infinite loop.
I hope that this is understandable and that others can reproduce this.

Edit: Oh, I forgot: ST2 2220 Win7x64. I will test with ST3 tomorrow.

Edit2: Can’t reproduce this on ST3 3031, I don’t get any calls besides the one actially activated.

Edit3: I worked around this by just ignoring all calls of on_activated until the plugin is initialized (“plugin_loaded”) and then iterating over all views in all windows. See: github.com/SublimeText/Inactive … 1761688d72

0 Likes

Dev Build 3031