2
2
import sublime_plugin
3
3
4
4
from .plugin import logger as log
5
- from .plugin . color_manager import color_manager , load_color_manager
5
+ from .lib . sublime_lib import ResourcePath
6
6
from .plugin .settings import load_settings , settings , unload_settings
7
7
8
8
NAME = "Colored Comments"
9
9
VERSION = "3.0.3"
10
10
11
11
comment_selector = "comment - punctuation.definition.comment"
12
12
13
+ # Thanks PackageDev
14
+ SCHEME_TEMPLATE = """\
15
+ {
16
+ // http://www.sublimetext.com/docs/3/color_schemes.html
17
+ "variables": {
18
+ "important_comment": "var(region.redish)",
19
+ "deprecated_comment": "var(region.purplish)",
20
+ "question_comment": "var(region.cyanish)",
21
+ "todo_comment": "var(region.greenish)",
22
+ "fixme_comment": "var(region.bluish)",
23
+ "undefined_comment": "var(region.accent)",
24
+ },
25
+ "globals": {
26
+ // "foreground": "var(green)",
27
+ },
28
+ "rules": [
29
+ {
30
+ "name": "IMPORTANT COMMENTS",
31
+ "scope": "comments.important",
32
+ "foreground": "var(important_comment)",
33
+ "background": "rgba(1,22,38, 0.1)",
34
+ },
35
+ {
36
+ "name": "DEPRECATED COMMENTS",
37
+ "scope": "comments.deprecated",
38
+ "foreground": "var(deprecated_comment)",
39
+ "background": "rgba(1,22,38, 0.1)",
40
+ },
41
+ {
42
+ "name": "QUESTION COMMENTS",
43
+ "scope": "comments.question",
44
+ "foreground": "var(question_comment)",
45
+ "background": "rgba(1,22,38, 0.1)",
46
+ },
47
+ {
48
+ "name": "TODO COMMENTS",
49
+ "scope": "comments.todo",
50
+ "foreground": "var(todo_comment)",
51
+ "background": "rgba(1,22,38, 0.1)",
52
+ },
53
+ {
54
+ "name": "FIXME COMMENTS",
55
+ "scope": "comments.fixme",
56
+ "foreground": "var(fixme_comment)",
57
+ "background": "rgba(1,22,38, 0.1)",
58
+ },
59
+ {
60
+ "name": "UNDEFINED COMMENTS",
61
+ "scope": "comments.undefined",
62
+ "foreground": "var(undefined_comment)",
63
+ "background": "rgba(1,22,38, 0.1)",
64
+ },
65
+ ],
66
+ }""" .replace (" " , "\t " )
67
+
68
+ KIND_SCHEME = (sublime .KIND_ID_VARIABLE , "s" , "Scheme" )
69
+ DEFAULT_CS = 'Packages/Color Scheme - Default/Mariana.sublime-color-scheme'
70
+
71
+
72
+ class ColoredCommentsEditSchemeCommand (sublime_plugin .WindowCommand ):
73
+
74
+ """Like syntax-specific settings but for the currently used color scheme."""
75
+
76
+ def run (self ):
77
+ view = self .window .active_view ()
78
+ if not view :
79
+ return
80
+
81
+ scheme_path = self .get_scheme_path (view , 'color_scheme' )
82
+ if scheme_path != 'auto' :
83
+ self .open_scheme (scheme_path )
84
+ else :
85
+ paths = [
86
+ (setting , self .get_scheme_path (view , setting ))
87
+ for setting in ('dark_color_scheme' , 'light_color_scheme' )
88
+ ]
89
+ choices = [
90
+ sublime .QuickPanelItem (
91
+ setting , details = str (path ), kind = KIND_SCHEME )
92
+ for setting , path in paths
93
+ ]
94
+
95
+ def on_done (i ):
96
+ if i >= 0 :
97
+ self .open_scheme (paths [i ][1 ])
98
+
99
+ self .window .show_quick_panel (choices , on_done )
100
+
101
+ @staticmethod
102
+ def get_scheme_path (view , setting_name ):
103
+ # Be lazy here and don't consider invalid values
104
+ scheme_setting = view .settings ().get (setting_name , DEFAULT_CS )
105
+ if scheme_setting == 'auto' :
106
+ return 'auto'
107
+ elif "/" not in scheme_setting :
108
+ return ResourcePath .glob_resources (scheme_setting )[0 ]
109
+ else :
110
+ return ResourcePath (scheme_setting )
111
+
112
+ def open_scheme (self , scheme_path ):
113
+ self .window .run_command (
114
+ 'edit_settings' ,
115
+ {
116
+ 'base_file' : '/' .join (("${packages}" ,) + scheme_path .parts [1 :]),
117
+ 'user_file' : "${packages}/User/" + scheme_path .stem + '.sublime-color-scheme' ,
118
+ 'default' : SCHEME_TEMPLATE ,
119
+ },
120
+ )
121
+
13
122
14
123
class ColoredCommentsEventListener (sublime_plugin .EventListener ):
15
124
def on_init (self , views ):
@@ -63,7 +172,7 @@ def ApplyDecorations(self) -> None:
63
172
self .view .add_regions (
64
173
key = key .lower (),
65
174
regions = to_decorate .get (key ),
66
- scope = settings .get_scope_for_region (tag ),
175
+ scope = settings .get_scope_for_region (key , tag ),
67
176
icon = settings .get_icon (),
68
177
flags = settings .get_flags (tag ),
69
178
)
@@ -87,9 +196,7 @@ def run(self, edit):
87
196
88
197
89
198
def plugin_loaded () -> None :
90
- global color_scheme_manager
91
199
load_settings ()
92
- load_color_manager ()
93
200
log .set_debug_logging (settings .debug )
94
201
95
202
0 commit comments