-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpm-plugin.py
71 lines (52 loc) · 1.75 KB
/
hpm-plugin.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
import sublime_plugin
import threading
import subprocess
import os
class HpmInstallCommand(sublime_plugin.WindowCommand):
def run(self):
window = self.window
window.show_input_panel("Package:", '',
lambda s: self.install_package(s), None, None)
def install_package(self, package):
command = 'hpm install %s' % package
thread = CommandThread(command.split(' '))
thread.start()
while thread.is_alive():
pass
focus_all_views(self.window)
class HpmRequireCommand(sublime_plugin.WindowCommand):
def run(self):
window = self.window
window.show_input_panel("Package:", '',
lambda s: self.require_package(s), None, None)
def require_package(self, package):
file_name = self.window.active_view().file_name()
command = 'hpm require %s %s' % (package, file_name)
thread = CommandThread(command.split(' '))
thread.start()
while thread.is_alive():
pass
focus_all_views(self.window)
class HpmDocsCommand(sublime_plugin.WindowCommand):
def run(self):
window = self.window
window.show_input_panel("Package:", '',
lambda s: self.open_docs(s), None, None)
def open_docs(self, package):
command = 'hpm docs %s' % package
CommandThread(command.split(' ')).start()
class CommandThread(threading.Thread):
def __init__(self, command):
self.command = command
threading.Thread.__init__(self)
def run(self):
subprocess.Popen(self.command, cwd=os.getcwd())
def focus_all_views(window):
current_view = window.active_view()
gr_number = window.num_groups()
for i in range(0, gr_number):
window.focus_group(i)
views_in_i = window.views_in_group(i)
for inner_view in views_in_i:
window.focus_view(inner_view)
window.focus_view(current_view)