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