Skip to content

Commit 550754c

Browse files
committed
First functional version of the package
1 parent 34be6a0 commit 550754c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

BackgroundColorEdit.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sublime
2+
import sublime_plugin
3+
4+
import plistlib
5+
import re
6+
7+
class EditBackgroundColorCommand(sublime_plugin.WindowCommand):
8+
def run(self):
9+
sublime.active_window().show_input_panel("New hex background color", "#", change_background_color, None, None)
10+
11+
class ShowBackgroundColorCommand(sublime_plugin.WindowCommand):
12+
def run(self):
13+
currentThemeName = str.lstrip(
14+
sublime.load_settings('Preferences.sublime-settings').get('color_scheme', ''), 'Packages')
15+
16+
currentThemePath = sublime.packages_path() + currentThemeName
17+
18+
tree = plistlib.readPlist(currentThemePath)
19+
sublime.active_window().status_message(
20+
"Current background color: " + tree['settings'][0]['settings']['background'])
21+
22+
def change_background_color(userInput):
23+
match = re.search(r'^#(?:[0-9a-fA-F]{1,2}){3}$', userInput)
24+
25+
if match:
26+
currentThemeName = str.lstrip(
27+
sublime.load_settings('Preferences.sublime-settings').get('color_scheme', ''), 'Packages')
28+
29+
currentThemePath = sublime.packages_path() + currentThemeName
30+
31+
tree = plistlib.readPlist(currentThemePath)
32+
tree['settings'][0]['settings']['background'] = userInput
33+
plistlib.writePlist(tree, currentThemePath)

Default.sublime-commands

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"caption": "BackgroundColorEdit: Set Background Color",
4+
"command": "edit_background_color"
5+
},
6+
{
7+
"caption": "BackgroundColorEdit: Show Background Color",
8+
"command": "show_background_color"
9+
}
10+
]

0 commit comments

Comments
 (0)