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