bfea38aff9461837e8eef52fe63ae30598ea90fc
[roobuilder] / src / Builder4 / ClutterFiles.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
6    "# Gee.ArrayList<Object> fileitems" : "new Gee.ArrayList<Object>()",
7    "$ xns" : "Clutter",
8    "@ void open" : "(JsRender.JsRender file)",
9    "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
10    "Project.Project project" : "",
11    "bool reactive" : true,
12    "id" : "ClutterFiles",
13    "items" : [
14     {
15      "$ reactive" : true,
16      "$ xns" : "Clutter",
17      "* init" : [
18       "",
19       "this.el.add_constraint(",
20       "    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)",
21       ");",
22       "this.el.set_position(0,0);",
23       " "
24      ],
25      "* pack" : "add_child",
26      "id" : "project_title",
27      "items" : [
28       {
29        "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
30        "$ xns" : "Clutter",
31        "* prop" : "layout_manager",
32        "boolean homogeneous" : false,
33        "column_spacing" : 20,
34        "id" : "project_title_manager",
35        "row_spacing" : 5,
36        "xtype" : "FlowLayout"
37       },
38       {
39        "$ xns" : "Clutter",
40        "* prop" : "layout_manager",
41        "xtype" : "FixedLayout"
42       },
43       {
44        "$ xns" : "Clutter",
45        "* ctor" : "new Clutter.Text.full(\"Sans 20px\", \"\",  Clutter.Color.from_string(\"#eee\"))",
46        "* pack" : "add_child",
47        "boolean x_expand" : false,
48        "float x" : "0.0f",
49        "float y" : "10.0f",
50        "id" : "project_title_name",
51        "xtype" : "Text"
52       },
53       {
54        "$ xns" : "Clutter",
55        "* ctor" : "new Clutter.Text.full(\"Sans 10px\", \"\",  Clutter.Color.from_string(\"#ccc\"))",
56        "* pack" : "add_child",
57        "float x" : "0.0f",
58        "float y" : "35.0f",
59        "id" : "project_title_path",
60        "xtype" : "Text"
61       }
62      ],
63      "xtype" : "Actor"
64     },
65     {
66      "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
67      "# Gee.ArrayList<Xcls_fileitem> fileitems" : "new Gee.ArrayList<Xcls_fileitem>()",
68      "$ xns" : "Clutter",
69      "* pack" : "add_child",
70      "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
71      "bool reactive" : true,
72      "id" : "scroller",
73      "items" : [
74       {
75        "$ reactive" : true,
76        "$ xns" : "Clutter",
77        "* init" : [
78         "",
79         "this.el.add_constraint(",
80         "    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)",
81         ");",
82         "",
83         " "
84        ],
85        "* pack" : "add_child",
86        "id" : "filelayout",
87        "items" : [
88         {
89          "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
90          "$ xns" : "Clutter",
91          "* prop" : "layout_manager",
92          "bool homogeneous" : false,
93          "column_spacing" : 20,
94          "float max_column_width" : "100.0f",
95          "id" : "filelayout_manager",
96          "row_spacing" : 20,
97          "xtype" : "FlowLayout"
98         },
99         {
100          "# JsRender.JsRender file" : "",
101          "$ reactive" : true,
102          "$ xns" : "Clutter",
103          "* args" : "JsRender.JsRender file",
104          "* init" : [
105           "this.file = file;",
106           "this.el.set_size(100,100);"
107          ],
108          "* pack" : true,
109          "id" : "*fileitem",
110          "items" : [
111           {
112            "$ xns" : "Clutter",
113            "* prop" : "layout_manager",
114            "orientation" : "Clutter.Orientation.VERTICAL",
115            "spacing" : 4,
116            "xtype" : "BoxLayout"
117           },
118           {
119            "$ margin_left" : 5,
120            "$ margin_right" : 5,
121            "$ margin_top" : 5,
122            "$ x_align" : "Clutter.ActorAlign.START",
123            "$ xns" : "Clutter",
124            "$ y_align" : "Clutter.ActorAlign.START",
125            "* args" : "JsRender.JsRender file",
126            "* init" : [
127             "{",
128             "    Gdk.Pixbuf pixbuf= null;",
129             "    ",
130             "    var fname = file.getIconFileName(false);",
131             "",
132             "    try {",
133             "        if (FileUtils.test(fname, FileTest.EXISTS)) {",
134             "            pixbuf = new Gdk.Pixbuf.from_file(fname);",
135             "        } ",
136             "    } catch (Error e) {",
137             "        // noop",
138             "    ",
139             "    }",
140             "    if (pixbuf == null) {",
141             "        ",
142             "        try {",
143             "            if (_this.missing_thumb_pixbuf == null) {",
144             "                    var icon_theme = Gtk.IconTheme.get_default ();",
145             "                    _this.missing_thumb_pixbuf = icon_theme.load_icon (\"package-x-generic\", 92, 0);",
146             "                    _this.missing_thumb_pixbuf.ref();",
147             "                }",
148             "                pixbuf = _this.missing_thumb_pixbuf;",
149             "",
150             "        } catch (Error e) {",
151             "            // noop?",
152             "        }",
153             "    }",
154             "    try {",
155             "        var img = new Clutter.Image();",
156             "        img.set_data(pixbuf.get_pixels(),   ",
157             "                            pixbuf.has_alpha ",
158             "                              ? Cogl.PixelFormat.RGBA_8888",
159             "                              : Cogl.PixelFormat.RGB_888,",
160             "                            pixbuf.get_width (),",
161             "                pixbuf.get_height (),",
162             "                            pixbuf.get_rowstride ()",
163             "        );",
164             "        this.el.set_content(img);",
165             "    } catch (Error e) {",
166             "        // noop?",
167             "    }",
168             "     // should probably do smarter scaling...",
169             "    ",
170             "    ",
171             "    this.el.set_size(90, 70);",
172             "}",
173             ""
174            ],
175            "* pack" : "add_child",
176            "bool x_expand" : false,
177            "bool y_expand" : false,
178            "id" : "+image",
179            "xtype" : "Actor"
180           },
181           {
182            "$ x_align" : "Clutter.ActorAlign.START",
183            "$ xns" : "Clutter",
184            "$ y_align" : "Clutter.ActorAlign.START",
185            "* args" : "JsRender.JsRender file",
186            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickType(),  Clutter.Color.from_string(\"#fff\"))",
187            "* pack" : "add_child",
188            "bool x_expand" : false,
189            "bool y_expand" : false,
190            "id" : "+typetitle",
191            "xtype" : "Text"
192           },
193           {
194            "$ x_align" : "Clutter.ActorAlign.START",
195            "$ xns" : "Clutter",
196            "$ y_align" : "Clutter.ActorAlign.START",
197            "* args" : "JsRender.JsRender file",
198            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickNameSplit(),  Clutter.Color.from_string(\"#fff\"))",
199            "* pack" : "add_child",
200            "bool x_expand" : false,
201            "bool y_expand" : false,
202            "id" : "+title",
203            "xtype" : "Text"
204           }
205          ],
206          "listeners" : {
207           "button_press_event" : [
208            "  ( event ) => {",
209            "    _this.open(this.file);",
210            "    return false;",
211            "} "
212           ],
213           "enter_event" : [
214            "(  event)  => {",
215            "    this.el.background_color =   Clutter.Color.from_string(\"#333\");",
216            "    this.title.el.background_color =   Clutter.Color.from_string(\"#fff\");",
217            "    this.typetitle.el.background_color =   Clutter.Color.from_string(\"#fff\");",
218            "    this.title.el.color =   Clutter.Color.from_string(\"#000\");",
219            "    this.typetitle.el.color =   Clutter.Color.from_string(\"#000\");",
220            "    ",
221            "        return false;",
222            "}"
223           ],
224           "leave_event" : [
225            "(  event)  => {",
226            "    this.el.background_color =   Clutter.Color.from_string(\"#000\");",
227            "     this.title.el.background_color =   Clutter.Color.from_string(\"#000\");",
228            "    this.typetitle.el.background_color =   Clutter.Color.from_string(\"#000\");",
229            "    this.title.el.color =   Clutter.Color.from_string(\"#fff\");",
230            "    this.typetitle.el.color =   Clutter.Color.from_string(\"#fff\");",
231            "   ",
232            "    ",
233            "    return false;",
234            "}"
235           ]
236          },
237          "xtype" : "Actor"
238         },
239         {
240          "$ reactive" : true,
241          "$ xns" : "Clutter",
242          "* args" : "string folderpath",
243          "* init" : [
244           " ",
245           "//this.el.set_size(100,100);"
246          ],
247          "* pack" : true,
248          "id" : "*folderitem",
249          "items" : [
250           {
251            "$ xns" : "Clutter",
252            "* prop" : "layout_manager",
253            "orientation" : "Clutter.Orientation.VERTICAL",
254            "spacing" : 2,
255            "xtype" : "BoxLayout"
256           },
257           {
258            "$ x_align" : "Clutter.ActorAlign.START",
259            "$ x_expand" : true,
260            "$ xns" : "Clutter",
261            "$ y_align" : "Clutter.ActorAlign.START",
262            "* args" : "string folderpath",
263            "* ctor" : "new Clutter.Text.full(\"Sans bold 14px\", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string(\"#fff\"))",
264            "* pack" : "add_child",
265            "bool y_expand" : false,
266            "id" : "+foldertitle",
267            "xtype" : "Text"
268           },
269           {
270            "$ xns" : "Clutter",
271            "* args" : "string filepath",
272            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", GLib.Path.get_basename(filepath),  Clutter.Color.from_string(\"#fff\"))",
273            "* init" : [
274             "{",
275             "\tthis.filepath = filepath;",
276             "}",
277             ""
278            ],
279            "Clutter.ActorAlign x_align" : "Clutter.ActorAlign.START",
280            "Clutter.ActorAlign y_align" : "Clutter.ActorAlign.START",
281            "bool reactive" : true,
282            "bool x_expand" : true,
283            "bool y_expand" : true,
284            "id" : "*folderfile",
285            "listeners" : {
286             "button_press_event" : [
287              "  (  event) => {",
288              "    ",
289              "   var f = JsRender.JsRender.factory(\"PlainFile\", _this.project, this.filepath);",
290              "    _this.open(f);",
291              "    return false;",
292              "} "
293             ],
294             "enter_event" : [
295              "(  event)  => {",
296              "    this.el.background_color =   Clutter.Color.from_string(\"#fff\");",
297              "    this.el.color =  Clutter.Color.from_string(\"#000\");",
298              "        return false;",
299              "}"
300             ],
301             "leave_event" : [
302              "(  event)  => {",
303              "    this.el.background_color =   Clutter.Color.from_string(\"#000\");",
304              "     this.el.color =   Clutter.Color.from_string(\"#fff\");",
305              "    return false;",
306              "}"
307             ]
308            },
309            "string filepath" : "",
310            "xtype" : "Text"
311           }
312          ],
313          "xtype" : "Actor"
314         }
315        ],
316        "xtype" : "Actor"
317       }
318      ],
319      "listeners" : {
320       "scroll_event" : [
321        "( event) => {",
322        "    print(\"scroll event\\n\");",
323        "    var y = _this.filelayout.el.y;",
324        "    var dir = event.direction;",
325        "    ",
326        "    var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;",
327        "    var bottompos = -1 * (  last_child_bottom - (0.5f * this.el.height));",
328        "    ",
329        "    switch (dir) {",
330        "        case Clutter.ScrollDirection.UP:",
331        "            print(\"Scroll up by %f\\n\", event.y);",
332        "            y += event.y /2;",
333        "            y = float.min(0, y); // ",
334        "            break;",
335        "            ",
336        "        case Clutter.ScrollDirection.DOWN:",
337        "            print(\"Scroll down by %f\\n\", event.y);",
338        "            y -= event.y /2 ;",
339        "            y = float.max(bottompos, y);",
340        "            ",
341        "            ",
342        "            break;",
343        "     \t  case Clutter.ScrollDirection.SMOOTH:",
344        "     \t    double delta_x, delta_y;",
345        "     \t    event.get_scroll_delta(out delta_x, out delta_y);",
346        "            //print(\"Scroll SMOOTH? by %f\\n\",  delta_y * event.y);",
347        "            y += ((float)delta_y * event.y * -1.0f) /2 ;",
348        "            y = float.max(bottompos, y);",
349        "            y = float.min(0, y); // ",
350        "                       ",
351        "            break;",
352        "        default:",
353        "\t        print(\"scroll event = bad direction %s\\n\", dir.to_string());",
354        "            return false;",
355        "    }",
356        "    // range of scroll -- can go up -- eg.. -ve value.",
357        "    ",
358        "",
359        "    ",
360        "   print(\"Set scroll to %f (lcb=%f / height = %f)\\n\", y, last_child_bottom, this.el.height);",
361        "   ",
362        "    _this.filelayout.el.y = y;",
363        "    return true;",
364        "          ",
365        "}"
366       ]
367      },
368      "xtype" : "ScrollActor"
369     }
370    ],
371    "xtype" : "Actor",
372    "| void clearFiles" : [
373     "() {",
374     "    ",
375     "    this.filelayout.el.remove_all_children();",
376     "    // we need to unref all the chidren that we loaded though...",
377     "    ",
378     "}",
379     " "
380    ],
381    "| void loadProject" : [
382     "(Project.Project pr) {",
383     "    // list all the files, and create new Xcls_fileitem for each one.",
384     "    ",
385     "    this.project = pr;",
386     "    ",
387     "    ",
388     "    // LEAK --- we should unref all the chilren...",
389     "    this.filelayout.el.y = 0;",
390     "    this.clearFiles();",
391     "    ",
392     "    print(\"clutter files - load project: \" + pr.name +\"\\n\");",
393     "    // should unref.. them hopefully.",
394     "    ",
395     "    this.project_title_name.el.text = pr.name;",
396     "    this.project_title_path.el.text = pr.firstPath();",
397     "    ",
398     "    // file items contains a reference until we reload ...",
399     "    this.fileitems = new Gee.ArrayList<Object>();",
400     "",
401     "    ",
402     "",
403     "    var fiter = pr.sortedFiles().list_iterator();",
404     "    while (fiter.next()) {",
405     "        var a = new Xcls_fileitem(this,fiter.get());",
406     "        this.fileitems.add(a);",
407     "",
408     "//        a.ref();",
409     "        print(\"add to clutter file view: \" + fiter.get().name + \"\\n\");",
410     "        this.filelayout.el.add_child(a.el);",
411     "    }",
412     "    ",
413     "    // folders...",
414     "    ",
415     "    if (!(pr is Project.Gtk)) {",
416     "        print (\"not gtk... skipping files\");",
417     "        return;",
418     "    }",
419     "    var gpr = (Project.Gtk)pr;",
420     "     var def = gpr.compilegroups.get(\"_default_\");",
421     "     // not sure why the above is returng null!??",
422     "     if (def == null) {",
423     " \t\tdef = new Project.GtkValaSettings(\"_default_\"); ",
424     " \t\tgpr.compilegroups.set(\"_default_\", def);",
425     "     }",
426     "\t var items  = def.sources;",
427     "\t\t ",
428     "\t\t ",
429     "\t ",
430     "\tfor(var i =0 ; i < items.size; i++) {",
431     "\t    print (\"cheking folder %s\\n\", items.get(i));",
432     "\t     var files = gpr.filesForOpen(items.get(i));",
433     "\t     if (files.size < 1) {",
434     "\t        continue;",
435     "\t     }",
436     "",
437     "\t    // add the directory... items.get(i);",
438     "\t    var x = new Xcls_folderitem(this,items.get(i));",
439     "\t    this.fileitems.add(x);",
440     "\t    this.filelayout.el.add_child(x.el);",
441     "\t    ",
442     "\t    for(var j =0 ; j < files.size; j++) {",
443     "\t        print (\"adding file %s\\n\", files.get(j));",
444     "\t    ",
445     "\t        var y = new Xcls_folderfile(this, files.get(j));",
446     "\t        this.fileitems.add(y);",
447     "\t        x.el.add_child(y.el);",
448     "",
449     "\t        // add file to files.get(j);",
450     "\t        ",
451     "\t    }",
452     "\t    ",
453     "\t    ",
454     "\t    //this.el.set_value(citer, 1,   items.get(i) );",
455     "\t}",
456     "     ",
457     "   ",
458     "    ",
459     "    this.el.show();",
460     "}",
461     ""
462    ],
463    "| void set_size" : [
464     "(float w, float h) ",
465     "{",
466     "    ",
467     "     // called by window resize... with is alreaddy -50 (for the buttons?)",
468     "     ",
469     "",
470     "",
471     "",
472     "     if (this.el == null) {",
473     "        print(\"object not ready yet?\");",
474     "        return;",
475     "    }",
476     "    ",
477     "    print(\"recv width %f, filelayoutw = %f\", w, w-200);",
478     "    ",
479     "    w = GLib.Math.floorf ( w/120.0f) * 120.0f;",
480     "    ",
481     "    ",
482     "    ",
483     "    ",
484     "   //_this.filelayout_manager.el.max_column_width = w - 200;",
485     "   _this.filelayout.el.width = w ;",
486     "   ",
487     "    this.el.set_size(",
488     "           // this.el.get_stage().width-150,",
489     "           w,",
490     "           h  // this.el.get_stage().height",
491     "    );",
492     "    ",
493     "    // 100 right for buttons ..",
494     "    this.el.set_position(75,0);",
495     "   ",
496     "   ",
497     "   this.scroller.el.set_size(",
498     "           // this.el.get_stage().width-150,",
499     "           w,",
500     "           h  // this.el.get_stage().height",
501     "    );",
502     "    ",
503     "    // 100 right for buttons ..",
504     "    this.scroller.el.set_position(0,50);",
505     "    // scroll...",
506     "    _this.filelayout.el.y = 0.0f;",
507     "    ",
508     "}",
509     ""
510    ]
511   }
512  ],
513  "modOrder" : "",
514  "name" : "ClutterFiles",
515  "parent" : "",
516  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/ClutterFiles.bjs",
517  "permname" : "",
518  "title" : ""
519 }