-
Notifications
You must be signed in to change notification settings - Fork 365
/
search_commands.py
54 lines (39 loc) · 1.84 KB
/
search_commands.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
import sublime_plugin
from .deprecated_command import deprecate
from .getTeXRoot import get_tex_root
from .latextools_utils import analysis, ana_utils, quickpanel
def _make_caption(ana, entry):
text = entry.text
file_pos_str = ana_utils.create_rel_file_str(ana, entry)
return "{text} ({file_pos_str})".format(**locals())
class LatextoolsSearchCommandCommand(sublime_plugin.WindowCommand):
def run(self, commands, only_current_file=False):
window = self.window
view = window.active_view()
tex_root = get_tex_root(view)
ana = analysis.analyze_document(tex_root)
entries = ana.filter_commands(commands, flags=analysis.ALL_COMMANDS)
if only_current_file:
file_name = view.file_name()
entries = [e for e in entries if e.file_name == file_name]
captions = [_make_caption(ana, e) for e in entries]
quickpanel.show_quickpanel(captions, entries)
class LatextoolsSearchCommandInputCommand(sublime_plugin.WindowCommand):
def is_visible(self, *args):
view = self.window.active_view()
return bool(view.score_selector(0, "text.tex"))
def run(self, only_current_file=False):
window = self.window
def on_done(text):
commands = [c.strip() for c in text.split(",")]
kwargs = {
"commands": commands,
"only_current_file": only_current_file
}
window.run_command("latextools_search_command", kwargs)
def do_nothing(text):
pass
caption = "Search for commands in a comma (,) separated list"
window.show_input_panel(caption, "", on_done, do_nothing, do_nothing)
deprecate(globals(), 'LatexSearchCommandCommand', LatextoolsSearchCommandCommand)
deprecate(globals(), 'LatexSearchCommandInputCommand', LatextoolsSearchCommandInputCommand)