From 002a1cfff4c5d7ffcc6e6b0cdffddd582b20e51b Mon Sep 17 00:00:00 2001 From: tdhsmith Date: Wed, 4 Feb 2015 14:50:48 -0600 Subject: [PATCH 1/2] Move color scheme fixes to User directory Package Control users utilizing the 'fix color scheme' feature would have their schemes overwritten on every update, leading to an annoying 'missing color scheme' popup. This moves future fixes to the User folder to avoid deletion. Since the issue affects this update as well, there is also a small function to fail a bit more gracefully, reverting missing themes to Monokai rather than generating endless dialog boxes (which is Sublime's ridiculous default behavior). --- gutter_color.py | 36 ++++++++++++++++++++++++++++++++---- messages.json | 4 +++- messages/v0.2.1.txt | 3 +++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 messages/v0.2.1.txt diff --git a/gutter_color.py b/gutter_color.py index da6fe92..e7387be 100644 --- a/gutter_color.py +++ b/gutter_color.py @@ -73,11 +73,37 @@ def fix_schemes_in_windows(): from sublime import windows for window in windows(): for view in window.views(): + check_bad_scheme_dir(view) if syntax(view) in settings().get('supported_syntax'): fix_scheme_in_view(view) +def check_bad_scheme_dir(view): + current_scheme = view.settings().get("color_scheme") + if "Packages/GutterColor" in current_scheme or "Packages/Gutter Color" in current_scheme: + # we are using the incorrect (0.2.0) directory for schemes, so we clear any settings matching it + view.settings().set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme") + + global_settings = load_settings("Preferences.sublime-settings") + if (global_settings.get("color_scheme") == current_scheme): + global_settings.erase("color_scheme") + save_settings("Preferences.sublime-settings") + + syntax_filename = view.settings().get('syntax').split('/')[-1].split('.')[0] + ".sublime-settings" + syntax_settings = load_settings(syntax_filename) + if (syntax_settings.get("color_scheme") == current_scheme): + syntax_settings.erase("color_scheme") + save_settings(syntax_filename) + + print("WARNING: Color schemes can no longer be saved in main Gutter Color package directory. Your scheme has been reset. See v0.2.1 changelog for details.") + + def fix_scheme_in_view(view, regenerate=False, ignore_flags=False): """Change color scheme in settings relevant to current view""" + + current_scheme = view.settings().get("color_scheme") + modified_marker = ".gcfix." + + # parse settings flags. TODO: move this to a settings on_change event fix_flag = settings().get("fix_color_schemes", False) (fix_syntax, fix_global, fix_custom) = (False, False, False) custom_files = [] @@ -97,15 +123,14 @@ def fix_scheme_in_view(view, regenerate=False, ignore_flags=False): else: return # setting is false, nonexistant, or malformed, so exit - current_scheme = view.settings().get("color_scheme") - modified_marker = ".gcfix." + if modified_marker in current_scheme: if regenerate: new_scheme = current_scheme else: return # this view already has a fixed scheme and we aren't regenerating, so exit else: - new_scheme = "Packages/"+current_directory()+"/"+current_scheme.split("/")[-1].split(".")[0]+\ + new_scheme = "Packages/User/GutterColor/"+current_scheme.split("/")[-1].split(".")[0]+\ modified_marker + current_scheme.split(".")[-1] if fix_custom: @@ -124,12 +149,15 @@ def fix_scheme_in_view(view, regenerate=False, ignore_flags=False): def fix_scheme_in_settings(settings_file,current_scheme, new_scheme, regenerate=False): """Change the color scheme in the given Settings to a background-corrected one""" - from os.path import join, normpath, isfile + from os.path import join, normpath, isfile, isdir + from os import makedirs settings = load_settings(settings_file) settings_scheme = settings.get("color_scheme") if current_scheme == settings_scheme: new_scheme_path = join(packages_path(), normpath(new_scheme[len("Packages/"):])) + if not isdir(join(packages_path(), normpath("User/GutterColor/"))): + makedirs(join(packages_path(), normpath("User/GutterColor/"))) if isfile(new_scheme_path) and not regenerate: settings.set("color_scheme", new_scheme) else: diff --git a/messages.json b/messages.json index d04c6d8..d30d17e 100644 --- a/messages.json +++ b/messages.json @@ -1,3 +1,5 @@ { - "install": "messages/install.txt" + "install": "messages/install.txt", + "0.2.0": "messages/v0.2.0.txt", + "0.2.1": "messages/v0.2.1.txt" } \ No newline at end of file diff --git a/messages/v0.2.1.txt b/messages/v0.2.1.txt new file mode 100755 index 0000000..784b36a --- /dev/null +++ b/messages/v0.2.1.txt @@ -0,0 +1,3 @@ +This version changes the default directory for color scheme fixes to the user directory. This will prevent some issues where Package Control would unavoidably erase the file during updates. + +If you used the color fix feature before this release, your scheme has been removed and temporarily reverted to Monokai. You may need to re-set your global and syntax-specific color schemes manually; we apologize for this inconvenience. From f70949fbb58a54d59eebc52ec4e6da8213a2224b Mon Sep 17 00:00:00 2001 From: tdhsmith Date: Wed, 4 Feb 2015 14:58:50 -0600 Subject: [PATCH 2/2] Wrong target version numbers --- messages.json | 2 +- messages/{v0.2.1.txt => v0.2.2.txt} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename messages/{v0.2.1.txt => v0.2.2.txt} (100%) diff --git a/messages.json b/messages.json index d30d17e..dcf36bb 100644 --- a/messages.json +++ b/messages.json @@ -1,5 +1,5 @@ { "install": "messages/install.txt", "0.2.0": "messages/v0.2.0.txt", - "0.2.1": "messages/v0.2.1.txt" + "0.2.2": "messages/v0.2.2.txt" } \ No newline at end of file diff --git a/messages/v0.2.1.txt b/messages/v0.2.2.txt similarity index 100% rename from messages/v0.2.1.txt rename to messages/v0.2.2.txt