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