src/Palete/CompletionProvider.vala
[app.Builder.js] / src / Palete / CompletionProvider.vala
1  
2
3 namespace Palete {
4
5     class CompletionProvider : Gtk.SourceCompletionProvider, Object
6     {
7                 
8                  public List<Gtk.SourceCompletionItem> proposals;
9                 //public List<Gtk.SourceCompletionItem> filtered_proposals;
10
11                 construct
12                 {
13                    
14                         this.proposals = new List<Gtk.SourceCompletionItem> ();
15                 }
16
17                 public string get_name ()
18                 {
19                   return  "test";
20                 }
21
22                 public int get_priority ()
23                 {
24                   return 1;
25                 }
26
27                 public bool match (Gtk.SourceCompletionContext context)
28                 {
29                 
30                         return true;
31                 }
32
33                 public void populate (Gtk.SourceCompletionContext context)
34                 {
35                         var buffer = context.completion.view.buffer;
36                         var  mark = buffer.get_insert ();
37                         TextIter end;
38
39                         buffer.get_iter_at_mark (out end, mark);
40                         var endpos = end;
41                         
42                         var searchpos = endpos;
43                         
44                         searchpos.backward_find_char(is_space, null);
45                         searchpos.forward_char();
46                         var search = endpos.get_text(searchpos);
47                         
48                         
49
50                         var filtered_proposals = new List<Gtk.SourceCompletionItem> ();
51                         foreach(var i in this.proposals) {
52                                 //if(i.text.contains(search)) // starts??
53                                 //      this.filtered_proposals.prepend (new Gtk.SourceCompletionItem (i.label, i.text, i.icon, i.info));
54                                 //}
55                         }
56                         context.add_proposals (this, filtered_proposals, true);
57                 }
58
59                 public bool activate_proposal (Gtk.SourceCompletionProposal proposal, Gtk.TextIter iter)
60                 {
61                         var istart = iter;
62                         istart.backward_find_char(is_space, null);
63                         istart.forward_char();
64
65                 //    var search = iter.get_text(istart);           
66                 
67                         var buffer = iter.get_buffer();
68                         buffer.delete(ref istart, ref iter);
69                         buffer.insert(ref istart, proposal.get_text(), -1);
70                 
71                         return true;
72                 }
73
74                 public Gtk.SourceCompletionActivation get_activation ()
75                 {
76                         //if(SettingsManager.Get_Setting("complete_auto") == "true"){
77                                 return Gtk.SourceCompletionActivation.INTERACTIVE | Gtk.SourceCompletionActivation.USER_REQUESTED;
78                         //} else {
79                         //      return Gtk.SourceCompletionActivation.USER_REQUESTED;
80                         //}
81                 }
82
83                 public int get_interactive_delay ()
84                 {
85                         return -1;
86                 }
87
88                 public bool get_start_iter (Gtk.SourceCompletionContext context, Gtk.SourceCompletionProposal proposal, Gtk.TextIter iter)
89                 {
90                         return false;
91                 }
92
93                 public void update_info (Gtk.SourceCompletionProposal proposal, Gtk.SourceCompletionInfo info)
94                 {
95
96                 }
97
98                 private bool is_space(unichar space){
99                         return space.isspace() || space.to_string() == "";
100                 }
101                 
102                 private bool is_forward_space(unichar space){
103                         return !(
104                                 space.to_string() == " "
105                                         ||
106                                 space.to_string() == ""
107                                 ||
108                                 space.to_string() == "\n")
109                                 ||
110                                 space.to_string() == ")")
111                                 ||
112                                 space.to_string() == "("
113                                 
114                         );
115                 }
116 }
117
118
119 }
120 Status API Training Shop Blog About
121 © 2015 GitHub, Inc. Terms Privacy Security Contact