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