Builder4/ClutterFiles.bjs
[app.Builder.js] / Builder4 / ClutterFiles.vala
1 /* -- to compile
2 valac  --pkg gio-2.0  --pkg posix  --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0  --pkg  libwnck-3.0 \
3     /tmp/ClutterFiles.vala  -o /tmp/ClutterFiles
4 */
5
6
7 /* -- to test class
8 static int main (string[] args) {
9     Gtk.init (ref args);
10     new Xcls_ClutterFiles();
11     ClutterFiles.show_all();
12      Gtk.main ();
13     return 0;
14 }
15 */
16
17
18 public static Xcls_ClutterFiles  ClutterFiles;
19
20 public class Xcls_ClutterFiles : Object 
21 {
22     public Clutter.ScrollActor el;
23     private Xcls_ClutterFiles  _this;
24
25     public Xcls_filelayout filelayout;
26     public Xcls_filelayout_manager filelayout_manager;
27
28         // my vars
29     public signal void open(JsRender.JsRender file);
30
31         // ctor 
32     public Xcls_ClutterFiles()
33     {
34         _this = this;
35         ClutterFiles = this;
36         this.el = new Clutter.ScrollActor();
37
38         // my vars
39
40         // set gobject values
41         this.el.reactive = true;
42         var child_0 = new Xcls_filelayout( _this );
43         child_0.ref();
44         this.el.add_child (  child_0.el  );
45
46         // init method 
47         this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
48     }
49
50     // userdefined 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.clearFiles();
62             
63             print("clutter files - load project: " + pr.name +"\n");
64             // should unref.. them hopefully.
65             this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
66         
67             var fiter = pr.files.map_iterator();
68             while (fiter.next()) {
69                 var a = new Xcls_fileitem(this,fiter.get_value());
70                 this.fileitems.add(a);
71         
72         //        a.ref();
73                 print("add to clutter file view: " + fiter.get_value().name + "\n");
74                 this.filelayout.el.add_child(a.el);
75             }
76             this.el.show_all();
77         }
78     public void set_size(float w, float h) 
79         {
80              if (this.el == null) {
81                 print("object not ready yet?");
82                 return;
83             }
84            _this.filelayout_manager.el.max_column_width = w - 150;
85            this.el.set_size(this.el.get_stage().width-150,
86                                 this.el.get_stage().height);
87                     this.el.set_position(100,50);
88         }
89
90     // skip |xns - no return type
91     public class Xcls_filelayout : Object 
92     {
93         public Clutter.Actor el;
94         private Xcls_ClutterFiles  _this;
95
96
97             // my vars
98
99             // ctor 
100         public Xcls_filelayout(Xcls_ClutterFiles _owner )
101         {
102             _this = _owner;
103             _this.filelayout = this;
104             this.el = new Clutter.Actor();
105
106             // my vars
107
108             // set gobject values
109             this.el.reactive = true;
110             var child_0 = new Xcls_filelayout_manager( _this );
111             child_0.ref();
112             this.el.layout_manager = child_0.el;
113
114             // init method 
115             this.el.add_constraint(
116                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
117             );
118         }
119
120         // userdefined functions 
121
122         // skip |xns - no return type
123     }
124     public class Xcls_filelayout_manager : Object 
125     {
126         public Clutter.FlowLayout el;
127         private Xcls_ClutterFiles  _this;
128
129
130             // my vars
131
132             // ctor 
133         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
134         {
135             _this = _owner;
136             _this.filelayout_manager = this;
137             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
138
139             // my vars
140
141             // set gobject values
142             this.el.column_spacing = 20;
143             this.el.homogeneous = true;
144             this.el.row_spacing = 20;
145         }
146
147         // userdefined functions 
148
149         // skip |xns - no return type
150     }
151     public class Xcls_fileitem : Object 
152     {
153         public Clutter.Actor el;
154         private Xcls_ClutterFiles  _this;
155
156
157             // my vars
158         public JsRender.JsRender file;
159         public Xcls_image image;
160         public Xcls_typetitle typetitle;
161         public Xcls_title title;
162
163             // ctor 
164         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
165         {
166             _this = _owner;
167             this.el = new Clutter.Actor();
168
169             // my vars
170
171             // set gobject values
172             this.el.reactive = true;
173             var child_0 = new Xcls_BoxLayout5( _this );
174             child_0.ref();
175             this.el.layout_manager = child_0.el;
176             var child_1 = new Xcls_image( _this ,file);
177             child_1.ref();
178             this.el.add_child (  child_1.el  );
179             this.image =  child_1;
180             var child_2 = new Xcls_typetitle( _this ,file);
181             child_2.ref();
182             this.el.add_child (  child_2.el  );
183             this.typetitle =  child_2;
184             var child_3 = new Xcls_title( _this ,file);
185             child_3.ref();
186             this.el.add_child (  child_3.el  );
187             this.title =  child_3;
188
189             // init method 
190             this.file = file;
191             this.el.set_size(100,100);
192
193             // listeners 
194             this.el.enter_event.connect( (  event)  => {
195                 this.el.background_color = new Clutter.Color.from_string("#333");
196                     return false;
197             } );
198             this.el.leave_event.connect( (  event)  => {
199                 this.el.background_color = new Clutter.Color.from_string("#000");
200                 return false;
201             } );
202             this.el.button_press_event.connect(   (  event) => {
203                 _this.open(this.file);
204                 return false;
205             } );
206         }
207
208         // userdefined functions 
209
210         // skip |xns - no return type
211     }
212     public class Xcls_BoxLayout5 : Object 
213     {
214         public Clutter.BoxLayout el;
215         private Xcls_ClutterFiles  _this;
216
217
218             // my vars
219
220             // ctor 
221         public Xcls_BoxLayout5(Xcls_ClutterFiles _owner )
222         {
223             _this = _owner;
224             this.el = new Clutter.BoxLayout();
225
226             // my vars
227
228             // set gobject values
229             this.el.orientation = Clutter.Orientation.VERTICAL;
230             this.el.spacing = 4;
231         }
232
233         // userdefined functions 
234
235         // skip |xns - no return type
236     }
237     public class Xcls_image : Object 
238     {
239         public Clutter.Texture el;
240         private Xcls_ClutterFiles  _this;
241
242
243             // my vars
244
245             // ctor 
246         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
247         {
248             _this = _owner;
249             this.el = new Clutter.Texture.from_file(file.getIconFileName(true));
250
251             // my vars
252
253             // set gobject values
254             this.el.margin_left = 5;
255             this.el.margin_right = 5;
256             this.el.margin_top = 5;
257             this.el.x_align = Clutter.ActorAlign.START;
258             this.el.x_expand = true;
259             this.el.y_align = Clutter.ActorAlign.START;
260             this.el.y_expand = false;
261         }
262
263         // userdefined functions 
264
265         // skip |xns - no return type
266     }
267     public class Xcls_typetitle : Object 
268     {
269         public Clutter.Text el;
270         private Xcls_ClutterFiles  _this;
271
272
273             // my vars
274
275             // ctor 
276         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
277         {
278             _this = _owner;
279             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),new Clutter.Color.from_string("#fff"));
280
281             // my vars
282
283             // set gobject values
284             this.el.x_align = Clutter.ActorAlign.START;
285             this.el.x_expand = true;
286             this.el.y_align = Clutter.ActorAlign.START;
287             this.el.y_expand = false;
288         }
289
290         // userdefined functions 
291
292         // skip |xns - no return type
293     }
294     public class Xcls_title : Object 
295     {
296         public Clutter.Text el;
297         private Xcls_ClutterFiles  _this;
298
299
300             // my vars
301
302             // ctor 
303         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
304         {
305             _this = _owner;
306             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),new Clutter.Color.from_string("#fff"));
307
308             // my vars
309
310             // set gobject values
311             this.el.x_align = Clutter.ActorAlign.START;
312             this.el.x_expand = true;
313             this.el.y_align = Clutter.ActorAlign.START;
314             this.el.y_expand = false;
315         }
316
317         // userdefined functions 
318
319         // skip |xns - no return type
320     }
321 }