f90aa8d2f8358ae35b80c99b7fb88d4049fca597
[roobuilder] / src / Builder4 / ClutterFiles.vala
1 static Xcls_ClutterFiles  _ClutterFiles;
2
3 public class Xcls_ClutterFiles : Object
4 {
5     public Clutter.Actor el;
6     private Xcls_ClutterFiles  _this;
7
8     public static Xcls_ClutterFiles singleton()
9     {
10         if (_ClutterFiles == null) {
11             _ClutterFiles= new Xcls_ClutterFiles();
12         }
13         return _ClutterFiles;
14     }
15     public Xcls_project_title project_title;
16     public Xcls_project_title_manager project_title_manager;
17     public Xcls_project_title_name project_title_name;
18     public Xcls_project_title_path project_title_path;
19     public Xcls_scroller scroller;
20     public Xcls_filelayout filelayout;
21     public Xcls_filelayout_manager filelayout_manager;
22
23         // my vars (def)
24
25     // ctor
26     public Xcls_ClutterFiles()
27     {
28         _this = this;
29         this.el = new Clutter.Actor();
30
31         // my vars (dec)
32         var child_0 = new Xcls_project_title( _this );
33         child_0.ref();
34         this.el.add_child (  child_0.el  );
35         var child_1 = new Xcls_scroller( _this );
36         child_1.ref();
37         this.el.add_child (  child_1.el  );
38     }
39
40     // user defined functions
41     public void clearFiles () {
42         
43         this.filelayout.el.remove_all_children();
44         // we need to unref all the chidren that we loaded though...
45         
46     }
47     public void loadProject (Project.Project pr) {
48         // list all the files, and create new Xcls_fileitem for each one.
49         
50         this.project = pr;
51         
52         
53         // LEAK --- we should unref all the chilren...
54         this.filelayout.el.y = 0;
55         this.clearFiles();
56         
57         print("clutter files - load project: " + pr.name +"\n");
58         // should unref.. them hopefully.
59         
60         this.project_title_name.el.text = pr.name;
61         this.project_title_path.el.text = pr.firstPath();
62         
63         // file items contains a reference until we reload ...
64         this.fileitems = new Gee.ArrayList<Object>();
65     
66         
67     
68         var fiter = pr.sortedFiles().list_iterator();
69         while (fiter.next()) {
70             var a = new Xcls_fileitem(this,fiter.get());
71             this.fileitems.add(a);
72     
73     //        a.ref();
74             print("add to clutter file view: " + fiter.get().name + "\n");
75             this.filelayout.el.add_child(a.el);
76         }
77         
78         // folders...
79         
80         if (!(pr is Project.Gtk)) {
81             print ("not gtk... skipping files");
82             return;
83         }
84         var gpr = (Project.Gtk)pr;
85          var def = gpr.compilegroups.get("_default_");
86          // not sure why the above is returng null!??
87          if (def == null) {
88                 def = new Project.GtkValaSettings("_default_"); 
89                 gpr.compilegroups.set("_default_", def);
90          }
91          var items  = def.sources;
92                  
93                  
94          
95         for(var i =0 ; i < items.size; i++) {
96             print ("cheking folder %s\n", items.get(i));
97              var files = gpr.filesForOpen(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             this.fileitems.add(x);
105             this.filelayout.el.add_child(x.el);
106             
107             for(var j =0 ; j < files.size; j++) {
108                 print ("adding file %s\n", files.get(j));
109             
110                 var y = new Xcls_folderfile(this, files.get(j));
111                 this.fileitems.add(y);
112                 x.el.add_child(y.el);
113     
114                 // add file to files.get(j);
115                 
116             }
117             
118             
119             //this.el.set_value(citer, 1,   items.get(i) );
120         }
121          
122        
123         
124         this.el.show();
125     }
126     public void set_size (float w, float h) 
127     {
128         
129          // called by window resize... with is alreaddy -50 (for the buttons?)
130          
131     
132     
133     
134          if (this.el == null) {
135             print("object not ready yet?");
136             return;
137         }
138         
139         print("recv width %f, filelayoutw = %f", w, w-200);
140         
141         w = GLib.Math.floorf ( w/120.0f) * 120.0f;
142         
143         
144         
145         
146        //_this.filelayout_manager.el.max_column_width = w - 200;
147        _this.filelayout.el.width = w ;
148        
149         this.el.set_size(
150                // this.el.get_stage().width-150,
151                w,
152                h  // this.el.get_stage().height
153         );
154         
155         // 100 right for buttons ..
156         this.el.set_position(75,0);
157        
158        
159        this.scroller.el.set_size(
160                // this.el.get_stage().width-150,
161                w,
162                h  // this.el.get_stage().height
163         );
164         
165         // 100 right for buttons ..
166         this.scroller.el.set_position(0,50);
167         // scroll...
168         _this.filelayout.el.y = 0.0f;
169         
170     }
171     public class Xcls_project_title : Object
172     {
173         public Clutter.Actor el;
174         private Xcls_ClutterFiles  _this;
175
176
177             // my vars (def)
178
179         // ctor
180         public Xcls_project_title(Xcls_ClutterFiles _owner )
181         {
182             _this = _owner;
183             _this.project_title = this;
184             this.el = new Clutter.Actor();
185
186             // my vars (dec)
187             var child_0 = new Xcls_project_title_manager( _this );
188             child_0.ref();
189             this.el.layout_manager = child_0.el;
190             var child_1 = new Xcls_FixedLayout4( _this );
191             child_1.ref();
192             this.el.layout_manager = child_1.el;
193             var child_2 = new Xcls_project_title_name( _this );
194             child_2.ref();
195             this.el.add_child (  child_2.el  );
196             var child_3 = new Xcls_project_title_path( _this );
197             child_3.ref();
198             this.el.add_child (  child_3.el  );
199         }
200
201         // user defined functions
202     }
203     public class Xcls_project_title_manager : Object
204     {
205         public Clutter.FlowLayout el;
206         private Xcls_ClutterFiles  _this;
207
208
209             // my vars (def)
210
211         // ctor
212         public Xcls_project_title_manager(Xcls_ClutterFiles _owner )
213         {
214             _this = _owner;
215             _this.project_title_manager = this;
216             this.el = new Clutter.FlowLayout();
217
218             // my vars (dec)
219         }
220
221         // user defined functions
222     }
223
224     public class Xcls_FixedLayout4 : Object
225     {
226         public Clutter.FixedLayout el;
227         private Xcls_ClutterFiles  _this;
228
229
230             // my vars (def)
231
232         // ctor
233         public Xcls_FixedLayout4(Xcls_ClutterFiles _owner )
234         {
235             _this = _owner;
236             this.el = new Clutter.FixedLayout();
237
238             // my vars (dec)
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
262         // user defined functions
263     }
264
265     public class Xcls_project_title_path : Object
266     {
267         public Clutter.Text el;
268         private Xcls_ClutterFiles  _this;
269
270
271             // my vars (def)
272
273         // ctor
274         public Xcls_project_title_path(Xcls_ClutterFiles _owner )
275         {
276             _this = _owner;
277             _this.project_title_path = this;
278             this.el = new Clutter.Text.full("Sans 10px", "",  Clutter.Color.from_string("#ccc"));
279
280             // my vars (dec)
281         }
282
283         // user defined functions
284     }
285
286
287     public class Xcls_scroller : Object
288     {
289         public Clutter.ScrollActor el;
290         private Xcls_ClutterFiles  _this;
291
292
293             // my vars (def)
294
295         // ctor
296         public Xcls_scroller(Xcls_ClutterFiles _owner )
297         {
298             _this = _owner;
299             _this.scroller = this;
300             this.el = new Clutter.ScrollActor();
301
302             // my vars (dec)
303             var child_0 = new Xcls_filelayout( _this );
304             child_0.ref();
305             this.el.add_child (  child_0.el  );
306
307             //listeners
308             this.el.scroll_event.connect( ( event) => {
309                 print("scroll event\n");
310                 var y = _this.filelayout.el.y;
311                 var dir = event.direction;
312                 
313                 var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;
314                 var bottompos = -1 * (  last_child_bottom - (0.5f * this.el.height));
315                 
316                 switch (dir) {
317                     case Clutter.ScrollDirection.UP:
318                         print("Scroll up by %f\n", event.y);
319                         y += event.y /2;
320                         y = float.min(0, y); // 
321                         break;
322                         
323                     case Clutter.ScrollDirection.DOWN:
324                         print("Scroll down by %f\n", event.y);
325                         y -= event.y /2 ;
326                         y = float.max(bottompos, y);
327                         
328                         
329                         break;
330                           case Clutter.ScrollDirection.SMOOTH:
331                             double delta_x, delta_y;
332                             event.get_scroll_delta(out delta_x, out delta_y);
333                         //print("Scroll SMOOTH? by %f\n",  delta_y * event.y);
334                         y += ((float)delta_y * event.y * -1.0f) /2 ;
335                         y = float.max(bottompos, y);
336                         y = float.min(0, y); // 
337                                    
338                         break;
339                     default:
340                         print("scroll event = bad direction %s\n", dir.to_string());
341                         return false;
342                 }
343                 // range of scroll -- can go up -- eg.. -ve value.
344                 
345             
346                 
347                print("Set scroll to %f (lcb=%f / height = %f)\n", y, last_child_bottom, this.el.height);
348                
349                 _this.filelayout.el.y = y;
350                 return true;
351                       
352             });
353         }
354
355         // user defined functions
356     }
357     public class Xcls_filelayout : Object
358     {
359         public Clutter.Actor el;
360         private Xcls_ClutterFiles  _this;
361
362
363             // my vars (def)
364
365         // ctor
366         public Xcls_filelayout(Xcls_ClutterFiles _owner )
367         {
368             _this = _owner;
369             _this.filelayout = this;
370             this.el = new Clutter.Actor();
371
372             // my vars (dec)
373             var child_0 = new Xcls_filelayout_manager( _this );
374             child_0.ref();
375             this.el.layout_manager = child_0.el;
376         }
377
378         // user defined functions
379     }
380     public class Xcls_filelayout_manager : Object
381     {
382         public Clutter.FlowLayout el;
383         private Xcls_ClutterFiles  _this;
384
385
386             // my vars (def)
387
388         // ctor
389         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
390         {
391             _this = _owner;
392             _this.filelayout_manager = this;
393             this.el = new Clutter.FlowLayout();
394
395             // my vars (dec)
396         }
397
398         // user defined functions
399     }
400
401     public class Xcls_fileitem : Object
402     {
403         public Clutter.Actor el;
404         private Xcls_ClutterFiles  _this;
405
406
407             // my vars (def)
408         public Xcls_image image;
409         public Xcls_typetitle typetitle;
410         public Xcls_title title;
411
412         // ctor
413         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
414         {
415             _this = _owner;
416             this.el = new Clutter.Actor();
417
418             // my vars (dec)
419             var child_0 = new Xcls_BoxLayout11( _this );
420             child_0.ref();
421             this.el.layout_manager = child_0.el;
422             var child_1 = new Xcls_image( _this ,file);
423             child_1.ref();
424             this.el.add_child (  child_1.el  );
425             this.image =  child_1;
426             var child_2 = new Xcls_typetitle( _this ,file);
427             child_2.ref();
428             this.el.add_child (  child_2.el  );
429             this.typetitle =  child_2;
430             var child_3 = new Xcls_title( _this ,file);
431             child_3.ref();
432             this.el.add_child (  child_3.el  );
433             this.title =  child_3;
434
435             //listeners
436             this.el.button_press_event.connect( ( event ) => {
437                 _this.open(this.file);
438                 return false;
439             });
440             this.el.enter_event.connect( (  event)  => {
441                 this.el.background_color =   Clutter.Color.from_string("#333");
442                 this.title.el.background_color =   Clutter.Color.from_string("#fff");
443                 this.typetitle.el.background_color =   Clutter.Color.from_string("#fff");
444                 this.title.el.color =   Clutter.Color.from_string("#000");
445                 this.typetitle.el.color =   Clutter.Color.from_string("#000");
446                 
447                     return false;
448             });
449             this.el.leave_event.connect( (  event)  => {
450                 this.el.background_color =   Clutter.Color.from_string("#000");
451                  this.title.el.background_color =   Clutter.Color.from_string("#000");
452                 this.typetitle.el.background_color =   Clutter.Color.from_string("#000");
453                 this.title.el.color =   Clutter.Color.from_string("#fff");
454                 this.typetitle.el.color =   Clutter.Color.from_string("#fff");
455                
456                 
457                 return false;
458             });
459         }
460
461         // user defined functions
462     }
463     public class Xcls_BoxLayout11 : Object
464     {
465         public Clutter.BoxLayout el;
466         private Xcls_ClutterFiles  _this;
467
468
469             // my vars (def)
470
471         // ctor
472         public Xcls_BoxLayout11(Xcls_ClutterFiles _owner )
473         {
474             _this = _owner;
475             this.el = new Clutter.BoxLayout();
476
477             // my vars (dec)
478         }
479
480         // user defined functions
481     }
482
483     public class Xcls_image : Object
484     {
485         public Clutter.Actor el;
486         private Xcls_ClutterFiles  _this;
487
488
489             // my vars (def)
490
491         // ctor
492         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
493         {
494             _this = _owner;
495             this.el = new Clutter.Actor();
496
497             // my vars (dec)
498         }
499
500         // user defined functions
501     }
502
503     public class Xcls_typetitle : Object
504     {
505         public Clutter.Text el;
506         private Xcls_ClutterFiles  _this;
507
508
509             // my vars (def)
510
511         // ctor
512         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
513         {
514             _this = _owner;
515             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),  Clutter.Color.from_string("#fff"));
516
517             // my vars (dec)
518         }
519
520         // user defined functions
521     }
522
523     public class Xcls_title : Object
524     {
525         public Clutter.Text el;
526         private Xcls_ClutterFiles  _this;
527
528
529             // my vars (def)
530
531         // ctor
532         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
533         {
534             _this = _owner;
535             this.el = new Clutter.Text.full("Sans 10px", file.nickNameSplit(),  Clutter.Color.from_string("#fff"));
536
537             // my vars (dec)
538         }
539
540         // user defined functions
541     }
542
543
544     public class Xcls_folderitem : Object
545     {
546         public Clutter.Actor el;
547         private Xcls_ClutterFiles  _this;
548
549
550             // my vars (def)
551         public Xcls_foldertitle foldertitle;
552
553         // ctor
554         public Xcls_folderitem(Xcls_ClutterFiles _owner , string folderpath)
555         {
556             _this = _owner;
557             this.el = new Clutter.Actor();
558
559             // my vars (dec)
560             var child_0 = new Xcls_BoxLayout16( _this );
561             child_0.ref();
562             this.el.layout_manager = child_0.el;
563             var child_1 = new Xcls_foldertitle( _this ,folderpath);
564             child_1.ref();
565             this.el.add_child (  child_1.el  );
566             this.foldertitle =  child_1;
567         }
568
569         // user defined functions
570     }
571     public class Xcls_BoxLayout16 : Object
572     {
573         public Clutter.BoxLayout el;
574         private Xcls_ClutterFiles  _this;
575
576
577             // my vars (def)
578
579         // ctor
580         public Xcls_BoxLayout16(Xcls_ClutterFiles _owner )
581         {
582             _this = _owner;
583             this.el = new Clutter.BoxLayout();
584
585             // my vars (dec)
586         }
587
588         // user defined functions
589     }
590
591     public class Xcls_foldertitle : Object
592     {
593         public Clutter.Text el;
594         private Xcls_ClutterFiles  _this;
595
596
597             // my vars (def)
598
599         // ctor
600         public Xcls_foldertitle(Xcls_ClutterFiles _owner , string folderpath)
601         {
602             _this = _owner;
603             this.el = new Clutter.Text.full("Sans bold 14px", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string("#fff"));
604
605             // my vars (dec)
606         }
607
608         // user defined functions
609     }
610
611     public class Xcls_folderfile : Object
612     {
613         public Clutter.Text el;
614         private Xcls_ClutterFiles  _this;
615
616
617             // my vars (def)
618
619         // ctor
620         public Xcls_folderfile(Xcls_ClutterFiles _owner , string filepath)
621         {
622             _this = _owner;
623             this.el = new Clutter.Text.full("Sans 10px", GLib.Path.get_basename(filepath),  Clutter.Color.from_string("#fff"));
624
625             // my vars (dec)
626
627             //listeners
628             this.el.button_press_event.connect( (  event) => {
629                 
630                var f = JsRender.JsRender.factory("PlainFile", _this.project, this.filepath);
631                 _this.open(f);
632                 return false;
633             });
634             this.el.enter_event.connect( (  event)  => {
635                 this.el.background_color =   Clutter.Color.from_string("#fff");
636                 this.el.color =  Clutter.Color.from_string("#000");
637                     return false;
638             });
639             this.el.leave_event.connect( (  event)  => {
640                 this.el.background_color =   Clutter.Color.from_string("#000");
641                  this.el.color =   Clutter.Color.from_string("#fff");
642                 return false;
643             });
644         }
645
646         // user defined functions
647     }
648
649
650
651
652 }