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.filesForOpen(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         w = GLib.Math.floorf ( w/120.0f) * 120.0f;
144         
145         
146         
147         
148        //_this.filelayout_manager.el.max_column_width = w - 200;
149        _this.filelayout.el.width = w - 200;
150        
151         this.el.set_size(
152                // this.el.get_stage().width-150,
153                w,
154                h  // this.el.get_stage().height
155         );
156         
157         // 100 right for buttons ..
158         this.el.set_position(0,0);
159        
160        
161        this.scroller.el.set_size(
162                // this.el.get_stage().width-150,
163                w-50,
164                h  // this.el.get_stage().height
165         );
166         
167         // 100 right for buttons ..
168         this.scroller.el.set_position(75,50);
169         // scroll...
170         _this.filelayout.el.y = 0.0f;
171         
172     }
173     public class Xcls_project_title : Object
174     {
175         public Clutter.Actor el;
176         private Xcls_ClutterFiles  _this;
177
178
179             // my vars (def)
180
181         // ctor
182         public Xcls_project_title(Xcls_ClutterFiles _owner )
183         {
184             _this = _owner;
185             _this.project_title = this;
186             this.el = new Clutter.Actor();
187
188             // my vars (dec)
189
190             // set gobject values
191             this.el.reactive = true;
192             var child_0 = new Xcls_project_title_manager( _this );
193             child_0.ref();
194             this.el.layout_manager = child_0.el;
195             var child_1 = new Xcls_FixedLayout4( _this );
196             child_1.ref();
197             this.el.layout_manager = child_1.el;
198             var child_2 = new Xcls_project_title_name( _this );
199             child_2.ref();
200             this.el.add_child (  child_2.el  );
201             var child_3 = new Xcls_project_title_path( _this );
202             child_3.ref();
203             this.el.add_child (  child_3.el  );
204
205             // init method
206
207             this.el.add_constraint(
208                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
209             );
210             this.el.set_position(75,0);
211         }
212
213         // user defined functions
214     }
215     public class Xcls_project_title_manager : Object
216     {
217         public Clutter.FlowLayout el;
218         private Xcls_ClutterFiles  _this;
219
220
221             // my vars (def)
222
223         // ctor
224         public Xcls_project_title_manager(Xcls_ClutterFiles _owner )
225         {
226             _this = _owner;
227             _this.project_title_manager = this;
228             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
229
230             // my vars (dec)
231
232             // set gobject values
233             this.el.homogeneous = false;
234             this.el.row_spacing = 5f;
235             this.el.column_spacing = 20f;
236         }
237
238         // user defined functions
239     }
240
241     public class Xcls_FixedLayout4 : Object
242     {
243         public Clutter.FixedLayout el;
244         private Xcls_ClutterFiles  _this;
245
246
247             // my vars (def)
248
249         // ctor
250         public Xcls_FixedLayout4(Xcls_ClutterFiles _owner )
251         {
252             _this = _owner;
253             this.el = new Clutter.FixedLayout();
254
255             // my vars (dec)
256
257             // set gobject values
258         }
259
260         // user defined functions
261     }
262
263     public class Xcls_project_title_name : Object
264     {
265         public Clutter.Text el;
266         private Xcls_ClutterFiles  _this;
267
268
269             // my vars (def)
270
271         // ctor
272         public Xcls_project_title_name(Xcls_ClutterFiles _owner )
273         {
274             _this = _owner;
275             _this.project_title_name = this;
276             this.el = new Clutter.Text.full("Sans 20px", "",  Clutter.Color.from_string("#eee"));
277
278             // my vars (dec)
279
280             // set gobject values
281             this.el.x = 0.0f;
282             this.el.y = 10.0f;
283             this.el.x_expand = false;
284         }
285
286         // user defined functions
287     }
288
289     public class Xcls_project_title_path : Object
290     {
291         public Clutter.Text el;
292         private Xcls_ClutterFiles  _this;
293
294
295             // my vars (def)
296
297         // ctor
298         public Xcls_project_title_path(Xcls_ClutterFiles _owner )
299         {
300             _this = _owner;
301             _this.project_title_path = this;
302             this.el = new Clutter.Text.full("Sans 10px", "",  Clutter.Color.from_string("#ccc"));
303
304             // my vars (dec)
305
306             // set gobject values
307             this.el.x = 0.0f;
308             this.el.y = 35.0f;
309         }
310
311         // user defined functions
312     }
313
314
315     public class Xcls_scroller : Object
316     {
317         public Clutter.ScrollActor el;
318         private Xcls_ClutterFiles  _this;
319
320
321             // my vars (def)
322         public Gee.ArrayList<Xcls_fileitem> fileitems;
323         public Gdk.Pixbuf missing_thumb_pixbuf;
324
325         // ctor
326         public Xcls_scroller(Xcls_ClutterFiles _owner )
327         {
328             _this = _owner;
329             _this.scroller = this;
330             this.el = new Clutter.ScrollActor();
331
332             // my vars (dec)
333             this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
334             this.missing_thumb_pixbuf = null;
335
336             // set gobject values
337             this.el.scroll_mode = Clutter.ScrollMode.VERTICALLY;
338             this.el.reactive = true;
339             var child_0 = new Xcls_filelayout( _this );
340             child_0.ref();
341             this.el.add_child (  child_0.el  );
342
343             //listeners
344             this.el.scroll_event.connect( ( event) => {
345                //Sprint("scroll event");
346                 var y = _this.filelayout.el.y;
347                 var dir = event.direction;
348                 
349                 var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;
350                 var bottompos = -1 * (  last_child_bottom - (0.5f * this.el.height));
351                 
352                 switch (dir) {
353                     case Clutter.ScrollDirection.UP:
354                         print("Scroll up by %f\n", event.y);
355                         y += event.y /2;
356                         y = float.min(0, y); // 
357                         break;
358                         
359                     case Clutter.ScrollDirection.DOWN:
360                         print("Scroll down by %f\n", event.y);
361                         y -= event.y /2 ;
362                         y = float.max(bottompos, y);
363                         
364                         
365                         break;
366                     default:
367                         return false;
368                 }
369                 // range of scroll -- can go up -- eg.. -ve value.
370                 
371             
372                 
373                 // to work out the max -ve number
374                 // height of filelayout
375                 // height of scrollactor..
376                 
377             /*
378                 if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {
379                     var nv =         _this.filelayout.el.y ;
380                     if (nv != -1 * (  last_child_bottom - this.el.height)) {
381                 
382                         _this.filelayout.el.y = -1 * (  last_child_bottom - this.el.height);
383                         return true;
384                     }
385                 
386                     return  false;
387                 }
388             
389             */
390                 
391                 
392             //    print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
393               //          last_child_bottom - this.el.height,
394                //         y));    
395                // y = float.min(0, y);    //??
396                // print("scroll event of %f  - new y = %f ".printf(event.y, y));
397                print("Set scroll to %f (lcb=%f / height = %f)\n", y, last_child_bottom, this.el.height);
398                
399                 _this.filelayout.el.y = y;
400                 return true;
401                       
402             });
403         }
404
405         // user defined functions
406     }
407     public class Xcls_filelayout : Object
408     {
409         public Clutter.Actor el;
410         private Xcls_ClutterFiles  _this;
411
412
413             // my vars (def)
414
415         // ctor
416         public Xcls_filelayout(Xcls_ClutterFiles _owner )
417         {
418             _this = _owner;
419             _this.filelayout = this;
420             this.el = new Clutter.Actor();
421
422             // my vars (dec)
423
424             // set gobject values
425             this.el.reactive = true;
426             var child_0 = new Xcls_filelayout_manager( _this );
427             child_0.ref();
428             this.el.layout_manager = child_0.el;
429
430             // init method
431
432             this.el.add_constraint(
433                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
434             );
435         }
436
437         // user defined functions
438     }
439     public class Xcls_filelayout_manager : Object
440     {
441         public Clutter.FlowLayout el;
442         private Xcls_ClutterFiles  _this;
443
444
445             // my vars (def)
446
447         // ctor
448         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
449         {
450             _this = _owner;
451             _this.filelayout_manager = this;
452             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
453
454             // my vars (dec)
455
456             // set gobject values
457             this.el.homogeneous = false;
458             this.el.max_column_width = 100.0f;
459             this.el.row_spacing = 20f;
460             this.el.column_spacing = 20f;
461         }
462
463         // user defined functions
464     }
465
466     public class Xcls_fileitem : Object
467     {
468         public Clutter.Actor el;
469         private Xcls_ClutterFiles  _this;
470
471
472             // my vars (def)
473         public JsRender.JsRender file;
474         public Xcls_image image;
475         public Xcls_typetitle typetitle;
476         public Xcls_title title;
477
478         // ctor
479         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
480         {
481             _this = _owner;
482             this.el = new Clutter.Actor();
483
484             // my vars (dec)
485
486             // set gobject values
487             this.el.reactive = true;
488             var child_0 = new Xcls_BoxLayout11( _this );
489             child_0.ref();
490             this.el.layout_manager = child_0.el;
491             var child_1 = new Xcls_image( _this ,file);
492             child_1.ref();
493             this.el.add_child (  child_1.el  );
494             this.image =  child_1;
495             var child_2 = new Xcls_typetitle( _this ,file);
496             child_2.ref();
497             this.el.add_child (  child_2.el  );
498             this.typetitle =  child_2;
499             var child_3 = new Xcls_title( _this ,file);
500             child_3.ref();
501             this.el.add_child (  child_3.el  );
502             this.title =  child_3;
503
504             // init method
505
506             this.file = file;
507             this.el.set_size(100,100);
508
509             //listeners
510             this.el.button_press_event.connect( (  event) => {
511                 _this.open(this.file);
512                 return false;
513             });
514             this.el.enter_event.connect( (  event)  => {
515                 this.el.background_color =   Clutter.Color.from_string("#333");
516                 this.title.el.background_color =   Clutter.Color.from_string("#fff");
517                 this.typetitle.el.background_color =   Clutter.Color.from_string("#fff");
518                 this.title.el.color =   Clutter.Color.from_string("#000");
519                 this.typetitle.el.color =   Clutter.Color.from_string("#000");
520                 
521                     return false;
522             });
523             this.el.leave_event.connect( (  event)  => {
524                 this.el.background_color =   Clutter.Color.from_string("#000");
525                  this.title.el.background_color =   Clutter.Color.from_string("#000");
526                 this.typetitle.el.background_color =   Clutter.Color.from_string("#000");
527                 this.title.el.color =   Clutter.Color.from_string("#fff");
528                 this.typetitle.el.color =   Clutter.Color.from_string("#fff");
529                
530                 
531                 return false;
532             });
533         }
534
535         // user defined functions
536     }
537     public class Xcls_BoxLayout11 : Object
538     {
539         public Clutter.BoxLayout el;
540         private Xcls_ClutterFiles  _this;
541
542
543             // my vars (def)
544
545         // ctor
546         public Xcls_BoxLayout11(Xcls_ClutterFiles _owner )
547         {
548             _this = _owner;
549             this.el = new Clutter.BoxLayout();
550
551             // my vars (dec)
552
553             // set gobject values
554             this.el.spacing = 4;
555             this.el.orientation = Clutter.Orientation.VERTICAL;
556         }
557
558         // user defined functions
559     }
560
561     public class Xcls_image : Object
562     {
563         public Clutter.Actor el;
564         private Xcls_ClutterFiles  _this;
565
566
567             // my vars (def)
568
569         // ctor
570         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
571         {
572             _this = _owner;
573             this.el = new Clutter.Actor();
574
575             // my vars (dec)
576
577             // set gobject values
578             this.el.margin_right = 5f;
579             this.el.margin_left = 5f;
580             this.el.x_align = Clutter.ActorAlign.START;
581             this.el.x_expand = false;
582             this.el.y_align = Clutter.ActorAlign.START;
583             this.el.margin_top = 5f;
584             this.el.y_expand = false;
585
586             // init method
587
588             {
589                 Gdk.Pixbuf pixbuf= null;
590                 
591                 var fname = file.getIconFileName(false);
592             
593                 try {
594                     if (FileUtils.test(fname, FileTest.EXISTS)) {
595                         pixbuf = new Gdk.Pixbuf.from_file(fname);
596                     } 
597                 } catch (Error e) {
598                     // noop
599                 
600                 }
601                 if (pixbuf == null) {
602                     
603                     try {
604                         if (_this.missing_thumb_pixbuf == null) {
605                                 var icon_theme = Gtk.IconTheme.get_default ();
606                                 _this.missing_thumb_pixbuf = icon_theme.load_icon ("package-x-generic", 92, 0);
607                                 _this.missing_thumb_pixbuf.ref();
608                             }
609                             pixbuf = _this.missing_thumb_pixbuf;
610             
611                     } catch (Error e) {
612                         // noop?
613                     }
614                 }
615                 try {
616                     var img = new Clutter.Image();
617                     img.set_data(pixbuf.get_pixels(),   
618                                         pixbuf.has_alpha 
619                                           ? Cogl.PixelFormat.RGBA_8888
620                                           : Cogl.PixelFormat.RGB_888,
621                                         pixbuf.get_width (),
622                             pixbuf.get_height (),
623                                         pixbuf.get_rowstride ()
624                     );
625                     this.el.set_content(img);
626                 } catch (Error e) {
627                     // noop?
628                 }
629                  // should probably do smarter scaling...
630                 
631                 
632                 this.el.set_size(90, 70);
633             }
634         }
635
636         // user defined functions
637     }
638
639     public class Xcls_typetitle : Object
640     {
641         public Clutter.Text el;
642         private Xcls_ClutterFiles  _this;
643
644
645             // my vars (def)
646
647         // ctor
648         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
649         {
650             _this = _owner;
651             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),  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     public class Xcls_title : Object
666     {
667         public Clutter.Text el;
668         private Xcls_ClutterFiles  _this;
669
670
671             // my vars (def)
672
673         // ctor
674         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
675         {
676             _this = _owner;
677             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),  Clutter.Color.from_string("#fff"));
678
679             // my vars (dec)
680
681             // set gobject values
682             this.el.x_align = Clutter.ActorAlign.START;
683             this.el.x_expand = false;
684             this.el.y_align = Clutter.ActorAlign.START;
685             this.el.y_expand = false;
686         }
687
688         // user defined functions
689     }
690
691
692     public class Xcls_folderitem : Object
693     {
694         public Clutter.Actor el;
695         private Xcls_ClutterFiles  _this;
696
697
698             // my vars (def)
699         public Xcls_foldertitle foldertitle;
700
701         // ctor
702         public Xcls_folderitem(Xcls_ClutterFiles _owner , string folderpath)
703         {
704             _this = _owner;
705             this.el = new Clutter.Actor();
706
707             // my vars (dec)
708
709             // set gobject values
710             this.el.reactive = true;
711             var child_0 = new Xcls_BoxLayout16( _this );
712             child_0.ref();
713             this.el.layout_manager = child_0.el;
714             var child_1 = new Xcls_foldertitle( _this ,folderpath);
715             child_1.ref();
716             this.el.add_child (  child_1.el  );
717             this.foldertitle =  child_1;
718
719             // init method
720
721             //this.el.set_size(100,100);
722         }
723
724         // user defined functions
725     }
726     public class Xcls_BoxLayout16 : Object
727     {
728         public Clutter.BoxLayout el;
729         private Xcls_ClutterFiles  _this;
730
731
732             // my vars (def)
733
734         // ctor
735         public Xcls_BoxLayout16(Xcls_ClutterFiles _owner )
736         {
737             _this = _owner;
738             this.el = new Clutter.BoxLayout();
739
740             // my vars (dec)
741
742             // set gobject values
743             this.el.spacing = 2;
744             this.el.orientation = Clutter.Orientation.VERTICAL;
745         }
746
747         // user defined functions
748     }
749
750     public class Xcls_foldertitle : Object
751     {
752         public Clutter.Text el;
753         private Xcls_ClutterFiles  _this;
754
755
756             // my vars (def)
757
758         // ctor
759         public Xcls_foldertitle(Xcls_ClutterFiles _owner , string folderpath)
760         {
761             _this = _owner;
762             this.el = new Clutter.Text.full("Sans bold 14px", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string("#fff"));
763
764             // my vars (dec)
765
766             // set gobject values
767             this.el.x_align = Clutter.ActorAlign.START;
768             this.el.x_expand = true;
769             this.el.y_align = Clutter.ActorAlign.START;
770             this.el.y_expand = false;
771         }
772
773         // user defined functions
774     }
775
776     public class Xcls_folderfile : Object
777     {
778         public Clutter.Text el;
779         private Xcls_ClutterFiles  _this;
780
781
782             // my vars (def)
783         public string filepath;
784
785         // ctor
786         public Xcls_folderfile(Xcls_ClutterFiles _owner , string filepath)
787         {
788             _this = _owner;
789             this.el = new Clutter.Text.full("Sans 10px", GLib.Path.get_basename(filepath),  Clutter.Color.from_string("#fff"));
790
791             // my vars (dec)
792
793             // set gobject values
794             this.el.x_align = Clutter.ActorAlign.START;
795             this.el.x_expand = true;
796             this.el.y_align = Clutter.ActorAlign.START;
797             this.el.reactive = true;
798             this.el.y_expand = false;
799
800             // init method
801
802             {
803                 this.filepath = filepath;
804             }
805
806             //listeners
807             this.el.button_press_event.connect( (  event) => {
808                // _this.open(this.filepath);
809                 return false;
810             });
811             this.el.enter_event.connect( (  event)  => {
812                 this.el.background_color =   Clutter.Color.from_string("#fff");
813                 this.el.color =  Clutter.Color.from_string("#000");
814                     return false;
815             });
816             this.el.leave_event.connect( (  event)  => {
817                 this.el.background_color =   Clutter.Color.from_string("#000");
818                  this.el.color =   Clutter.Color.from_string("#fff");
819                 return false;
820             });
821         }
822
823         // user defined functions
824     }
825
826
827
828
829 }