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