8000 Backported refractoring and fixes from ST3 · vprimachenko/Sublime-Colorcoder@c215243 · GitHub
[go: up one dir, main page]

Skip to content

Commit c215243

Browse files
committed
Backported refractoring and fixes from ST3
2 parents 4c56ffa + 1aa1c3d commit c215243

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

colorcoder.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,24 @@ def crc(self, msg):
4242
runningCRC = self.crcTable[runningCRC ^ c]
4343
return runningCRC
4444

45+
def plugin_loaded():
46+
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme',maybefixscheme)
47+
pp = sublime.packages_path()
48+
if not os.path.exists(pp+"/Colorcoder"):
49+
os.makedirs(pp+"/Colorcoder")
50+
51+
firstrunfile = pp+"/Colorcoder/firstrun"
52+
if not os.path.exists(firstrunfile):
53+
maybefixscheme()
54+
open(firstrunfile, 'a').close()
55+
4556
class colorcoder(sublime_plugin.EventListener):
4657

4758
hasher = crc8();
4859

4960
def __init__(self):
50-
sublime.set_timeout(self.read_settings,500)
51-
52-
def read_settings(self):
53-
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme',self.maybefixscheme)
54-
pp = sublime.packages_path()
55-
if not os.path.exists(pp+"/Colorcoder"):
56-
os.makedirs(pp+"/Colorcoder")
57-
58-
firstrunfile = pp+"/Colorcoder/firstrun"
59-
if not os.path.exists(firstrunfile):
60-
self.maybefixscheme()
61-
open(firstrunfile, 'a').close()
62-
63-
self.on_modified(sublime.active_window().active_view())
64-
65-
def maybefixscheme(self):
66-
set = sublime.load_settings("colorcoder.sublime-settings")
67-
if set.get('auto_apply_on_scheme_change'):
68-
if sublime.load_settings("Preferences.sublime-settings").get('color_scheme').find('/Colorcoder/') == -1:
69-
modify_color_scheme(set.get('lightness'),set.get('saturation'))
70-
71-
def on_modified(self, view):
72-
sublime.set_timeout(lambda: self.on_modified_async(view), 0)
61+
sublime.set_timeout(plugin_loaded,500)
62+
sublime.set_timeout(lambda: self.on_modified(sublime.active_window().active_view()),500)
7363

7464
def on_load(self,view):
7565
if view.file_name():
@@ -90,6 +80,8 @@ def on_load(self,view):
9080

9181
self.on_modified(view)
9282

83+
def on_modified(self, view):
84+
sublime.set_timeout(lambda: self.on_modified_async(view), 0)
9385

9486
def on_modified_async(self, view):
9587
if not view.settings().get('colorcode',True):
@@ -111,6 +103,10 @@ def on_text_command(self, win, cmd, args):
111103
if cmd=="set_file_type":
112104
self.on_modified_async(sublime.active_window().active_view())
113105

106+
class colorcoderdisabler(sublime_plugin.ApplicationCommand):
107+
def run(self):
108+
sublime.active_window().active_view().settings().set('colorcode',False)
109+
114110
class colorshemeemodifier(sublime_plugin.ApplicationCommand):
115111
def run(self):
116112
sublime.active_ 8000 window().show_input_panel("Lightness and Saturation","%s %s" % (sublime.load_settings("colorcoder.sublime-settings").get('lightness'),sublime.load_settings("colorcoder.sublime-settings").get('saturation')),self.panel_callback,None,None)
@@ -123,16 +119,18 @@ def panel_callback(self, text):
123119
sublime.save_settings("colorcoder.sublime-settings")
124120
sublime.set_timeout(lambda: modify_color_scheme(l,s,True), 0)
125121

126-
127-
128122
class colorcoderInspectScope(sublime_plugin.ApplicationCommand):
129123
def run(self):
130124
view = sublime.active_window().active_view();
131125
sel = view.sel()[0]
132126
print(view.scope_name(sel.a))
133127
sublime.active_window().run_command("show_panel", {"panel": "console", "toggle": True})
134128

135-
modification_running = False
129+
def maybefixscheme():
130+
set = sublime.load_settings("colorcoder.sublime-settings")
131+
if set.get('auto_apply_on_scheme_change'):
132+
if sublime.load_settings("Preferences.sublime-settings").get('color_scheme').find('/Colorcoder/') == -1:
133+
modify_color_scheme(set.get('lightness'),set.get('saturation'))
136134

137135
def modify_color_scheme(l,s,read_original = False):
138136
global modification_running
@@ -187,3 +185,5 @@ def modify_color_scheme(l,s,read_original = False):
187185
sublime.save_settings("Preferences.sublime-settings")
188186

189187
modification_running = False
188+
189+
modification_running = False

colorcoder.sublime-settings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"entity.name",
44
"support.function",
55
"meta.function-call",
6-
"variable.other"]
6+
"variable.other"],
7+
"auto_apply_on_scheme_change": true,
8+
"lightness":0.5,
9+
"saturation":0.5
710
}

0 commit comments

Comments
 (0)
0