forked from dempfi/ayu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activation.py
93 lines (57 loc) · 2.06 KB
/
activation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import functools
NO_SELECTION = -1
PREFERENCES = 'Preferences.sublime-settings'
THEMES = [ 'ayu-light', 'ayu-mirage', 'ayu-dark' ]
def get_color_scheme():
return sublime.load_settings(PREFERENCES).get('color_scheme', '')
def set_color_scheme(path):
return sublime.load_settings(PREFERENCES).set('color_scheme', path)
def preview_color_scheme(path):
set_color_scheme(path)
def activate_color_scheme(path):
set_color_scheme(path)
commit()
def revert_color_scheme(path):
set_color_scheme(path)
def get_ui_theme():
return sublime.load_settings(PREFERENCES).get('theme', '')
def set_ui_theme(path):
return sublime.load_settings(PREFERENCES).set('theme', path)
def preview_ui_theme(path):
set_ui_theme(path)
def activate_ui_theme(path):
set_ui_theme(path)
commit()
def revert_ui_theme(path):
set_ui_theme(path)
def commit():
return sublime.save_settings(PREFERENCES)
class AyuActivateCommand(sublime_plugin.WindowCommand):
def display_list(self, themes):
self.themes = themes
self.initial_color_scheme = get_color_scheme()
self.initial_ui_theme = get_ui_theme()
quick_list = [theme.replace("-", " ") for theme in self.themes]
self.quick_list = quick_list
self.window.show_quick_panel(quick_list, self.on_done, on_highlight=self.on_highlighted)
def on_highlighted(self, index):
preview_color_scheme(self._quick_list_to_scheme(index))
preview_ui_theme(self._quick_list_to_theme(index))
def on_done(self, index):
if index is NO_SELECTION:
revert_color_scheme(self.initial_color_scheme)
revert_ui_theme(self.initial_ui_theme)
return
color_scheme = self._quick_list_to_scheme(index)
activate_color_scheme(color_scheme)
ui_theme = self._quick_list_to_theme(index)
activate_ui_theme(ui_theme)
def _quick_list_to_scheme(self, index):
return 'Packages/ayu/%s.tmTheme' % THEMES[index]
def _quick_list_to_theme(self, index):
return '%s.sublime-theme' % THEMES[index]
def run(self):
self.display_list(THEMES)