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