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