Skip to content

Commit 9f30f6f

Browse files
committed
Show error message when scheme is unsupported + updated readme
When the color scheme is not a raw file on the filesystem, show a message in the status area. Also, created a method for getting the path of the current scheme and cleaned up some copy/pasted code. Changed a bunch of instances of 'theme' to 'color scheme' for accuracy.
1 parent 93e6957 commit 9f30f6f

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

BackgroundColorEdit.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,40 @@
33

44
import plistlib
55
import re
6+
import os.path as path
67

78
class EditBackgroundColorCommand(sublime_plugin.WindowCommand):
89
def run(self):
910
sublime.active_window().show_input_panel("New hex background color", "#", change_background_color, None, None)
1011

1112
class ShowBackgroundColorCommand(sublime_plugin.WindowCommand):
1213
def run(self):
13-
currentThemeName = str.lstrip(
14-
sublime.load_settings('Preferences.sublime-settings').get('color_scheme', ''), 'Packages')
14+
currentSchemePath = getCurrentSchemePath()
1515

16-
currentThemePath = sublime.packages_path() + currentThemeName
16+
if path.isfile(currentSchemePath):
17+
tree = plistlib.readPlist(currentSchemePath)
18+
sublime.active_window().status_message(
19+
"Current background color: " + tree['settings'][0]['settings']['background'])
1720

18-
tree = plistlib.readPlist(currentThemePath)
19-
sublime.active_window().status_message(
20-
"Current background color: " + tree['settings'][0]['settings']['background'])
21+
else:
22+
sublime.active_window().status_message("The current color scheme is not supported.")
2123

2224
def change_background_color(userInput):
2325
match = re.search(r'^#(?:[0-9a-fA-F]{1,2}){3}$', userInput)
2426

2527
if match:
26-
currentThemeName = str.lstrip(
27-
sublime.load_settings('Preferences.sublime-settings').get('color_scheme', ''), 'Packages')
28+
currentSchemePath = getCurrentSchemePath()
2829

29-
currentThemePath = sublime.packages_path() + currentThemeName
30+
if path.isfile(currentSchemePath):
31+
tree = plistlib.readPlist(currentSchemePath)
32+
tree['settings'][0]['settings']['background'] = userInput
33+
plistlib.writePlist(tree, currentSchemePath)
3034

31-
tree = plistlib.readPlist(currentThemePath)
32-
tree['settings'][0]['settings']['background'] = userInput
33-
plistlib.writePlist(tree, currentThemePath)
35+
else:
36+
sublime.active_window().status_message("The current color scheme is not supported.")
37+
38+
def getCurrentSchemePath():
39+
currentSchemeName = str.lstrip(
40+
sublime.load_settings('Preferences.sublime-settings').get('color_scheme', ''), 'Packages')
41+
42+
return sublime.packages_path() + currentSchemeName

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# BackgroundColorEdit
22

3-
Allows you to quickly and easily change only the background color of the currently active theme in Sublime Text 3.
3+
Allows you to quickly and easily change only the background color of the currently active color scheme in Sublime Text 3.
44

5-
Currenntly only works with themes installed via [Colorsublime](colorsublime.com/).
5+
Currenntly only works with color schemes installed via [Colorsublime](colorsublime.com/).
66

77
## Requirements
88

@@ -28,8 +28,8 @@ Clone this repo to your Sublime Text 'Packages' directory, which can be found vi
2828
1. Open the command palette (`ctrl+shift+p` or `cmd+shift+p` by default)
2929
2. Search for `BackgroundColorEdit: Set Background Color`
3030
3. Type a hex color code in the prompt provided and press enter to apply.
31-
4. Alternately, search for `BackgroundColorEdit: Show Background Color` to print out the active theme's current background color to the status bar.
31+
4. Alternately, search for `BackgroundColorEdit: Show Background Color` to print out the active color scheme's current background color to the status bar.
3232

3333
## Resetting the background color
3434

35-
Simply reinstall the theme in Colorsublime.
35+
Simply reinstall the color scheme in Colorsublime.

0 commit comments

Comments
 (0)