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