Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions colorcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def on_load(self,view):
return

vcc = view.settings().get('color_scheme')
if vcc and "Widget" in vcc:
if vcc and "Widget" in vcc:
view.settings().set('colorcode',False)
return

Expand Down Expand Up @@ -152,6 +152,32 @@ def panel_callback(self, text):
sublime.save_settings("colorcoder.sublime-settings")
colorshemeemodifier.modify_color_scheme(l,s,True)

@staticmethod
def get_save_dir():
set = sublime.load_settings("colorcoder.sublime-settings")
save_dir = set.get('colorcoder_schemas_dir')
if save_dir:
if save_dir[0] != '/':
save_dir = '/' + save_dir
if save_dir[-1] != '/':
save_dir = save_dir + '/'
else:
save_dir = ''

set.set('colorcoder_schemas_dir', save_dir)
sublime.save_settings("colorcoder.sublime-settings")

pp = sublime.packages_path()
save_dir = pp + save_dir
if not os.path.exists(save_dir):
os.makedirs(save_dir)
firstrunfile = save_dir + '/firstrun'
if not os.path.exists(firstrunfile):
colorshemeemodifier.maybefixscheme()
open(firstrunfile, 'a').close()

return save_dir

@staticmethod
def maybefixscheme():
set = sublime.load_settings("colorcoder.sublime-settings")
Expand Down Expand Up @@ -204,9 +230,9 @@ def modify_color_scheme(l,s,read_original = False):
)
))

newname = "/Colorcoder/%s (Colorcoded).tmTheme" % re.search("/([^/]+).tmTheme$", name).group(1)
newname = "/%s (Colorcoded).tmTheme" % re.search("/([^/]+).tmTheme$", name).group(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way you populate newname will lead to problems in L#238, as color_scheme setting expects to have an sublime.load_resource compatible path eg Packages/Colorcoder/Obsidian (Colorcoded).tmTheme

i guess it would be simpler just to do

newname = "/%s/%s (Colorcoded).tmTheme" % (set.get('colorcoder_schemas_dir').strip("/\\"), re.search("/([^/]+).tmTheme$", name).group(1))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. It has a relative and full path now. Phew! You were completely right. I was missing something huge!


plistlib.writePlist(cs,"%s%s" % (sublime.packages_path(),newname))
plistlib.writePlist(cs,"%s%s" % (colorshemeemodifier.get_save_dir(),newname))

sublime.load_settings("Preferences.sublime-settings").set("original_color_scheme", name)
sublime.load_settings("Preferences.sublime-settings").set("color_scheme","Packages%s" % newname)
Expand All @@ -228,15 +254,9 @@ def run(self):
def plugin_loaded():
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme',colorshemeemodifier.maybefixscheme)
sublime.load_settings("colorcoder.sublime-settings").add_on_change('scopes',colorcoder.update_scopes)

colorcoder.update_scopes()
pp = sublime.packages_path()
if not os.path.exists(pp+"/Colorcoder"):
os.makedirs(pp+"/Colorcoder")

firstrunfile = pp+"/Colorcoder/firstrun"
if not os.path.exists(firstrunfile):
colorshemeemodifier.maybefixscheme()
open(firstrunfile, 'a').close()
colorshemeemodifier.get_save_dir()

for wnd in sublime.windows():
for view in wnd.views():
Expand Down
2 changes: 2 additions & 0 deletions colorcoder.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"meta.function-call",
"variable.other"],
"auto_apply_on_scheme_change": true,
"colorcoder_schemas_dir": "/Colorcoder",
"lightness":0.5,
"max_size": 10000,
"saturation":0.5
}