I would like to work with an event which fires when I change the color_scheme setting located inside Preferences.sublime-settings for a plugin I'm writing for Sublime Text 2.

I've read to use on_window_command of EventListener but it seems it doesn't fire.

class MyPluginEvents(sublime_plugin.EventListener):
    def on_window_command(self, window, command_name, args):
        print " --- FIRE! --- "

I've also tried post_window_command without success. Is there any way to detect when the preferences change?

有帮助吗?

解决方案

Those docs you linked to are for ST3. Here are the docs for ST2. Note there is not on_window_command. That aside, you may want to take a look at Settings#add_on_change. I've never used that method in the API before, but based on the description, it should do what you want.

Edit

Know you have solution already, but adding this for anyone else that comes by this. You would likely tie into an event, such as on_load or on_new so the command will run on any newly created view.

import sublime_plugin

class TestCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        settings = self.view.settings()
        settings.add_on_change("color_scheme", self.callback)

    def callback(self):
        print(self.view.settings().get("color_scheme"))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top