forked from yyjhao/sublime-text-markmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarkmonListener.py
42 lines (31 loc) · 1.25 KB
/
MarkmonListener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sublime
import sublime_plugin
class MarkmonListener(sublime_plugin.EventListener):
@classmethod
def shared_plugin(cls):
"""Return the plugin instance."""
return cls.shared_instance
def __init__(self, *args, **kwargs):
"""Initialize a new instance."""
super().__init__(*args, **kwargs)
self.settings = None
self.on_setting_change_callbacks = []
self.on_modified_callbacks = []
self.__class__.shared_instance = self
def add_on_settings_change(self, callback):
self.on_setting_change_callbacks.append(callback)
callback(self.settings)
def add_on_modified(self, callback):
self.on_modified_callbacks.append(callback)
def load_settings(self):
self.settings = sublime.load_settings('sublime-text-markmon.sublime-settings')
self.settings.add_on_change("*", self.settings_updated)
def settings_updated(self):
for callback in self.on_setting_change_callbacks:
callback(self.settings)
def on_modified_async(self, view):
for callback in self.on_modified_callbacks:
callback(view)
def on_activated_async(self, view):
for callback in self.on_modified_callbacks:
callback(view)