3
* Copyright (C) 2008-2010 Nicolas Joseph
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
* Nicolas Joseph <nicolas.joseph@valaide.org>
24
public class Completion : Plugin, Object
27
private SourceBuffer buffer;
28
private Gtk.ActionGroup action_group = null;
30
const Gtk.ActionEntry[] entries = {
31
{ "search-goto-definition", null, "Go to Definition", "<ctrl>D",
32
"Goto the definition of the current symbol", on_goto_definition },
33
{ "search-autocomplete", null, "_AutoComplete", "<ctrl>space",
34
"Display method or symbol information", on_autocomplete }
39
<menubar name="menubar">
40
<menu action="search">
41
<placeholder name="search-ops-3">
42
<menuitem action="search-goto-definition"/>
44
<menuitem action="search-autocomplete"/>
51
* @see Valide.Plugin.path
53
public string path { get; construct set; }
55
* @see Valide.Plugin.window
57
public Window window { get; construct set; }
59
private void get_buffer_info (SourceBuffer buffer, out int pos,
64
contents = buffer.get_buffer_contents ();
65
this.buffer.get_iter_at_mark (out iter, this.buffer.get_insert ());
66
pos = iter.get_offset ();
69
private void jump_to_symbol_definition ()
73
Valencia.ScanInfo info;
75
this.get_buffer_info (this.buffer, out pos, out source);
76
info = Valencia.ScanInfo.get_scan_info (this.buffer, false);
77
if (info != null && info.inner () != null)
80
Valencia.SourceFile sf;
81
Valencia.Program program;
83
program = Valencia.Program.find_containing (this.buffer.path);
84
sf = program.find_source (this.buffer.path);
85
sym = sf.resolve (info.inner (), pos, false);
92
document = this.window.documents.create (sym.source.filename);
93
document.select_offsets (sym.start, sym.start + sym.name_length ());
103
private void on_goto_definition ()
107
SourceView source_view;
109
document = this.window.documents.current;
110
source_view = document.text_view;
111
filename = source_view.buffer.path;
113
if (filename != null && Valencia.Program.is_vala (filename))
115
Valencia.Program program;
117
program = Valencia.Program.find_containing (filename, true);
118
this.buffer = document.buffer;
119
if (program.is_parsing ())
121
program.system_parse_complete.connect (this.jump_to_symbol_definition);
125
this.jump_to_symbol_definition ();
130
private void on_autocomplete ()
132
Gtk.bindings_activate (this.window.get_focus (), Gdk.KeySyms.space,
133
Gdk.ModifierType.CONTROL_MASK);
136
private void setup_ui (DocumentManager sender, Document? document)
140
if (this.action_group == null)
142
Gtk.UIManager ui_manager;
144
ui_manager = this.window.ui_manager;
145
this.action_group = new Gtk.ActionGroup ("completion");
146
this.action_group.add_actions (this.entries, this);
147
ui_manager.insert_action_group (this.action_group, 0);
150
this.ui_id = ui_manager.add_ui_from_string (ui, -1);
158
if (sender.current != null)
162
this.action_group.get_action ("search-goto-definition").sensitive = active;
163
this.action_group.get_action ("search-autocomplete").sensitive = active;
166
private void on_tab_added (DocumentManager sender, Document document)
171
Gtk.SourceView source_view;
172
Gtk.SourceCompletion completion;
174
filename = document.path;
175
source_view = document.split_view.active_view;
176
completion = source_view.get_completion ();
177
completion.show_headers = false;
178
completion.remember_info_visibility = true;
179
completion.add_provider ((Gtk.SourceCompletionProvider)new ValenciaProvider (document.buffer));
181
this.setup_ui (this.window.documents, null);
191
this.window.documents.tab_added.connect (this.on_tab_added);
192
this.window.documents.tab_removed.connect (this.setup_ui);
193
this.setup_ui (this.window.documents, null);
198
this.window.ui_manager.remove_ui (this.ui_id);
202
public Type register_plugin (TypeModule module)
204
return typeof (Completion);