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