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