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