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                         print("Scroll up by %f\n", event.y);
343                         y += event.y /2;
344                         y = float.min(0, y);
345                         break;
346                         
347                     case Clutter.ScrollDirection.DOWN:
348                         print("Scroll down by %f\n", event.y);
349                         y -= event.y /2 ;
350                         break;
351                     default:
352                         return false;
353                 }
354                 // range of scroll -- can go up -- eg.. -ve value.
355                 
356             
357                 
358                 // to work out the max -ve number
359                 // height of filelayout
360                 // height of scrollactor..
361                 
362                 var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;
363                 if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {
364                     var nv =         _this.filelayout.el.y ;
365                     if (nv != -1 * (  last_child_bottom - this.el.height)) {
366                 
367                         _this.filelayout.el.y = -1 * (  last_child_bottom - this.el.height);
368                         return true;
369                     }
370                 
371                     return  false;
372                 }
373             
374             
375                 
376                 
377             //    print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
378               //          last_child_bottom - this.el.height,
379                //         y));    
380                // y = float.min(0, y);    //??
381                // print("scroll event of %f  - new y = %f ".printf(event.y, y));
382                print("Set scroll to %f (lcb=%f / height = %f)\n", y, last_child_bottom, this.el.height);
383                
384                 _this.filelayout.el.y = y;
385                 return true;
386                       
387             });
388         }
389
390         // user defined functions
391     }
392     public class Xcls_filelayout : Object
393     {
394         public Clutter.Actor el;
395         private Xcls_ClutterFiles  _this;
396
397
398             // my vars (def)
399
400         // ctor
401         public Xcls_filelayout(Xcls_ClutterFiles _owner )
402         {
403             _this = _owner;
404             _this.filelayout = this;
405             this.el = new Clutter.Actor();
406
407             // my vars (dec)
408
409             // set gobject values
410             this.el.reactive = true;
411             var child_0 = new Xcls_filelayout_manager( _this );
412             child_0.ref();
413             this.el.layout_manager = child_0.el;
414
415             // init method
416
417             this.el.add_constraint(
418                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
419             );
420         }
421
422         // user defined functions
423     }
424     public class Xcls_filelayout_manager : Object
425     {
426         public Clutter.FlowLayout el;
427         private Xcls_ClutterFiles  _this;
428
429
430             // my vars (def)
431
432         // ctor
433         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
434         {
435             _this = _owner;
436             _this.filelayout_manager = this;
437             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
438
439             // my vars (dec)
440
441             // set gobject values
442             this.el.homogeneous = false;
443             this.el.max_column_width = 100.0f;
444             this.el.row_spacing = 20f;
445             this.el.column_spacing = 20f;
446         }
447
448         // user defined functions
449     }
450
451     public class Xcls_fileitem : Object
452     {
453         public Clutter.Actor el;
454         private Xcls_ClutterFiles  _this;
455
456
457             // my vars (def)
458         public JsRender.JsRender file;
459         public Xcls_image image;
460         public Xcls_typetitle typetitle;
461         public Xcls_title title;
462
463         // ctor
464         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
465         {
466             _this = _owner;
467             this.el = new Clutter.Actor();
468
469             // my vars (dec)
470
471             // set gobject values
472             this.el.reactive = true;
473             var child_0 = new Xcls_BoxLayout11( _this );
474             child_0.ref();
475             this.el.layout_manager = child_0.el;
476             var child_1 = new Xcls_image( _this ,file);
477             child_1.ref();
478             this.el.add_child (  child_1.el  );
479             this.image =  child_1;
480             var child_2 = new Xcls_typetitle( _this ,file);
481             child_2.ref();
482             this.el.add_child (  child_2.el  );
483             this.typetitle =  child_2;
484             var child_3 = new Xcls_title( _this ,file);
485             child_3.ref();
486             this.el.add_child (  child_3.el  );
487             this.title =  child_3;
488
489             // init method
490
491             this.file = file;
492             this.el.set_size(100,100);
493
494             //listeners
495             this.el.button_press_event.connect( (  event) => {
496                 _this.open(this.file);
497                 return false;
498             });
499             this.el.enter_event.connect( (  event)  => {
500                 this.el.background_color =   Clutter.Color.from_string("#333");
501                     return false;
502             });
503             this.el.leave_event.connect( (  event)  => {
504                 this.el.background_color =   Clutter.Color.from_string("#000");
505                 return false;
506             });
507         }
508
509         // user defined functions
510     }
511     public class Xcls_BoxLayout11 : Object
512     {
513         public Clutter.BoxLayout el;
514         private Xcls_ClutterFiles  _this;
515
516
517             // my vars (def)
518
519         // ctor
520         public Xcls_BoxLayout11(Xcls_ClutterFiles _owner )
521         {
522             _this = _owner;
523             this.el = new Clutter.BoxLayout();
524
525             // my vars (dec)
526
527             // set gobject values
528             this.el.spacing = 4;
529             this.el.orientation = Clutter.Orientation.VERTICAL;
530         }
531
532         // user defined functions
533     }
534
535     public class Xcls_image : Object
536     {
537         public Clutter.Actor el;
538         private Xcls_ClutterFiles  _this;
539
540
541             // my vars (def)
542
543         // ctor
544         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
545         {
546             _this = _owner;
547             this.el = new Clutter.Actor();
548
549             // my vars (dec)
550
551             // set gobject values
552             this.el.margin_right = 5f;
553             this.el.margin_left = 5f;
554             this.el.x_align = Clutter.ActorAlign.START;
555             this.el.x_expand = false;
556             this.el.y_align = Clutter.ActorAlign.START;
557             this.el.margin_top = 5f;
558             this.el.y_expand = false;
559
560             // init method
561
562             {
563                 Gdk.Pixbuf pixbuf= null;
564                 
565                 var fname = file.getIconFileName(false);
566             
567                 try {
568                     if (FileUtils.test(fname, FileTest.EXISTS)) {
569                         pixbuf = new Gdk.Pixbuf.from_file(fname);
570                     } 
571                 } catch (Error e) {
572                     // noop
573                 
574                 }
575                 if (pixbuf == null) {
576                     
577                     try {
578                         if (_this.missing_thumb_pixbuf == null) {
579                                 var icon_theme = Gtk.IconTheme.get_default ();
580                                 _this.missing_thumb_pixbuf = icon_theme.load_icon ("package-x-generic", 92, 0);
581                                 _this.missing_thumb_pixbuf.ref();
582                             }
583                             pixbuf = _this.missing_thumb_pixbuf;
584             
585                     } catch (Error e) {
586                         // noop?
587                     }
588                 }
589                 try {
590                     var img = new Clutter.Image();
591                     img.set_data(pixbuf.get_pixels(),   
592                                         pixbuf.has_alpha 
593                                           ? Cogl.PixelFormat.RGBA_8888
594                                           : Cogl.PixelFormat.RGB_888,
595                                         pixbuf.get_width (),
596                             pixbuf.get_height (),
597                                         pixbuf.get_rowstride ()
598                     );
599                     this.el.set_content(img);
600                 } catch (Error e) {
601                     // noop?
602                 }
603                  // should probably do smarter scaling...
604                 
605                 
606                 this.el.set_size(90, 70);
607             }
608         }
609
610         // user defined functions
611     }
612
613     public class Xcls_typetitle : Object
614     {
615         public Clutter.Text el;
616         private Xcls_ClutterFiles  _this;
617
618
619             // my vars (def)
620
621         // ctor
622         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
623         {
624             _this = _owner;
625             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),  Clutter.Color.from_string("#fff"));
626
627             // my vars (dec)
628
629             // set gobject values
630             this.el.x_align = Clutter.ActorAlign.START;
631             this.el.x_expand = false;
632             this.el.y_align = Clutter.ActorAlign.START;
633             this.el.y_expand = false;
634         }
635
636         // user defined functions
637     }
638
639     public class Xcls_title : Object
640     {
641         public Clutter.Text el;
642         private Xcls_ClutterFiles  _this;
643
644
645             // my vars (def)
646
647         // ctor
648         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
649         {
650             _this = _owner;
651             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),  Clutter.Color.from_string("#fff"));
652
653             // my vars (dec)
654
655             // set gobject values
656             this.el.x_align = Clutter.ActorAlign.START;
657             this.el.x_expand = false;
658             this.el.y_align = Clutter.ActorAlign.START;
659             this.el.y_expand = false;
660         }
661
662         // user defined functions
663     }
664
665
666     public class Xcls_folderitem : Object
667     {
668         public Clutter.Actor el;
669         private Xcls_ClutterFiles  _this;
670
671
672             // my vars (def)
673         public Xcls_foldertitle foldertitle;
674
675         // ctor
676         public Xcls_folderitem(Xcls_ClutterFiles _owner , string folderpath)
677         {
678             _this = _owner;
679             this.el = new Clutter.Actor();
680
681             // my vars (dec)
682
683             // set gobject values
684             this.el.reactive = true;
685             var child_0 = new Xcls_BoxLayout16( _this );
686             child_0.ref();
687             this.el.layout_manager = child_0.el;
688             var child_1 = new Xcls_foldertitle( _this ,folderpath);
689             child_1.ref();
690             this.el.add_child (  child_1.el  );
691             this.foldertitle =  child_1;
692
693             // init method
694
695             //this.el.set_size(100,100);
696         }
697
698         // user defined functions
699     }
700     public class Xcls_BoxLayout16 : Object
701     {
702         public Clutter.BoxLayout el;
703         private Xcls_ClutterFiles  _this;
704
705
706             // my vars (def)
707
708         // ctor
709         public Xcls_BoxLayout16(Xcls_ClutterFiles _owner )
710         {
711             _this = _owner;
712             this.el = new Clutter.BoxLayout();
713
714             // my vars (dec)
715
716             // set gobject values
717             this.el.spacing = 2;
718             this.el.orientation = Clutter.Orientation.VERTICAL;
719         }
720
721         // user defined functions
722     }
723
724     public class Xcls_foldertitle : Object
725     {
726         public Clutter.Text el;
727         private Xcls_ClutterFiles  _this;
728
729
730             // my vars (def)
731
732         // ctor
733         public Xcls_foldertitle(Xcls_ClutterFiles _owner , string folderpath)
734         {
735             _this = _owner;
736             this.el = new Clutter.Text.full("Sans 14px", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string("#fff"));
737
738             // my vars (dec)
739
740             // set gobject values
741             this.el.x_align = Clutter.ActorAlign.START;
742             this.el.x_expand = true;
743             this.el.y_align = Clutter.ActorAlign.START;
744             this.el.y_expand = false;
745         }
746
747         // user defined functions
748     }
749
750     public class Xcls_folderfile : Object
751     {
752         public Clutter.Text el;
753         private Xcls_ClutterFiles  _this;
754
755
756             // my vars (def)
757         public string filepath;
758
759         // ctor
760         public Xcls_folderfile(Xcls_ClutterFiles _owner , string filepath)
761         {
762             _this = _owner;
763             this.el = new Clutter.Text.full("Sans 10px", GLib.Path.get_basename(filepath),  Clutter.Color.from_string("#fff"));
764
765             // my vars (dec)
766
767             // set gobject values
768             this.el.x_align = Clutter.ActorAlign.START;
769             this.el.x_expand = true;
770             this.el.y_align = Clutter.ActorAlign.START;
771             this.el.reactive = true;
772             this.el.y_expand = false;
773
774             // init method
775
776             {
777                 this.filepath = filepath;
778             }
779
780             //listeners
781             this.el.button_press_event.connect( (  event) => {
782                // _this.open(this.filepath);
783                 return false;
784             });
785             this.el.enter_event.connect( (  event)  => {
786                 this.el.background_color =   Clutter.Color.from_string("#333");
787                     return false;
788             });
789             this.el.leave_event.connect( (  event)  => {
790                 this.el.background_color =   Clutter.Color.from_string("#000");
791                 return false;
792             });
793         }
794
795         // user defined functions
796     }
797
798
799
800
801 }