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