1
/* Copyright 2009 Yorba Foundation
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
18
public SymbolBrowser(Instance parent) {
21
find_entry = new Gtk.Entry();
22
find_entry.activate += on_entry_activated;
23
find_entry.changed += on_text_changed;
24
find_entry.focus_in_event += on_receive_focus;
26
// A width of 175 pixels is a sane minimum; the user can always expand this to be bigger
27
list = new ListViewString(Gtk.TreeViewColumnSizing.FIXED, 175);
28
list.row_activated += on_list_activated;
29
list.received_focus += on_list_receive_focus;
31
symbol_vbox = new Gtk.VBox(false, 6);
32
symbol_vbox.pack_start(find_entry, false, false, 0);
33
symbol_vbox.pack_start(list.scrolled_window, true, true, 0);
34
symbol_vbox.show_all();
36
weak Gedit.Panel panel = this.parent.window.get_side_panel();
37
panel.add_item_with_stock_icon(symbol_vbox, "Symbols", Gtk.STOCK_FIND);
39
panel.show += on_panel_open;
40
panel.hide += on_panel_hide;
43
void on_text_changed() {
47
void on_panel_open(Gedit.Panel panel) {
52
void on_panel_hide() {
56
void on_list_receive_focus(Gtk.TreePath? path) {
59
list.select_path(path);
62
bool on_receive_focus() {
63
if (parent.active_document_is_valid_vala_file()) {
64
parent.reparse_modified_documents(parent.active_filename());
71
public static void on_active_tab_changed(Gedit.Window window, Gedit.Tab tab,
72
SymbolBrowser browser) {
73
browser.on_update_symbols();
76
void on_update_symbols() {
77
string document_path = parent.active_filename();
78
if (document_path == null || !Program.is_vala(document_path))
81
Program program = Program.find_containing(document_path);
83
if (program.is_parsing())
84
program.system_parse_complete += update_symbols;
85
else update_symbols();
88
SourceFile get_current_sourcefile() {
89
string document_path = parent.active_filename();
90
Program program = Program.find_containing(document_path);
91
SourceFile? sf = program.find_source(document_path);
93
Gedit.Document doc = parent.window.get_active_document();
94
program.update(document_path, buffer_contents(doc));
95
sf = program.find_source(document_path);
102
void update_symbols() {
103
if (!parent.active_document_is_valid_vala_file()) {
108
string text = find_entry.get_text().substring(0);
109
Expression id = new Id(text);
110
SourceFile sf = get_current_sourcefile();
111
SymbolSet symbol_set = sf.resolve_all_locals(id, 0);
113
weak Vala.HashSet<Symbol> symbols = symbol_set.get_symbols();
114
string[] symbol_names;
115
if (symbols != null) {
116
// Insert symbol names into the list in a sorted order
117
symbol_names = new string[symbols.size];
120
foreach (Symbol symbol in symbols)
121
symbol_names[i++] = symbol.name;
123
qsort(symbol_names, symbols.size, sizeof(string), (GLib.CompareFunc) compare_string);
124
} else symbol_names = new string[0];
126
list.collate(symbol_names);
129
void jump_to_symbol(string symbol_name) {
130
if (!parent.active_document_is_valid_vala_file())
133
Expression id = new Id(symbol_name);
134
SourceFile sf = get_current_sourcefile();
135
Symbol? symbol = sf.resolve_local(id, 0);
140
parent.jump(symbol.source.filename,
141
new CharRange(symbol.start, symbol.start + (int) symbol.name.length));
144
void on_entry_activated() {
145
if (list.size() <= 0)
147
list.select_first_cell();
151
void on_list_activated() {
152
jump_to_symbol(list.get_selected_item());
155
public void on_document_saved() {
160
public void set_parent_instance_focus() {
161
Gedit.Panel panel = parent.window.get_side_panel();
164
panel.activate_item(symbol_vbox);
165
parent.window.set_focus(find_entry);