forked from SublimeText/ColdFusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cflib.py
43 lines (36 loc) · 1.57 KB
/
cflib.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
import sublime, sublime_plugin, json
from urllib import urlopen
CFLIBCATS = r"http://www.cflib.org/api/api.cfc?method=getlibraries&returnformat=json"
CFLIBUDFS = r"http://www.cflib.org/api/api.cfc?method=getudfs&returnformat=json&libraryid="
CFLIBUDF = r"http://www.cflib.org/api/api.cfc?method=getudf&returnFormat=json&udfid="
class ShowCflibCommand(sublime_plugin.WindowCommand):
categories = []
udfs = []
def __init__(self, *args, **kwargs):
super(ShowCflibCommand, self).__init__(*args, **kwargs)
categories = []
udfs = []
def run(self):
self.getCategories()
self.window.show_quick_panel([[v] for k, v in (self.categories)], self.on_select_categories)
def getCategories(self):
d = json.load(urlopen(CFLIBCATS))
self.categories = d['DATA']
def getUdfs(self,index):
d = json.load(urlopen(CFLIBUDFS + str(self.categories[index][0])))
self.udfs = d['DATA']
def on_select_categories(self, index):
if index == -1:
return
self.getUdfs(index)
self.window.show_quick_panel([[v.strip(), c.strip()] for k, v, c in self.udfs], self.on_select_udf)
def on_select_udf(self, index):
if index == -1:
self.run()
else:
d = json.load(urlopen(CFLIBUDF + str(self.udfs[index][0])))
self.window.active_view().run_command("insert_udf", {"code":str(d['CODE'])})
class InsertUdfCommand(sublime_plugin.TextCommand):
def run(self, edit, code):
for region in self.view.sel():
self.view.replace(edit, region, code)