2121public class Scratch.Plugins.Completion : Peas .ExtensionBase , Peas .Activatable {
2222
2323 public const int MAX_TOKENS = 1000000 ;
24+ public const uint INTERACTIVE_DELAY = 500 ;
25+
2426 private const uint [] ACTIVATE_KEYS = {
2527 Gdk . Key . Return ,
2628 Gdk . Key . KP_Enter ,
@@ -36,8 +38,10 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
3638 public Object object { owned get ; construct; }
3739
3840 private List<Gtk . SourceView > text_view_list = new List<Gtk . SourceView > ();
39- private Euclide . Completion . Parser parser {get ; private set ;}
40- private Gtk . SourceView ? current_view {get ; private set ;}
41+ private Euclide . Completion . Parser parser;
42+ private Gtk . SourceView ? current_view;
43+ private Gtk . SourceCompletion ? current_completion;
44+ private Scratch . Plugins . CompletionProvider current_provider;
4145 private Scratch . Services . Document current_document {get ; private set ;}
4246 private MainWindow main_window;
4347 private Scratch . Services . Interface plugins;
@@ -76,29 +80,30 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
7680
7781 current_document = doc;
7882 current_view = doc. source_view;
83+ current_completion = current_view. completion;
7984 current_view. buffer. insert_text. connect (on_insert_text);
8085 current_view. buffer. delete_range. connect (on_delete_range);
8186
82- current_view . completion . show. connect (() = > {
87+ current_completion . show. connect (() = > {
8388 completion_in_progress = true ;
8489 });
8590
86- current_view . completion . hide. connect (() = > {
91+ current_completion . hide. connect (() = > {
8792 completion_in_progress = false ;
8893 });
8994
9095 if (text_view_list. find (current_view) == null ) {
9196 text_view_list. append (current_view);
9297 }
9398
94- var comp_provider = new Scratch .Plugins .CompletionProvider (parser, current_view);
95- comp_provider. priority = 1 ;
96- comp_provider. name = provider_name_from_document (doc);
99+ current_provider = new Scratch .Plugins .CompletionProvider (parser, doc);
97100
98101 try {
99- current_view. completion. add_provider (comp_provider);
100- current_view. completion. show_headers = true ;
101- current_view. completion. show_icons = true ;
102+ current_completion. add_provider (current_provider);
103+ current_completion. show_headers = true ;
104+ current_completion. show_icons = true ;
105+ current_completion. accelerators = 9 ;
106+ current_completion. select_on_show = true ;
102107 } catch (Error e) {
103108 critical (
104109 " Could not add completion provider to %s. %s\n " ,
@@ -180,10 +185,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
180185 return Source . REMOVE ;
181186 });
182187 }
183- }
184188
185- private string provider_name_from_document (Scratch .Services .Document doc ) {
186- return _(" %s - Word Completion" ). printf (doc. get_basename ());
187189 }
188190
189191 private void cleanup () {
@@ -195,13 +197,10 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
195197 current_view. buffer. delete_range. disconnect (on_delete_range);
196198 // Disconnect show completion??
197199
198- current_view . completion . get_providers (). foreach ((p) = > {
200+ current_completion . get_providers (). foreach ((p) = > {
199201 try {
200202 /* Only remove provider added by this plug in */
201- if (p. get_name () == provider_name_from_document (current_document)) {
202- debug (" removing provider %s " , p != null ? p. get_name () : " null" );
203- current_view. completion. remove_provider (p);
204- }
203+ current_completion. remove_provider (current_provider);
205204 } catch (Error e) {
206205 warning (e. message);
207206 }
0 commit comments