-
Notifications
You must be signed in to change notification settings - Fork 9
/
WordPressCodex.py
99 lines (78 loc) · 3.26 KB
/
WordPressCodex.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
91
92
93
94
95
96
97
98
99
# written by Matthias Krok (www.welovewordpress.de)
# based on Stackoverflow Search Plugin by Eric Martel (emartel@gmail.com / www.ericmartel.com)
# available commands
# wordpress_codex_open_selection
# wordpress_codex_search_selection
# wordpress_codex_search_from_input
import sublime
import sublime_plugin
import subprocess
def OpenInBrowser(url):
sublime.active_window().run_command('open_url', {"url": url})
def SearchWpCodexFor(text):
url = 'http://wordpress.org/search/' + text.replace(' ','%20')
OpenInBrowser(url)
def SearchQPFor(text):
url = 'http://queryposts.com/?s=' + text.replace(' ','%20')
OpenInBrowser(url)
def OpenWpFunctionReference(text):
url = 'http://codex.wordpress.org/Function_Reference/' + text.replace(' ','%20')
OpenInBrowser(url)
def OpenQPFunctionReference(text):
url = 'http://queryposts.com/function/' + text.replace(' ','%20')
OpenInBrowser(url)
class WordpressCodexOpenSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for selection in self.view.sel():
# if the user didn't select anything, search the currently highlighted word
if selection.empty():
selection = self.view.word(selection)
text = self.view.substr(selection)
OpenWpFunctionReference(text)
class WordpressCodexSearchSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for selection in self.view.sel():
# if the user didn't select anything, search the currently highlighted word
if selection.empty():
selection = self.view.word(selection)
text = self.view.substr(selection)
SearchWpCodexFor(text)
class WordpressCodexSearchFromInputCommand(sublime_plugin.WindowCommand):
def run(self):
# Get the search item
self.window.show_input_panel('Search WordPress Codex for', '',
self.on_done, self.on_change, self.on_cancel)
def on_done(self, input):
SearchWpCodexFor(input)
def on_change(self, input):
pass
def on_cancel(self):
pass
# query_posts_search_selection
class QueryPostsOpenSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for selection in self.view.sel():
# if the user didn't select anything, search the currently highlighted word
if selection.empty():
selection = self.view.word(selection)
text = self.view.substr(selection)
OpenQPFunctionReference(text)
class QueryPostsSearchSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for selection in self.view.sel():
# if the user didn't select anything, search the currently highlighted word
if selection.empty():
selection = self.view.word(selection)
text = self.view.substr(selection)
SearchQPFor(text)
class QueryPostsSearchFromInputCommand(sublime_plugin.WindowCommand):
def run(self):
# Get the search item
self.window.show_input_panel('Search QueryPosts.com for', '',
self.on_done, self.on_change, self.on_cancel)
def on_done(self, input):
SearchQPFor(input)
def on_change(self, input):
pass
def on_cancel(self):
pass