4831be015f351db99dc8c221c8cf578b53356016
[app.Builder.js] / Builder4 / ClutterFiles.bjs
1 {
2     "name" : "ClutterFiles",
3     "parent" : "",
4     "title" : "",
5     "path" : "/home/alan/gitlive/app.Builder.js/Builder4/ClutterFiles.bjs",
6     "permname" : "",
7     "modOrder" : "",
8     "items" : [
9         {
10             "listeners" : {
11                 "scroll_event" : "( event) => {\n   //Sprint(\"scroll event\");\n            var y = this.filelayout.el.y;\n            var dir = event.direction;\n            switch (dir) {\n                case Clutter.ScrollDirection.UP:\n                    y += event.y /2;\n                    break;\n                case Clutter.ScrollDirection.DOWN:\n                    y -= event.y /2 ;\n                    break;\n                default:\n                    return false;\n            }\n            // range of scroll -- can go up -- eg.. -ve value.\n            \n            y = float.min(0, y);\n            \n            // to work out the max -ve number\n            // height of filelayout\n            // height of scrollactor..\n            \n            var last_child_bottom = this.filelayout.el.last_child.y +  this.filelayout.el.last_child.height;\n             if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {\n                return  false;\n            }\n        \n        \n            \n            \n        //    print(\"\\nlast child - this height = %f  ==== new y %f\\n \".printf( \n          //          last_child_bottom - this.el.height,\n           //         y));    \n           // y = float.min(0, y);    //??\n           // print(\"scroll event of %f  - new y = %f \".printf(event.y, y));\n            this.filelayout.el.y = y;\n            return true;\n          \n}"
12             },
13             "# Gee.ArrayList<Xcls_fileitem> fileitems" : "",
14             "id" : "ClutterFiles",
15             "|  void clearFiles" : "() {\n    \n    this.filelayout.el.remove_all_children();\n    // we need to unref all the chidren that we loaded though...\n    \n}\n",
16             "scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
17             "* init" : "this.fileitems = new Gee.ArrayList<Xcls_fileitem>();\n",
18             "xtype" : "ScrollActor",
19             "$ reactive" : true,
20             "|  void loadProject" : "(Project.Project pr) {\n    // list all the files, and create new Xcls_fileitem for each one.\n    \n    // LEAK --- we should unref all the chilren...\n    this.filelayout.el.y = 0;\n    this.clearFiles();\n    \n    print(\"clutter files - load project: \" + pr.name +\"\\n\");\n    // should unref.. them hopefully.\n    this.fileitems = new Gee.ArrayList<Xcls_fileitem>();\n\n    \n\n    var fiter = pr.sortedFiles().list_iterator();\n    while (fiter.next()) {\n        var a = new Xcls_fileitem(this,fiter.get());\n        this.fileitems.add(a);\n\n//        a.ref();\n        print(\"add to clutter file view: \" + fiter.get().name + \"\\n\");\n        this.filelayout.el.add_child(a.el);\n    }\n    \n   \n    \n    this.el.show_all();\n}\n",
21             "@ void open" : "(JsRender.JsRender file)",
22             "$ xns" : "Clutter",
23             "|  void set_size" : "(float w, float h) \n{\n     if (this.el == null) {\n        print(\"object not ready yet?\");\n        return;\n    }\n   _this.filelayout_manager.el.max_column_width = w - 150;\n   this.el.set_size(this.el.get_stage().width-150,\n                        this.el.get_stage().height);\n            this.el.set_position(100,50);\n}\n",
24             "items" : [
25                 {
26                     "id" : "filelayout",
27                     "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\n\n",
28                     "xtype" : "Actor",
29                     "* pack" : "add_child",
30                     "$ reactive" : true,
31                     "$ xns" : "Clutter",
32                     "items" : [
33                         {
34                             "id" : "filelayout_manager",
35                             "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
36                             "xtype" : "FlowLayout",
37                             "$ xns" : "Clutter",
38                             "row_spacing" : 20,
39                             "* prop" : "layout_manager",
40                             "column_spacing" : 20,
41                             "$ homogeneous" : true
42                         },
43                         {
44                             "listeners" : {
45                                 "button_press_event" : "  (  event) => {\n    _this.open(this.file);\n    return false;\n}",
46                                 "enter_event" : "(  event)  => {\n    this.el.background_color = new Clutter.Color.from_string(\"#333\");\n        return false;\n}",
47                                 "leave_event" : "(  event)  => {\n    this.el.background_color = new Clutter.Color.from_string(\"#000\");\n    return false;\n}"
48                             },
49                             "id" : "*fileitem",
50                             "* args" : "JsRender.JsRender file",
51                             "* init" : "this.file = file;\nthis.el.set_size(100,100);",
52                             "* pack" : true,
53                             "xtype" : "Actor",
54                             "# JsRender.JsRender file" : "",
55                             "$ reactive" : true,
56                             "$ xns" : "Clutter",
57                             "items" : [
58                                 {
59                                     "$ orientation" : "Clutter.Orientation.VERTICAL",
60                                     "spacing" : 4,
61                                     "xtype" : "BoxLayout",
62                                     "$ xns" : "Clutter",
63                                     "* prop" : "layout_manager"
64                                 },
65                                 {
66                                     "$ margin_right" : 5,
67                                     "$ margin_top" : 5,
68                                     "id" : "+image",
69                                     "* args" : "JsRender.JsRender file",
70                                     "* init" : "{\n    Gdk.Pixbuf pixbuf;\n    var fname = file.getIconFileName(false);\n\n    if (FileUtils.test(fname, FileTest.EXISTS)) {\n        pixbuf = new Gdk.Pixbuf.from_file(fname);\n    } else {\n        if (_this.missing_thumb_pixbuf == null) {\n                var     icon_theme = Gtk.IconTheme.get_default ();\n                _this.missing_thumb_pixbuf = icon_theme.load_icon (\"package-x-generic\", 92, 0);\n                _this.missing_thumb_pixbuf.ref();\n            }\n            pixbuf = _this.missing_thumb_pixbuf;\n\n    }\n\n    var img = new Clutter.Image();\n    img.set_data(pixbuf.get_pixels(),   \n                        pixbuf.has_alpha \n                          ? Cogl.PixelFormat.RGBA_8888\n                          : Cogl.PixelFormat.RGB_888,\n                        pixbuf.get_width (),\n            pixbuf.get_height (),\n                        pixbuf.get_rowstride ()\n    );\n    this.el.set_content(img);\n     // should probably do smarter scaling...\n    \n    \n    this.el.set_size(90, 70);\n}\n",
71                                     "$ x_expand" : true,
72                                     "* pack" : "add_child",
73                                     "xtype" : "Actor",
74                                     "$ y_align" : "Clutter.ActorAlign.START",
75                                     "$ margin_left" : 5,
76                                     "$ xns" : "Clutter",
77                                     "$ y_expand" : true,
78                                     "$ x_align" : "Clutter.ActorAlign.START"
79                                 },
80                                 {
81                                     "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickType(),new Clutter.Color.from_string(\"#fff\"))",
82                                     "id" : "+typetitle",
83                                     "* args" : "JsRender.JsRender file",
84                                     "$ x_expand" : true,
85                                     "* pack" : "add_child",
86                                     "xtype" : "Text",
87                                     "$ y_align" : "Clutter.ActorAlign.START",
88                                     "$ xns" : "Clutter",
89                                     "$ y_expand" : true,
90                                     "$ x_align" : "Clutter.ActorAlign.START"
91                                 },
92                                 {
93                                     "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickName(),new Clutter.Color.from_string(\"#fff\"))",
94                                     "id" : "+title",
95                                     "* args" : "JsRender.JsRender file",
96                                     "$ x_expand" : true,
97                                     "* pack" : "add_child",
98                                     "xtype" : "Text",
99                                     "$ y_align" : "Clutter.ActorAlign.START",
100                                     "$ xns" : "Clutter",
101                                     "$ y_expand" : true,
102                                     "$ x_align" : "Clutter.ActorAlign.START"
103                                 }
104                             ]
105                         }
106                     ]
107                 }
108             ]
109         }
110     ]
111 }