forked from vojtajina/sublime-BuildSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_switcher.py
60 lines (42 loc) · 1.72 KB
/
build_switcher.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
from sublime_plugin import WindowCommand
class BuildSwitcherCommand(WindowCommand):
def __init__(self, window):
WindowCommand.__init__(self, window)
settings = self.window.active_view().settings()
settings.add_on_change("build_switcher_systems", self._reload_settings)
self._reload_settings()
def _reload_settings(self):
settings = self.window.active_view().settings()
self.available_systems = settings.get("build_switcher_systems")
def run(self):
win = self.window
if not self.available_systems:
# no switcher builds - just do selected build
win.run_command("build")
elif len(self.available_systems) is 1:
# only one build system - just run it
self._run_build(0)
else:
# more options, show the popup
win.show_quick_panel(self.available_systems, self._run_build)
def _run_build(self, idx):
# the dialog was cancelled
if idx is -1: return
item = self.available_systems[idx]
if isinstance(item, list):
system = item[0].partition("#")
build = item[1]
else:
system = item.partition("#")
build = system[0]
self.window.run_command("set_build_system", {"file": build})
if system[1]:
self.window.run_command("build", {"variant": system[2]})
else:
self.window.run_command("build")
# move the last used system to first position
self.available_systems.insert(0, self.available_systems.pop(idx))
def is_enabled(self):
return True
def description(self):
return "Pop up a dialog with available build commands."