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