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