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