-
Notifications
You must be signed in to change notification settings - Fork 19
/
picker.py
90 lines (72 loc) · 2.8 KB
/
picker.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
import sublime
import sublime_plugin
class CdnjsLibraryPickerCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
self.packages = args["packages"]
self.onlyURL = args["onlyURL"]
self.wholeFile = args["wholeFile"]
sublime.set_timeout(self.show_quickpanel, 10)
def get_list(self):
package_list = []
for x in self.packages:
if not x.get('name'):
x.update({'name': 'n/a'})
if not x.get('description'):
x.update({'description': 'n/a'})
package_list.append([x['name'], x.get('description')])
return package_list
def show_quickpanel(self):
self.view.window().show_quick_panel(self.get_list(), self.callback)
def callback(self, index):
if index == -1:
return
pkg = self.packages[index]
self.view.run_command('cdnjs_version_picker', {
"package": pkg,
"onlyURL": self.onlyURL,
"wholeFile":self.wholeFile
})
class CdnjsVersionPickerCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
self.package = args["package"]
self.onlyURL = args["onlyURL"]
self.wholeFile = args["wholeFile"]
sublime.set_timeout(self.show_quickpanel, 10)
def get_list(self):
assets = self.package["assets"]
versions = [version["version"] for version in assets]
return versions
def show_quickpanel(self):
self.view.window().show_quick_panel(self.get_list(), self.callback)
def callback(self, index):
if index == -1:
return
asset = self.package["assets"][index]
self.view.run_command('cdnjs_file_picker', {
"package": self.package,
"onlyURL": self.onlyURL,
"wholeFile": self.wholeFile,
"asset": asset
})
class CdnjsFilePickerCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
self.package = args.get("package", {})
self.asset = args.get("asset", {})
self.onlyURL = args.get("onlyURL", False)
self.wholeFile = args.get("wholeFile", False)
sublime.set_timeout(self.show_quickpanel, 10)
def get_list(self):
return self.asset.get("files", [])
def show_quickpanel(self):
self.view.window().show_quick_panel(self.get_list(), self.callback)
def callback(self, index):
if index == -1:
return
fileName = self.asset["files"][index]
self.view.run_command('cdnjs_tag_builder', {
"package": self.package,
"asset": self.asset,
"file": fileName,
"onlyURL": self.onlyURL,
"wholeFile": self.wholeFile
})