-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtags_ui.py
89 lines (71 loc) · 2.82 KB
/
gtags_ui.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
import sublime
import sublime_plugin
import SublimeGtags.gtags_event
import SublimeGtags.gtags_navigation
import logging
from SublimeGtags.gtags_event import GtagsEventListener
from SublimeGtags.gtags_navigation import GtagsNavigation
import os
from sublime_plugin import all_callbacks
logging.basicConfig(format="[%(asctime)s] - [%(name)s] - [%(levelname)s] - \n%(message)s\n")
logger = logging.getLogger('UI')
logger.setLevel(logging.DEBUG)
class GtagsUIQuickPanel(object):
symbol = None
show_traces = False
def file_jump(self, path, line=None):
GtagsNavigation().lock()
if path is not None:
logger.info("jump to file: %s:%s", line, path)
position = '%s:%d:0' % (os.path.normpath(path), int(line))
sublime.active_window().open_file(position, sublime.ENCODED_POSITION)
if self.show_traces is False:
GtagsNavigation().add(path, line, self.symbol)
GtagsNavigation().unlock()
def file_preview(self, path, line):
GtagsNavigation().lock()
if path is not None:
logger.info("preview file: %s:%s", line, path)
position = '%s:%d:0' % (os.path.normpath(path), int(line))
sublime.active_window().open_file(position, sublime.ENCODED_POSITION | sublime.TRANSIENT)
GtagsNavigation().unlock()
def show(self, panel_list, path_list, event_listener=None):
if len(path_list) != 0:
GtagsEventListener().register(event_listener)
def on_select(index):
if 'Symbol Traces' in panel_list[0]:
if index > 0:
index = index - 1
GtagsNavigation().set_cur_index(index)
logger.info("select %d", index)
if index > 0:
self.file_jump(path_list[index]["path"], path_list[index]["line"])
else:
self.file_jump(path_list[0]["path"], path_list[0]["line"])
GtagsEventListener().unregister(event_listener)
def on_highlight(index):
logger.info("highlight %d", index)
if index > 0:
if 'Symbol Traces' in panel_list[0]:
index = index - 1
self.file_preview(path_list[index]["path"], path_list[index]["line"])
#panel_list = [ ["1", "1.1", "1.2"] , ["2", "2.1", "2.2"] ]
view = sublime.active_window().active_view()
self.symbol = view.substr(view.word(view.sel()[0].a))
if 'Symbol Traces' not in panel_list[0]:
if 'Symbol References' in panel_list[0]:
logger.info("Symbol Ref")
self.symbol = "R : " + self.symbol
else:
logger.info("Symbol Def")
self.symbol = "D : " + self.symbol
GtagsNavigation().add(view.file_name(), view.rowcol(view.sel()[0].a)[0]+1, self.symbol)
else:
self.show_traces = True
sublime.active_window().run_command('hide_overlay')
logger.info("panel_list len %d", len(panel_list))
# jump immediately when there is only one item
if len(panel_list) == 2:
self.file_jump(path_list[1]["path"], path_list[1]["line"])
else:
sublime.active_window().show_quick_panel(panel_list, on_select, 0, -1, on_highlight)