src/Builder4/GtkView.bjs
[app.Builder.js] / src / Builder4 / GtkView.vala
1 static Xcls_GtkView  _GtkView;
2
3 public class Xcls_GtkView : Object 
4 {
5     public Gtk.VPaned el;
6     private Xcls_GtkView  _this;
7
8     public static Xcls_GtkView singleton()
9     {
10         if (_GtkView == null) {
11             _GtkView= new Xcls_GtkView();
12         }
13         return _GtkView;
14     }
15     public Xcls_view_layout view_layout;
16     public Xcls_container container;
17     public Xcls_compile_view compile_view;
18     public Xcls_compile_result_store compile_result_store;
19     public Xcls_renderer renderer;
20
21         // my vars (def)
22     public Gtk.Widget lastObj;
23     public int width;
24     public Xcls_MainWindow main_window;
25     public JsRender.JsRender file;
26     public int height;
27
28     // ctor 
29     public Xcls_GtkView()
30     {
31         _this = this;
32         this.el = new Gtk.VPaned();
33
34         // my vars (dec)
35         this.lastObj = null;
36         this.width = 0;
37         this.file = null;
38         this.height = 0;
39
40         // set gobject values
41         var child_0 = new Xcls_ScrolledWindow2( _this );
42         child_0.ref();
43         this.el.pack1 (  child_0.el , true,true );
44         var child_1 = new Xcls_compile_view( _this );
45         child_1.ref();
46         this.el.pack2 (  child_1.el , true,true );
47
48         // listeners 
49         this.el.size_allocate.connect( (aloc) => {
50         
51             this.width = aloc.width;
52             this.height =aloc.height;
53             });
54     }
55
56     // user defined functions 
57     public void createThumb () {
58         
59         
60         if (this.file == null) {
61             return;
62         }
63         var filename = this.file.getIconFileName(false);
64         
65         var  win = this.el.get_parent_window();
66         var width = win.get_width();
67         var height = win.get_height();
68     
69         Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
70     
71         screenshot.save(filename,"png");
72         return;
73         
74         
75         
76         
77         
78          
79         
80         // should we hold until it's printed...
81         
82           
83     
84         
85         
86     
87     
88         
89          
90     }
91     public void loadFile (JsRender.JsRender file) 
92     {
93             file.compile_notice.connect(this.compileNotice);
94            // this.el.set_position((int)(this.el.max_position * 0.7));
95             this.el.set_position(this.el.max_position );
96             this.file = null;
97             
98             if (file.tree == null) {
99                 return;
100             }
101             this.file = file;
102             if (this.lastObj != null) {
103                 this.container.el.remove(this.lastObj);
104             }
105             
106             // hide the compile view at present..
107               
108             
109             var w = this.width;
110             var h = this.height;
111             
112             print("ALLOC SET SIZES %d, %d\n", w,h); 
113             
114             // set the container size min to 500/500 or 20 px less than max..
115             w = int.max (w-20, 500);
116             h = int.max (h-20, 500); 
117             
118             print("SET SIZES %d, %d\n", w,h);       
119             _this.container.el.set_size_request(w,h);
120             
121             _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
122             var rgba = Gdk.RGBA ();
123             rgba.parse ("#ccc");
124             _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
125             
126             
127         var x = new JsRender.NodeToGtk(file.tree);
128             var obj = x.munge() as Gtk.Widget;
129             this.lastObj = null;
130         if (obj == null) {
131                 return;
132         }
133         this.lastObj = obj;
134             
135             this.container.el.add(obj);
136             obj.show_all();
137             
138              
139             
140     }
141     public void compileNotice ( string  type,   string file,   int line,   string  message) {
142         // if type = "START"... then we reset the tree?
143         // the issue is that the compiler is continually going..
144         // so editing a file etc.. may change things.?
145         // probably not an issue.
146         if (type =="START") {
147             // reset the tree;
148             return;
149         }
150         var cs = _this.compile_result_store;
151         
152         var top = 0;
153         var title = "";
154         switch(type) {
155             case "ERR":
156                 title = "Errors";
157                 top =0;
158                 break;
159             
160             case "WARN":
161                 title = "Warnings";
162                 top =1;
163                 break;
164                 
165             case "DEPR":
166                 title = "Depricated";
167                 top=2;
168                 break;
169             
170             default:
171                 title = type;
172                 top =3;
173                 break;
174         }
175                 
176         
177          var tv = cs.nodeFindOrCreate(null, top.to_string(), title);
178          tv = cs.nodeFindOrCreate(tv, "%d:%s".printf(top, file), file);
179           cs.nodeAppendOrCreate(tv, "%d:%s:%d".printf(top, file,line), file,line, message);
180         
181     }
182     public class Xcls_ScrolledWindow2 : Object 
183     {
184         public Gtk.ScrolledWindow el;
185         private Xcls_GtkView  _this;
186
187
188             // my vars (def)
189
190         // ctor 
191         public Xcls_ScrolledWindow2(Xcls_GtkView _owner )
192         {
193             _this = _owner;
194             this.el = new Gtk.ScrolledWindow( null, null );
195
196             // my vars (dec)
197
198             // set gobject values
199             var child_0 = new Xcls_view_layout( _this );
200             child_0.ref();
201             this.el.add (  child_0.el  );
202         }
203
204         // user defined functions 
205     }
206     public class Xcls_view_layout : Object 
207     {
208         public Gtk.Layout el;
209         private Xcls_GtkView  _this;
210
211
212             // my vars (def)
213
214         // ctor 
215         public Xcls_view_layout(Xcls_GtkView _owner )
216         {
217             _this = _owner;
218             _this.view_layout = this;
219             this.el = new Gtk.Layout( null, null );
220
221             // my vars (dec)
222
223             // set gobject values
224             var child_0 = new Xcls_container( _this );
225             child_0.ref();
226             this.el.put (  child_0.el , 10,10 );
227         }
228
229         // user defined functions 
230     }
231     public class Xcls_container : Object 
232     {
233         public Gtk.HBox el;
234         private Xcls_GtkView  _this;
235
236
237             // my vars (def)
238
239         // ctor 
240         public Xcls_container(Xcls_GtkView _owner )
241         {
242             _this = _owner;
243             _this.container = this;
244             this.el = new Gtk.HBox( true, 0 );
245
246             // my vars (dec)
247
248             // set gobject values
249         }
250
251         // user defined functions 
252     }
253     public class Xcls_compile_view : Object 
254     {
255         public Gtk.VBox el;
256         private Xcls_GtkView  _this;
257
258
259             // my vars (def)
260
261         // ctor 
262         public Xcls_compile_view(Xcls_GtkView _owner )
263         {
264             _this = _owner;
265             _this.compile_view = this;
266             this.el = new Gtk.VBox( false, 0 );
267
268             // my vars (dec)
269
270             // set gobject values
271             var child_0 = new Xcls_HBox6( _this );
272             child_0.ref();
273             this.el.pack_start (  child_0.el , false,false,0 );
274             var child_1 = new Xcls_HBox8( _this );
275             child_1.ref();
276             this.el.pack_start (  child_1.el , true,true,0 );
277         }
278
279         // user defined functions 
280     }
281     public class Xcls_HBox6 : Object 
282     {
283         public Gtk.HBox el;
284         private Xcls_GtkView  _this;
285
286
287             // my vars (def)
288
289         // ctor 
290         public Xcls_HBox6(Xcls_GtkView _owner )
291         {
292             _this = _owner;
293             this.el = new Gtk.HBox( true, 0 );
294
295             // my vars (dec)
296
297             // set gobject values
298             var child_0 = new Xcls_Button7( _this );
299             child_0.ref();
300             this.el.pack_start (  child_0.el , true,true,0 );
301         }
302
303         // user defined functions 
304     }
305     public class Xcls_Button7 : Object 
306     {
307         public Gtk.Button el;
308         private Xcls_GtkView  _this;
309
310
311             // my vars (def)
312
313         // ctor 
314         public Xcls_Button7(Xcls_GtkView _owner )
315         {
316             _this = _owner;
317             this.el = new Gtk.Button();
318
319             // my vars (dec)
320
321             // set gobject values
322             this.el.label = "Full Compile";
323         }
324
325         // user defined functions 
326     }
327     public class Xcls_HBox8 : Object 
328     {
329         public Gtk.HBox el;
330         private Xcls_GtkView  _this;
331
332
333             // my vars (def)
334
335         // ctor 
336         public Xcls_HBox8(Xcls_GtkView _owner )
337         {
338             _this = _owner;
339             this.el = new Gtk.HBox( true, 0 );
340
341             // my vars (dec)
342
343             // set gobject values
344             var child_0 = new Xcls_TreeView9( _this );
345             child_0.ref();
346             this.el.add (  child_0.el  );
347             var child_1 = new Xcls_ScrolledWindow13( _this );
348             child_1.ref();
349             this.el.pack_start (  child_1.el , true,true,0 );
350         }
351
352         // user defined functions 
353     }
354     public class Xcls_TreeView9 : Object 
355     {
356         public Gtk.TreeView el;
357         private Xcls_GtkView  _this;
358
359
360             // my vars (def)
361
362         // ctor 
363         public Xcls_TreeView9(Xcls_GtkView _owner )
364         {
365             _this = _owner;
366             this.el = new Gtk.TreeView();
367
368             // my vars (dec)
369
370             // set gobject values
371             var child_0 = new Xcls_compile_result_store( _this );
372             child_0.ref();
373             this.el.set_model (  child_0.el  );
374             var child_1 = new Xcls_column( _this );
375             child_1.ref();
376             this.el.append_column (  child_1.el  );
377         }
378
379         // user defined functions 
380     }
381     public class Xcls_compile_result_store : Object 
382     {
383         public Gtk.TreeStore el;
384         private Xcls_GtkView  _this;
385
386
387             // my vars (def)
388
389         // ctor 
390         public Xcls_compile_result_store(Xcls_GtkView _owner )
391         {
392             _this = _owner;
393             _this.compile_result_store = this;
394             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
395
396             // my vars (dec)
397
398             // set gobject values
399         }
400
401         // user defined functions 
402         public void nodeAppendOrCreate (Gtk.TreePath  par, string id, string file, int line, string message) {
403         
404             Gtk.TreeIter piter;
405              
406             this.el.get_iter(out piter, par);
407              
408             // loop through parent childnre
409             Gtk.TreeIter iter; 
410             var loop =  par == null ? 
411                 this.el.iter_children(out iter, null) :
412                  this.el.iter_children(out iter,  piter);
413             
414             while (loop) {
415                 GLib.Value val;
416                 this.el.get_value(iter, 0, out val);
417                 var sval = (string)val;
418                 if (sval == id) {
419                     GLib.Value mval;
420                     this.el.get_value(iter, 2, out mval);
421                     var smval = (string)mval;
422                     mval.set_string(smval + "\n" + message); //markup?
423                 
424                     return;
425                 }
426                 loop = this.el.iter_next(ref iter);    
427             }
428             
429             // create the node...
430             if (par == null) {
431                 this.el.append(out iter, null);
432             } else {
433                 this.el.append(out iter, piter);
434             }
435             this.el.set(iter, 0, id, 1, line,2, message, 3, file,-1);
436                 
437             return ;
438         
439         }
440         public Gtk.TreePath nodeFindOrCreate (Gtk.TreePath? par, string id, string title) {
441         
442         
443             print("looking for %s\n", id);
444             // loop through parent childnre
445             Gtk.TreeIter piter   ;
446             Gtk.TreeIter iter;
447             var loop = true;
448             if (par != null) {
449                 this.el.get_iter(out piter, par);
450                 loop = this.el.iter_children(out iter,  piter);
451             } else {
452                 loop = this.el.iter_children(out iter, null) ;
453             }
454                  
455                  
456             while (loop) {
457                 GLib.Value val;
458                 this.el.get_value(iter, 0, out val);
459                 var sval = (string)val;
460                 print("got node %s", sval);
461                 if (sval == id) {
462                     return this.el.get_path(iter);
463                 }
464                 loop = this.el.iter_next(ref iter);    
465             }
466             // create the node...
467              if (par == null) {
468                 this.el.append(out iter, null);
469             } else {
470               this.el.get_iter(out piter, par);
471                 this.el.append(out iter, piter);
472             }
473             print("add iter %s / %s", id, title);
474             this.el.set(iter, 0, id, 1, 0, 2, title, 3, "",-1);
475                
476             return   this.el.get_path(iter);
477         
478         }
479     }
480     public class Xcls_column : Object 
481     {
482         public Gtk.TreeViewColumn el;
483         private Xcls_GtkView  _this;
484
485
486             // my vars (def)
487
488         // ctor 
489         public Xcls_column(Xcls_GtkView _owner )
490         {
491             _this = _owner;
492             this.el = new Gtk.TreeViewColumn();
493
494             // my vars (dec)
495
496             // set gobject values
497             this.el.title = "Compile output";
498             var child_0 = new Xcls_renderer( _this );
499             child_0.ref();
500             this.el.pack_start (  child_0.el , true );
501
502             // init method 
503
504             {
505               this.el.add_attribute(_this.renderer.el , "markup", 2 );
506              
507             }
508         }
509
510         // user defined functions 
511     }
512     public class Xcls_renderer : Object 
513     {
514         public Gtk.CellRendererText el;
515         private Xcls_GtkView  _this;
516
517
518             // my vars (def)
519
520         // ctor 
521         public Xcls_renderer(Xcls_GtkView _owner )
522         {
523             _this = _owner;
524             _this.renderer = this;
525             this.el = new Gtk.CellRendererText();
526
527             // my vars (dec)
528
529             // set gobject values
530         }
531
532         // user defined functions 
533     }
534     public class Xcls_ScrolledWindow13 : Object 
535     {
536         public Gtk.ScrolledWindow el;
537         private Xcls_GtkView  _this;
538
539
540             // my vars (def)
541
542         // ctor 
543         public Xcls_ScrolledWindow13(Xcls_GtkView _owner )
544         {
545             _this = _owner;
546             this.el = new Gtk.ScrolledWindow( null, null );
547
548             // my vars (dec)
549
550             // set gobject values
551             var child_0 = new Xcls_View14( _this );
552             child_0.ref();
553             this.el.add (  child_0.el  );
554         }
555
556         // user defined functions 
557     }
558     public class Xcls_View14 : Object 
559     {
560         public Gtk.SourceView el;
561         private Xcls_GtkView  _this;
562
563
564             // my vars (def)
565
566         // ctor 
567         public Xcls_View14(Xcls_GtkView _owner )
568         {
569             _this = _owner;
570             this.el = new Gtk.SourceView();
571
572             // my vars (dec)
573
574             // set gobject values
575             this.el.editable = false;
576             this.el.show_line_marks = true;
577             this.el.show_line_numbers = true;
578         }
579
580         // user defined functions 
581     }
582 }