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