src/Builder4/ValaCompileResults.bjs
[app.Builder.js] / src / Builder4 / ValaCompileResults.vala
1 static Xcls_ValaCompileResults  _ValaCompileResults;
2
3 public class Xcls_ValaCompileResults : Object
4 {
5     public Gtk.Popover el;
6     private Xcls_ValaCompileResults  _this;
7
8     public static Xcls_ValaCompileResults singleton()
9     {
10         if (_ValaCompileResults == null) {
11             _ValaCompileResults= new Xcls_ValaCompileResults();
12         }
13         return _ValaCompileResults;
14     }
15     public Xcls_compile_view compile_view;
16     public Xcls_compile_tree compile_tree;
17     public Xcls_compile_result_store compile_result_store;
18     public Xcls_renderer renderer;
19
20         // my vars (def)
21     public Xcls_MainWindow window;
22     public bool active;
23     public JsRender.JsRender? file;
24     public Json.Object notices;
25
26     // ctor
27     public Xcls_ValaCompileResults()
28     {
29         _this = this;
30         this.el = new Gtk.Popover( null );
31
32         // my vars (dec)
33         this.active = false;
34
35         // set gobject values
36         this.el.width_request = 900;
37         this.el.height_request = 800;
38         this.el.modal = true;
39         this.el.position = Gtk.PositionType.TOP;
40         var child_0 = new Xcls_compile_view( _this );
41         child_0.ref();
42         this.el.add (  child_0.el  );
43     }
44
45     // user defined functions
46     public void show (Json.Object tree, Gtk.Widget onbtn) {
47     
48             
49             this.file = null;
50             this.notices = tree;
51            
52              //print("looking for %s\n", id);
53             // loop through parent childnre
54               
55             
56             var store = this.compile_result_store.el;    
57             
58             store.clear();
59          
60             
61             tree.foreach_member((obj, file, node) => {
62                 // id line "display text", file
63                 
64                 var title = GLib.Path.get_basename(GLib.Path.get_dirname( file)) + "/" +  GLib.Path.get_basename( file) ;
65                 Gtk.TreeIter iter;
66                 print("Add file %s", title);
67                 store.append(out iter, null);
68                 var lines = tree.get_object_member(file);
69                 title += " (" + lines.get_size().to_string() + ")";
70                 store.set(iter, 0, file, 1, 0, 2, title, 3, file,-1);
71                 
72                 lines.foreach_member((obja, line, nodea) => {
73                     var msg  = "";
74                     var ar = lines.get_array_member(line);
75                     for (var i = 0 ; i < ar.get_length(); i++) {
76                             msg += (msg.length > 0) ? "\n" : "";
77                             msg += ar.get_string_element(i);
78                 }
79                     Gtk.TreeIter citer;  
80                     print("Add line %s", line);
81                     store.append(out citer, iter);
82                     store.set(citer, 
83                         0, file + ":" + line, 
84                         1, int.parse(line), 
85                         2, GLib.Markup.escape_text(line + ": " + msg), 
86                         3, file,-1);
87                 
88                 });
89                 
90                 
91             
92             });
93             
94         int w,h;
95         this.window.el.get_size(out w, out h);
96         
97         // left tree = 250, editor area = 500?
98         
99         var new_w = int.min(250, w-100);
100         if (new_w > (w-100)) {
101             new_w = w-100;
102         }
103         this.el.set_size_request( int.max(100, new_w), int.max(100, h-120));
104     
105         
106     
107         if (this.el.relative_to == null) {
108             this.el.set_relative_to(onbtn);
109         }
110         this.el.show_all();
111        
112         while(Gtk.events_pending()) { 
113                 Gtk.main_iteration();
114         }       
115      //   this.hpane.el.set_position( 0);
116     }
117     public class Xcls_compile_view : Object
118     {
119         public Gtk.Box el;
120         private Xcls_ValaCompileResults  _this;
121
122
123             // my vars (def)
124
125         // ctor
126         public Xcls_compile_view(Xcls_ValaCompileResults _owner )
127         {
128             _this = _owner;
129             _this.compile_view = this;
130             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
131
132             // my vars (dec)
133
134             // set gobject values
135             this.el.homogeneous = false;
136             var child_0 = new Xcls_ScrolledWindow3( _this );
137             child_0.ref();
138             this.el.pack_end (  child_0.el , true,true,0 );
139         }
140
141         // user defined functions
142     }
143     public class Xcls_ScrolledWindow3 : Object
144     {
145         public Gtk.ScrolledWindow el;
146         private Xcls_ValaCompileResults  _this;
147
148
149             // my vars (def)
150
151         // ctor
152         public Xcls_ScrolledWindow3(Xcls_ValaCompileResults _owner )
153         {
154             _this = _owner;
155             this.el = new Gtk.ScrolledWindow( null, null );
156
157             // my vars (dec)
158
159             // set gobject values
160             var child_0 = new Xcls_compile_tree( _this );
161             child_0.ref();
162             this.el.add (  child_0.el  );
163
164             // init method
165
166             {
167              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
168              
169             
170             }
171         }
172
173         // user defined functions
174     }
175     public class Xcls_compile_tree : Object
176     {
177         public Gtk.TreeView el;
178         private Xcls_ValaCompileResults  _this;
179
180
181             // my vars (def)
182
183         // ctor
184         public Xcls_compile_tree(Xcls_ValaCompileResults _owner )
185         {
186             _this = _owner;
187             _this.compile_tree = this;
188             this.el = new Gtk.TreeView();
189
190             // my vars (dec)
191
192             // set gobject values
193             var child_0 = new Xcls_compile_result_store( _this );
194             child_0.ref();
195             this.el.set_model (  child_0.el  );
196             var child_1 = new Xcls_column( _this );
197             child_1.ref();
198             this.el.append_column (  child_1.el  );
199
200             // init method
201
202             {
203              var description = new Pango.FontDescription();
204                 description.set_size(8000);
205                 this.el.override_font(description);
206             
207             }
208
209             //listeners
210             this.el.button_press_event.connect( ( ev)  => {
211              
212                 Gtk.TreeViewColumn col;
213                 int cell_x;
214                 int cell_y;
215                 Gtk.TreePath path;
216                 if (!this.el.get_path_at_pos((int)ev.x, (int) ev.y, out path, out col, out cell_x, out cell_y )) {
217                     print("nothing selected on click");
218                     
219                     return false; //not on a element.
220                 }
221                 
222                  
223                  // right click.
224                  if (ev.type != Gdk.EventType.2BUTTON_PRESS  || ev.button != 1  ) {    
225                     // show popup!.   
226                         
227                      
228                     return false;
229                 }
230                 Gtk.TreeIter iter;
231                  var mod = _this.compile_result_store.el;
232                 mod.get_iter (out iter, path);
233                 
234                   
235                 
236                 // var val = "";
237                 GLib.Value value;
238                 _this.compile_result_store.el.get_value(iter, 3, out value);
239                 var fname = (string)value;
240                 //GLib.Value lvalue;
241                 //_this.compile_result_store.el.get_value(iter, 1, out lvalue);
242                 //var line = (int) lvalue;
243                 
244                 
245                var  bjsf = "";
246                 try {             
247                    var  regex = new Regex("\\.vala$");
248                 
249                  
250                     bjsf = regex.replace(fname,fname.length , 0 , ".bjs");
251                  } catch (GLib.RegexError e) {
252                     return false;
253                 }   
254                 var p = _this.window.project;
255                     
256                     
257                     
258                 var jsr = p.getByPath(bjsf);
259                 if (jsr != null) {
260                     _this.window.windowstate.fileViewOpen(jsr);
261                     
262                     return false;
263                 
264                 }
265                 
266                 var pf = JsRender.JsRender.factory("PlainFile", p, fname);
267                 _this.window.windowstate.fileViewOpen(pf);
268                 
269                 // try hiding the left nav..
270              
271                 return false;
272                 
273               });
274         }
275
276         // user defined functions
277     }
278     public class Xcls_compile_result_store : Object
279     {
280         public Gtk.TreeStore el;
281         private Xcls_ValaCompileResults  _this;
282
283
284             // my vars (def)
285
286         // ctor
287         public Xcls_compile_result_store(Xcls_ValaCompileResults _owner )
288         {
289             _this = _owner;
290             _this.compile_result_store = this;
291             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
292
293             // my vars (dec)
294
295             // set gobject values
296         }
297
298         // user defined functions
299     }
300
301     public class Xcls_column : Object
302     {
303         public Gtk.TreeViewColumn el;
304         private Xcls_ValaCompileResults  _this;
305
306
307             // my vars (def)
308
309         // ctor
310         public Xcls_column(Xcls_ValaCompileResults _owner )
311         {
312             _this = _owner;
313             this.el = new Gtk.TreeViewColumn();
314
315             // my vars (dec)
316
317             // set gobject values
318             this.el.title = "Compile output";
319             var child_0 = new Xcls_renderer( _this );
320             child_0.ref();
321             this.el.pack_start (  child_0.el , true );
322
323             // init method
324
325             {
326               this.el.add_attribute(_this.renderer.el , "markup", 2 );
327              
328             }
329         }
330
331         // user defined functions
332     }
333     public class Xcls_renderer : Object
334     {
335         public Gtk.CellRendererText el;
336         private Xcls_ValaCompileResults  _this;
337
338
339             // my vars (def)
340
341         // ctor
342         public Xcls_renderer(Xcls_ValaCompileResults _owner )
343         {
344             _this = _owner;
345             _this.renderer = this;
346             this.el = new Gtk.CellRendererText();
347
348             // my vars (dec)
349
350             // set gobject values
351         }
352
353         // user defined functions
354     }
355
356
357
358
359
360 }