This repository was archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathcolorswitch-plugin.py
More file actions
67 lines (55 loc) · 2.36 KB
/
colorswitch-plugin.py
File metadata and controls
67 lines (55 loc) · 2.36 KB
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
from .colorswitch import commands
from .colorswitch import status
from . import colorswitch
import sublime_plugin
NO_SELECTION = -1
class ColorSwitchInstallSchemeCommand(sublime_plugin.WindowCommand):
def run(self):
print('Running install command.')
self.theme_status = {}
self.status = status.loading('Getting scheme list')
self.original_theme = commands.get_current_theme()
commands.fetch_theme_list(self.display_list)
def display_list(self, themes):
self.status.stop()
if not themes:
status.error('Scheme list not found. Please check internet ' +
'connection or enable debug in the settings and ' +
'report the stack traces.')
return
self.themes = themes
self.window.show_quick_panel(themes.quick_list(),
self.on_select,
on_highlight=self.on_highlighted)
def on_highlighted(self, theme_index):
theme = self.themes[theme_index]
self.theme_status[theme.name] = status.loading('Downloading scheme %s' % theme.name)
self.current_theme = theme
commands.get_theme(self.themes[theme_index], self.on_get)
def on_get(self, theme):
self.theme_status[theme.name].stop()
if not theme.file_path:
status.error('Scheme %s download failed.' % theme.name)
return
# Don't set if user has moved on already
if theme.file_name == self.current_theme.file_name:
status.message('Showing scheme %s.' % theme.name)
commands.set_theme(theme)
def on_select(self, theme_index):
if theme_index is NO_SELECTION:
commands.set_theme(self.original_theme)
status.message('Scheme install canceled.')
return
theme = self.themes[theme_index]
status.message('Installing scheme %s' % theme.name)
commands.install_theme(theme, self.install_done)
def install_done(self, theme):
self.status.stop()
if theme is None:
commands.set_theme(self.original_theme)
status.error('Scheme install was unsuccessful. Please check console.')
return
commands.set_theme(theme)
status.message('Scheme installed successfully!')
def plugin_loaded():
colorswitch.init()