src/Builder4/ClutterFiles.bjs
[app.Builder.js] / src / Builder4 / ClutterFiles.vala
1 static Xcls_ClutterFiles  _ClutterFiles;
2
3 public class Xcls_ClutterFiles : Object
4 {
5     public Clutter.Actor el;
6     private Xcls_ClutterFiles  _this;
7
8     public static Xcls_ClutterFiles singleton()
9     {
10         if (_ClutterFiles == null) {
11             _ClutterFiles= new Xcls_ClutterFiles();
12         }
13         return _ClutterFiles;
14     }
15     public Xcls_project_title project_title;
16     public Xcls_project_title_manager project_title_manager;
17     public Xcls_project_title_name project_title_name;
18     public Xcls_project_title_path project_title_path;
19     public Xcls_scroller scroller;
20     public Xcls_filelayout filelayout;
21     public Xcls_filelayout_manager filelayout_manager;
22
23         // my vars (def)
24     public Clutter.ScrollMode scroll_mode;
25     public Gdk.Pixbuf missing_thumb_pixbuf;
26     public signal void open (JsRender.JsRender file);
27     public Gee.ArrayList<Object> fileitems;
28
29     // ctor
30     public Xcls_ClutterFiles()
31     {
32         _this = this;
33         this.el = new Clutter.Actor();
34
35         // my vars (dec)
36         this.scroll_mode = Clutter.ScrollMode.VERTICALLY;
37         this.missing_thumb_pixbuf = null;
38         this.fileitems = new Gee.ArrayList<Object>();
39
40         // set gobject values
41         this.el.reactive = true;
42         var child_0 = new Xcls_project_title( _this );
43         child_0.ref();
44         this.el.add_child (  child_0.el  );
45         var child_1 = new Xcls_scroller( _this );
46         child_1.ref();
47         this.el.add_child (  child_1.el  );
48     }
49
50     // user defined functions
51     public  void clearFiles () {
52         
53         this.filelayout.el.remove_all_children();
54         // we need to unref all the chidren that we loaded though...
55         
56     }
57     public  void loadProject (Project.Project pr) {
58         // list all the files, and create new Xcls_fileitem for each one.
59         
60         // LEAK --- we should unref all the chilren...
61         this.filelayout.el.y = 0;
62         this.clearFiles();
63         
64         print("clutter files - load project: " + pr.name +"\n");
65         // should unref.. them hopefully.
66         
67         this.project_title_name.el.text = pr.name;
68         this.project_title_path.el.text = pr.firstPath();
69         
70         // file items contains a reference until we reload ...
71         this.fileitems = new Gee.ArrayList<Object>();
72     
73         
74     
75         var fiter = pr.sortedFiles().list_iterator();
76         while (fiter.next()) {
77             var a = new Xcls_fileitem(this,fiter.get());
78             this.fileitems.add(a);
79     
80     //        a.ref();
81             print("add to clutter file view: " + fiter.get().name + "\n");
82             this.filelayout.el.add_child(a.el);
83         }
84         
85         // folders...
86         
87         if (!(pr is Project.Gtk)) {
88             print ("not gtk... skipping files");
89             return;
90         }
91         var gpr = (Project.Gtk)pr;
92          var def = gpr.compilegroups.get("_default_");
93          var items  = def.sources;
94          
95          
96          
97         for(var i =0 ; i < items.size; i++) {
98             print ("cheking folder %s\n", items.get(i));
99              var files = gpr.files(items.get(i));
100              if (files.size < 1) {
101                 continue;
102              }
103     
104             // add the directory... items.get(i);
105             var x = new Xcls_folderitem(this,items.get(i));
106             this.fileitems.add(x);
107             this.filelayout.el.add_child(x.el);
108             
109             for(var j =0 ; j < files.size; j++) {
110                 print ("adding file %s\n", files.get(j));
111             
112                 var y = new Xcls_folderfile(this, files.get(j));
113                 this.fileitems.add(y);
114                 x.el.add_child(y.el);
115     
116                 // add file to files.get(j);
117                 
118             }
119             
120             
121             //this.el.set_value(citer, 1,   items.get(i) );
122         }
123         
124        
125         
126         this.el.show();
127     }
128     public  void set_size (float w, float h) 
129     {
130         
131          // called by window resize... with is alreaddy -50 (for the buttons?)
132          
133     
134     
135     
136          if (this.el == null) {
137             print("object not ready yet?");
138             return;
139         }
140         
141         print("recv width %f, filelayoutw = %f", w, w-200);
142         
143        //_this.filelayout_manager.el.max_column_width = w - 200;
144        _this.filelayout.el.width = w - 200;
145        
146         this.el.set_size(
147                // this.el.get_stage().width-150,
148                w,
149                h  // this.el.get_stage().height
150         );
151         
152         // 100 right for buttons ..
153         this.el.set_position(0,0);
154        
155        
156        this.scroller.el.set_size(
157                // this.el.get_stage().width-150,
158                w-50,
159                h  // this.el.get_stage().height
160         );
161         
162         // 100 right for buttons ..
163         this.scroller.el.set_position(75,50);
164     }
165     public class Xcls_project_title : Object
166     {
167         public Clutter.Actor el;
168         private Xcls_ClutterFiles  _this;
169
170
171             // my vars (def)
172
173         // ctor
174         public Xcls_project_title(Xcls_ClutterFiles _owner )
175         {
176             _this = _owner;
177             _this.project_title = this;
178             this.el = new Clutter.Actor();
179
180             // my vars (dec)
181
182             // set gobject values
183             this.el.reactive = true;
184             var child_0 = new Xcls_project_title_manager( _this );
185             child_0.ref();
186             this.el.layout_manager = child_0.el;
187             var child_1 = new Xcls_FixedLayout4( _this );
188             child_1.ref();
189             this.el.layout_manager = child_1.el;
190             var child_2 = new Xcls_project_title_name( _this );
191             child_2.ref();
192             this.el.add_child (  child_2.el  );
193             var child_3 = new Xcls_project_title_path( _this );
194             child_3.ref();
195             this.el.add_child (  child_3.el  );
196
197             // init method
198
199             this.el.add_constraint(
200                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
201             );
202             this.el.set_position(75,0);
203         }
204
205         // user defined functions
206     }
207     public class Xcls_project_title_manager : Object
208     {
209         public Clutter.FlowLayout el;
210         private Xcls_ClutterFiles  _this;
211
212
213             // my vars (def)
214
215         // ctor
216         public Xcls_project_title_manager(Xcls_ClutterFiles _owner )
217         {
218             _this = _owner;
219             _this.project_title_manager = this;
220             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
221
222             // my vars (dec)
223
224             // set gobject values
225             this.el.homogeneous = false;
226             this.el.row_spacing = 5f;
227             this.el.column_spacing = 20f;
228         }
229
230         // user defined functions
231     }
232
233     public class Xcls_FixedLayout4 : Object
234     {
235         public Clutter.FixedLayout el;
236         private Xcls_ClutterFiles  _this;
237
238
239             // my vars (def)
240
241         // ctor
242         public Xcls_FixedLayout4(Xcls_ClutterFiles _owner )
243         {
244             _this = _owner;
245             this.el = new Clutter.FixedLayout();
246
247             // my vars (dec)
248
249             // set gobject values
250         }
251
252         // user defined functions
253     }
254
255     public class Xcls_project_title_name : Object
256     {
257         public Clutter.Text el;
258         private Xcls_ClutterFiles  _this;
259
260
261             // my vars (def)
262
263         // ctor
264         public Xcls_project_title_name(Xcls_ClutterFiles _owner )
265         {
266             _this = _owner;
267             _this.project_title_name = this;
268             this.el = new Clutter.Text.full("Sans 20px", "",  Clutter.Color.from_string("#eee"));
269
270             // my vars (dec)
271
272             // set gobject values
273             this.el.x = 0.0f;
274             this.el.y = 10.0f;
275             this.el.x_expand = false;
276         }
277
278         // user defined functions
279     }
280
281     public class Xcls_project_title_path : Object
282     {
283         public Clutter.Text el;
284         private Xcls_ClutterFiles  _this;
285
286
287             // my vars (def)
288
289         // ctor
290         public Xcls_project_title_path(Xcls_ClutterFiles _owner )
291         {
292             _this = _owner;
293             _this.project_title_path = this;
294             this.el = new Clutter.Text.full("Sans 10px", "",  Clutter.Color.from_string("#ccc"));
295
296             // my vars (dec)
297
298             // set gobject values
299             this.el.x = 0.0f;
300             this.el.y = 35.0f;
301         }
302
303         // user defined functions
304     }
305
306
307     public class Xcls_scroller : Object
308     {
309         public Clutter.ScrollActor el;
310         private Xcls_ClutterFiles  _this;
311
312
313             // my vars (def)
314         public Gee.ArrayList<Xcls_fileitem> fileitems;
315         public Gdk.Pixbuf missing_thumb_pixbuf;
316
317         // ctor
318         public Xcls_scroller(Xcls_ClutterFiles _owner )
319         {
320             _this = _owner;
321             _this.scroller = this;
322             this.el = new Clutter.ScrollActor();
323
324             // my vars (dec)
325             this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
326             this.missing_thumb_pixbuf = null;
327
328             // set gobject values
329             this.el.scroll_mode = Clutter.ScrollMode.VERTICALLY;
330             this.el.reactive = true;
331             var child_0 = new Xcls_filelayout( _this );
332             child_0.ref();
333             this.el.add_child (  child_0.el  );
334
335             //listeners
336             this.el.scroll_event.connect( ( event) => {
337                //Sprint("scroll event");
338                 var y = _this.filelayout.el.y;
339                 var dir = event.direction;
340                 switch (dir) {
341                     case Clutter.ScrollDirection.UP:
342                         y += event.y /2;
343                         break;
344                     case Clutter.ScrollDirection.DOWN:
345                         y -= event.y /2 ;
346                         break;
347                     default:
348                         return false;
349                 }
350                 // range of scroll -- can go up -- eg.. -ve value.
351                 
352                 y = float.min(0, y);
353                 
354                 // to work out the max -ve number
355                 // height of filelayout
356                 // height of scrollactor..
357                 
358                 var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;
359                 if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {
360                     var nv =         _this.filelayout.el.y ;
361                     if (nv != -1 * (  last_child_bottom - this.el.height) {
362                 
363                         _this.filelayout.el.y = -1 * (  last_child_bottom - this.el.height);
364                     }
365                 
366                     return  false;
367                 }
368             
369             
370                 
371                 
372             //    print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
373               //          last_child_bottom - this.el.height,
374                //         y));    
375                // y = float.min(0, y);    //??
376                // print("scroll event of %f  - new y = %f ".printf(event.y, y));
377                print("Set scroll to %f (lcb=%f / height = %f)\n", y, last_child_bottom, this.el.height);
378                
379                 _this.filelayout.el.y = y;
380                 return true;
381                       
382             });
383         }
384
385         // user defined functions
386     }
387     public class Xcls_filelayout : Object
388     {
389         public Clutter.Actor el;
390         private Xcls_ClutterFiles  _this;
391
392
393             // my vars (def)
394
395         // ctor
396         public Xcls_filelayout(Xcls_ClutterFiles _owner )
397         {
398             _this = _owner;
399             _this.filelayout = this;
400             this.el = new Clutter.Actor();
401
402             // my vars (dec)
403
404             // set gobject values
405             this.el.reactive = true;
406             var child_0 = new Xcls_filelayout_manager( _this );
407             child_0.ref();
408             this.el.layout_manager = child_0.el;
409
410             // init method
411
412             this.el.add_constraint(
413                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
414             );
415         }
416
417         // user defined functions
418     }
419     public class Xcls_filelayout_manager : Object
420     {
421         public Clutter.FlowLayout el;
422         private Xcls_ClutterFiles  _this;
423
424
425             // my vars (def)
426
427         // ctor
428         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
429         {
430             _this = _owner;
431             _this.filelayout_manager = this;
432             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
433
434             // my vars (dec)
435
436             // set gobject values
437             this.el.homogeneous = false;
438             this.el.max_column_width = 100.0f;
439             this.el.row_spacing = 20f;
440             this.el.column_spacing = 20f;
441         }
442
443         // user defined functions
444     }
445
446     public class Xcls_fileitem : Object
447     {
448         public Clutter.Actor el;
449         private Xcls_ClutterFiles  _this;
450
451
452             // my vars (def)
453         public JsRender.JsRender file;
454         public Xcls_image image;
455         public Xcls_typetitle typetitle;
456         public Xcls_title title;
457
458         // ctor
459         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
460         {
461             _this = _owner;
462             this.el = new Clutter.Actor();
463
464             // my vars (dec)
465
466             // set gobject values
467             this.el.reactive = true;
468             var child_0 = new Xcls_BoxLayout11( _this );
469             child_0.ref();
470             this.el.layout_manager = child_0.el;
471             var child_1 = new Xcls_image( _this ,file);
472             child_1.ref();
473             this.el.add_child (  child_1.el  );
474             this.image =  child_1;
475             var child_2 = new Xcls_typetitle( _this ,file);
476             child_2.ref();
477             this.el.add_child (  child_2.el  );
478             this.typetitle =  child_2;
479             var child_3 = new Xcls_title( _this ,file);
480             child_3.ref();
481             this.el.add_child (  child_3.el  );
482             this.title =  child_3;
483
484             // init method
485
486             this.file = file;
487             this.el.set_size(100,100);
488
489             //listeners
490             this.el.button_press_event.connect( (  event) => {
491                 _this.open(this.file);
492                 return false;
493             });
494             this.el.enter_event.connect( (  event)  => {
495                 this.el.background_color =   Clutter.Color.from_string("#333");
496                     return false;
497             });
498             this.el.leave_event.connect( (  event)  => {
499                 this.el.background_color =   Clutter.Color.from_string("#000");
500                 return false;
501             });
502         }
503
504         // user defined functions
505     }
506     public class Xcls_BoxLayout11 : Object
507     {
508         public Clutter.BoxLayout el;
509         private Xcls_ClutterFiles  _this;
510
511
512             // my vars (def)
513
514         // ctor
515         public Xcls_BoxLayout11(Xcls_ClutterFiles _owner )
516         {
517             _this = _owner;
518             this.el = new Clutter.BoxLayout();
519
520             // my vars (dec)
521
522             // set gobject values
523             this.el.spacing = 4;
524             this.el.orientation = Clutter.Orientation.VERTICAL;
525         }
526
527         // user defined functions
528     }
529
530     public class Xcls_image : Object
531     {
532         public Clutter.Actor el;
533         private Xcls_ClutterFiles  _this;
534
535
536             // my vars (def)
537
538         // ctor
539         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
540         {
541             _this = _owner;
542             this.el = new Clutter.Actor();
543
544             // my vars (dec)
545
546             // set gobject values
547             this.el.margin_right = 5f;
548             this.el.margin_left = 5f;
549             this.el.x_align = Clutter.ActorAlign.START;
550             this.el.x_expand = false;
551             this.el.y_align = Clutter.ActorAlign.START;
552             this.el.margin_top = 5f;
553             this.el.y_expand = false;
554
555             // init method
556
557             {
558                 Gdk.Pixbuf pixbuf= null;
559                 
560                 var fname = file.getIconFileName(false);
561             
562                 try {
563                     if (FileUtils.test(fname, FileTest.EXISTS)) {
564                         pixbuf = new Gdk.Pixbuf.from_file(fname);
565                     } 
566                 } catch (Error e) {
567                     // noop
568                 
569                 }
570                 if (pixbuf == null) {
571                     
572                     try {
573                         if (_this.missing_thumb_pixbuf == null) {
574                                 var icon_theme = Gtk.IconTheme.get_default ();
575                                 _this.missing_thumb_pixbuf = icon_theme.load_icon ("package-x-generic", 92, 0);
576                                 _this.missing_thumb_pixbuf.ref();
577                             }
578                             pixbuf = _this.missing_thumb_pixbuf;
579             
580                     } catch (Error e) {
581                         // noop?
582                     }
583                 }
584                 try {
585                     var img = new Clutter.Image();
586                     img.set_data(pixbuf.get_pixels(),   
587                                         pixbuf.has_alpha 
588                                           ? Cogl.PixelFormat.RGBA_8888
589                                           : Cogl.PixelFormat.RGB_888,
590                                         pixbuf.get_width (),
591                             pixbuf.get_height (),
592                                         pixbuf.get_rowstride ()
593                     );
594                     this.el.set_content(img);
595                 } catch (Error e) {
596                     // noop?
597                 }
598                  // should probably do smarter scaling...
599                 
600                 
601                 this.el.set_size(90, 70);
602             }
603         }
604
605         // user defined functions
606     }
607
608     public class Xcls_typetitle : Object
609     {
610         public Clutter.Text el;
611         private Xcls_ClutterFiles  _this;
612
613
614             // my vars (def)
615
616         // ctor
617         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
618         {
619             _this = _owner;
620             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),  Clutter.Color.from_string("#fff"));
621
622             // my vars (dec)
623
624             // set gobject values
625             this.el.x_align = Clutter.ActorAlign.START;
626             this.el.x_expand = false;
627             this.el.y_align = Clutter.ActorAlign.START;
628             this.el.y_expand = false;
629         }
630
631         // user defined functions
632     }
633
634     public class Xcls_title : Object
635     {
636         public Clutter.Text el;
637         private Xcls_ClutterFiles  _this;
638
639
640             // my vars (def)
641
642         // ctor
643         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
644         {
645             _this = _owner;
646             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),  Clutter.Color.from_string("#fff"));
647
648             // my vars (dec)
649
650             // set gobject values
651             this.el.x_align = Clutter.ActorAlign.START;
652             this.el.x_expand = false;
653             this.el.y_align = Clutter.ActorAlign.START;
654             this.el.y_expand = false;
655         }
656
657         // user defined functions
658     }
659
660
661     public class Xcls_folderitem : Object
662     {
663         public Clutter.Actor el;
664         private Xcls_ClutterFiles  _this;
665
666
667             // my vars (def)
668         public Xcls_foldertitle foldertitle;
669
670         // ctor
671         public Xcls_folderitem(Xcls_ClutterFiles _owner , string folderpath)
672         {
673             _this = _owner;
674             this.el = new Clutter.Actor();
675
676             // my vars (dec)
677
678             // set gobject values
679             this.el.reactive = true;
680             var child_0 = new Xcls_BoxLayout16( _this );
681             child_0.ref();
682             this.el.layout_manager = child_0.el;
683             var child_1 = new Xcls_foldertitle( _this ,folderpath);
684             child_1.ref();
685             this.el.add_child (  child_1.el  );
686             this.foldertitle =  child_1;
687
688             // init method
689
690             //this.el.set_size(100,100);
691         }
692
693         // user defined functions
694     }
695     public class Xcls_BoxLayout16 : Object
696     {
697         public Clutter.BoxLayout el;
698         private Xcls_ClutterFiles  _this;
699
700
701             // my vars (def)
702
703         // ctor
704         public Xcls_BoxLayout16(Xcls_ClutterFiles _owner )
705         {
706             _this = _owner;
707             this.el = new Clutter.BoxLayout();
708
709             // my vars (dec)
710
711             // set gobject values
712             this.el.spacing = 2;
713             this.el.orientation = Clutter.Orientation.VERTICAL;
714         }
715
716         // user defined functions
717     }
718
719     public class Xcls_foldertitle : Object
720     {
721         public Clutter.Text el;
722         private Xcls_ClutterFiles  _this;
723
724
725             // my vars (def)
726
727         // ctor
728         public Xcls_foldertitle(Xcls_ClutterFiles _owner , string folderpath)
729         {
730             _this = _owner;
731             this.el = new Clutter.Text.full("Sans 14px", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string("#fff"));
732
733             // my vars (dec)
734
735             // set gobject values
736             this.el.x_align = Clutter.ActorAlign.START;
737             this.el.x_expand = true;
738             this.el.y_align = Clutter.ActorAlign.START;
739             this.el.y_expand = false;
740         }
741
742         // user defined functions
743     }
744
745     public class Xcls_folderfile : Object
746     {
747         public Clutter.Text el;
748         private Xcls_ClutterFiles  _this;
749
750
751             // my vars (def)
752         public string filepath;
753
754         // ctor
755         public Xcls_folderfile(Xcls_ClutterFiles _owner , string filepath)
756         {
757             _this = _owner;
758             this.el = new Clutter.Text.full("Sans 10px", GLib.Path.get_basename(filepath),  Clutter.Color.from_string("#fff"));
759
760             // my vars (dec)
761
762             // set gobject values
763             this.el.x_align = Clutter.ActorAlign.START;
764             this.el.x_expand = true;
765             this.el.y_align = Clutter.ActorAlign.START;
766             this.el.reactive = true;
767             this.el.y_expand = false;
768
769             // init method
770
771             {
772                 this.filepath = filepath;
773             }
774
775             //listeners
776             this.el.button_press_event.connect( (  event) => {
777                // _this.open(this.filepath);
778                 return false;
779             });
780             this.el.enter_event.connect( (  event)  => {
781                 this.el.background_color =   Clutter.Color.from_string("#333");
782                     return false;
783             });
784             this.el.leave_event.connect( (  event)  => {
785                 this.el.background_color =   Clutter.Color.from_string("#000");
786                 return false;
787             });
788         }
789
790         // user defined functions
791     }
792
793
794
795
796 }