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