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