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         print("err %s / %s:%d / %s\n", type,file,line,message);
147         var cs = _this.compile_result_store;    
148         if (type =="START") {
149             // reset the tree;
150             cs.el.clear();   
151             cs.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);   
152             return;
153         }
154     
155         
156         var top = 0;
157         var title = "";
158         switch(type) {
159             case "ERR":
160                 title = "Errors";
161                 top =0;
162                 break;
163             
164             case "WARN":
165                 title = "Warnings";
166                 top =1;
167                 break;
168                 
169             case "DEPR":
170                 title = "Depricated";
171                 top=2;
172                 break;
173             
174             default:
175                 title = type;
176                 top =3;
177                 break;
178         }
179                 
180         
181          var tv = cs.nodeFindOrCreate(null, top.to_string(), title);
182          tv = cs.nodeFindOrCreate(tv, "%d:%s".printf(top, file), GLib.Path.get_basename( file));
183           cs.nodeAppendOrCreate(tv, "%d:%s:%d".printf(top, file,line), file,line, message);
184         
185     }
186     public class Xcls_ScrolledWindow2 : Object 
187     {
188         public Gtk.ScrolledWindow el;
189         private Xcls_GtkView  _this;
190
191
192             // my vars (def)
193
194         // ctor 
195         public Xcls_ScrolledWindow2(Xcls_GtkView _owner )
196         {
197             _this = _owner;
198             this.el = new Gtk.ScrolledWindow( null, null );
199
200             // my vars (dec)
201
202             // set gobject values
203             var child_0 = new Xcls_view_layout( _this );
204             child_0.ref();
205             this.el.add (  child_0.el  );
206         }
207
208         // user defined functions 
209     }
210     public class Xcls_view_layout : Object 
211     {
212         public Gtk.Layout el;
213         private Xcls_GtkView  _this;
214
215
216             // my vars (def)
217
218         // ctor 
219         public Xcls_view_layout(Xcls_GtkView _owner )
220         {
221             _this = _owner;
222             _this.view_layout = this;
223             this.el = new Gtk.Layout( null, null );
224
225             // my vars (dec)
226
227             // set gobject values
228             var child_0 = new Xcls_container( _this );
229             child_0.ref();
230             this.el.put (  child_0.el , 10,10 );
231         }
232
233         // user defined functions 
234     }
235     public class Xcls_container : Object 
236     {
237         public Gtk.HBox el;
238         private Xcls_GtkView  _this;
239
240
241             // my vars (def)
242
243         // ctor 
244         public Xcls_container(Xcls_GtkView _owner )
245         {
246             _this = _owner;
247             _this.container = this;
248             this.el = new Gtk.HBox( true, 0 );
249
250             // my vars (dec)
251
252             // set gobject values
253         }
254
255         // user defined functions 
256     }
257     public class Xcls_compile_view : Object 
258     {
259         public Gtk.VBox el;
260         private Xcls_GtkView  _this;
261
262
263             // my vars (def)
264
265         // ctor 
266         public Xcls_compile_view(Xcls_GtkView _owner )
267         {
268             _this = _owner;
269             _this.compile_view = this;
270             this.el = new Gtk.VBox( false, 0 );
271
272             // my vars (dec)
273
274             // set gobject values
275             var child_0 = new Xcls_HBox6( _this );
276             child_0.ref();
277             this.el.pack_start (  child_0.el , false,false,0 );
278             var child_1 = new Xcls_HPaned8( _this );
279             child_1.ref();
280             this.el.pack_start (  child_1.el , true,true,0 );
281         }
282
283         // user defined functions 
284     }
285     public class Xcls_HBox6 : Object 
286     {
287         public Gtk.HBox el;
288         private Xcls_GtkView  _this;
289
290
291             // my vars (def)
292
293         // ctor 
294         public Xcls_HBox6(Xcls_GtkView _owner )
295         {
296             _this = _owner;
297             this.el = new Gtk.HBox( true, 0 );
298
299             // my vars (dec)
300
301             // set gobject values
302             var child_0 = new Xcls_Button7( _this );
303             child_0.ref();
304             this.el.pack_start (  child_0.el , true,true,0 );
305         }
306
307         // user defined functions 
308     }
309     public class Xcls_Button7 : Object 
310     {
311         public Gtk.Button el;
312         private Xcls_GtkView  _this;
313
314
315             // my vars (def)
316
317         // ctor 
318         public Xcls_Button7(Xcls_GtkView _owner )
319         {
320             _this = _owner;
321             this.el = new Gtk.Button();
322
323             // my vars (dec)
324
325             // set gobject values
326             this.el.label = "Full Compile";
327         }
328
329         // user defined functions 
330     }
331     public class Xcls_HPaned8 : Object 
332     {
333         public Gtk.HPaned el;
334         private Xcls_GtkView  _this;
335
336
337             // my vars (def)
338
339         // ctor 
340         public Xcls_HPaned8(Xcls_GtkView _owner )
341         {
342             _this = _owner;
343             this.el = new Gtk.HPaned();
344
345             // my vars (dec)
346
347             // set gobject values
348             var child_0 = new Xcls_ScrolledWindow9( _this );
349             child_0.ref();
350             this.el.add (  child_0.el  );
351             var child_1 = new Xcls_ScrolledWindow14( _this );
352             child_1.ref();
353             this.el.add (  child_1.el  );
354         }
355
356         // user defined functions 
357     }
358     public class Xcls_ScrolledWindow9 : Object 
359     {
360         public Gtk.ScrolledWindow el;
361         private Xcls_GtkView  _this;
362
363
364             // my vars (def)
365
366         // ctor 
367         public Xcls_ScrolledWindow9(Xcls_GtkView _owner )
368         {
369             _this = _owner;
370             this.el = new Gtk.ScrolledWindow( null, null );
371
372             // my vars (dec)
373
374             // set gobject values
375             var child_0 = new Xcls_TreeView10( _this );
376             child_0.ref();
377             this.el.add (  child_0.el  );
378
379             // init method 
380
381             {
382              this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
383              
384             
385             }
386         }
387
388         // user defined functions 
389     }
390     public class Xcls_TreeView10 : Object 
391     {
392         public Gtk.TreeView el;
393         private Xcls_GtkView  _this;
394
395
396             // my vars (def)
397
398         // ctor 
399         public Xcls_TreeView10(Xcls_GtkView _owner )
400         {
401             _this = _owner;
402             this.el = new Gtk.TreeView();
403
404             // my vars (dec)
405
406             // set gobject values
407             var child_0 = new Xcls_compile_result_store( _this );
408             child_0.ref();
409             this.el.set_model (  child_0.el  );
410             var child_1 = new Xcls_column( _this );
411             child_1.ref();
412             this.el.append_column (  child_1.el  );
413         }
414
415         // user defined functions 
416     }
417     public class Xcls_compile_result_store : Object 
418     {
419         public Gtk.TreeStore el;
420         private Xcls_GtkView  _this;
421
422
423             // my vars (def)
424
425         // ctor 
426         public Xcls_compile_result_store(Xcls_GtkView _owner )
427         {
428             _this = _owner;
429             _this.compile_result_store = this;
430             this.el = new Gtk.TreeStore( 4,   typeof(string), typeof(int), typeof(string), typeof(string)  );
431
432             // my vars (dec)
433
434             // set gobject values
435         }
436
437         // user defined functions 
438         public void nodeAppendOrCreate (Gtk.TreePath  par, string id, string file, int line, string message) {
439         
440             Gtk.TreeIter piter;
441              
442             this.el.get_iter(out piter, par);
443              
444             // loop through parent childnre
445             Gtk.TreeIter iter; 
446             var loop =  par == null ? 
447                 this.el.iter_children(out iter, null) :
448                  this.el.iter_children(out iter,  piter);
449             
450             while (loop) {
451                 GLib.Value val;
452                 this.el.get_value(iter, 0, out val);
453                 var sval = (string)val;
454                 if (sval == id) {
455                     GLib.Value mval;
456                     this.el.get_value(iter, 2, out mval);
457                     var smval = (string)mval;
458                     mval.set_string(smval + "\n" + GLib.Markup.escape_text(message)); //markup?
459                 
460                     return;
461                 }
462                 loop = this.el.iter_next(ref iter);    
463             }
464             
465             // create the node...
466             if (par == null) {
467                 this.el.append(out iter, null);
468             } else {
469                 this.el.append(out iter, piter);
470             }
471             this.el.set(iter, 0, id, 1, line,2, GLib.Markup.escape_text("%d: %s".printf(line,message)), 3, file,-1);
472                 
473             return ;
474         
475         }
476         public Gtk.TreePath nodeFindOrCreate (Gtk.TreePath? par, string id, string title) {
477         
478         
479             //print("looking for %s\n", id);
480             // loop through parent childnre
481             Gtk.TreeIter piter   ;
482             Gtk.TreeIter iter;
483             var loop = true;
484             if (par != null) {
485                 this.el.get_iter(out piter, par);
486                 loop = this.el.iter_children(out iter,  piter);
487             } else {
488                 loop = this.el.iter_children(out iter, null) ;
489             }
490                  
491                  
492             while (loop) {
493                 GLib.Value val;
494                 this.el.get_value(iter, 0, out val);
495                 var sval = (string)val;
496                 //print("got node %s", sval);
497                 if (sval == id) {
498                     return this.el.get_path(iter);
499                 }
500                 loop = this.el.iter_next(ref iter);    
501             }
502             // create the node...
503              if (par == null) {
504                 this.el.append(out iter, null);
505             } else {
506               this.el.get_iter(out piter, par);
507                 this.el.append(out iter, piter);
508             }
509             //print("add iter %s / %s", id, title);
510             this.el.set(iter, 0, id, 1, 0, 2, title, 3, "",-1);
511                
512             return   this.el.get_path(iter);
513         
514         }
515     }
516     public class Xcls_column : Object 
517     {
518         public Gtk.TreeViewColumn el;
519         private Xcls_GtkView  _this;
520
521
522             // my vars (def)
523
524         // ctor 
525         public Xcls_column(Xcls_GtkView _owner )
526         {
527             _this = _owner;
528             this.el = new Gtk.TreeViewColumn();
529
530             // my vars (dec)
531
532             // set gobject values
533             this.el.title = "Compile output";
534             var child_0 = new Xcls_renderer( _this );
535             child_0.ref();
536             this.el.pack_start (  child_0.el , true );
537
538             // init method 
539
540             {
541               this.el.add_attribute(_this.renderer.el , "markup", 2 );
542              
543             }
544         }
545
546         // user defined functions 
547     }
548     public class Xcls_renderer : Object 
549     {
550         public Gtk.CellRendererText el;
551         private Xcls_GtkView  _this;
552
553
554             // my vars (def)
555
556         // ctor 
557         public Xcls_renderer(Xcls_GtkView _owner )
558         {
559             _this = _owner;
560             _this.renderer = this;
561             this.el = new Gtk.CellRendererText();
562
563             // my vars (dec)
564
565             // set gobject values
566         }
567
568         // user defined functions 
569     }
570     public class Xcls_ScrolledWindow14 : Object 
571     {
572         public Gtk.ScrolledWindow el;
573         private Xcls_GtkView  _this;
574
575
576             // my vars (def)
577
578         // ctor 
579         public Xcls_ScrolledWindow14(Xcls_GtkView _owner )
580         {
581             _this = _owner;
582             this.el = new Gtk.ScrolledWindow( null, null );
583
584             // my vars (dec)
585
586             // set gobject values
587             var child_0 = new Xcls_View15( _this );
588             child_0.ref();
589             this.el.add (  child_0.el  );
590         }
591
592         // user defined functions 
593     }
594     public class Xcls_View15 : Object 
595     {
596         public Gtk.SourceView el;
597         private Xcls_GtkView  _this;
598
599
600             // my vars (def)
601
602         // ctor 
603         public Xcls_View15(Xcls_GtkView _owner )
604         {
605             _this = _owner;
606             this.el = new Gtk.SourceView();
607
608             // my vars (dec)
609
610             // set gobject values
611             this.el.editable = false;
612             this.el.show_line_marks = true;
613             this.el.show_line_numbers = true;
614         }
615
616         // user defined functions 
617     }
618 }