src/Builder4/ClutterFiles.bjs
[app.Builder.js] / src / Builder4 / ClutterFiles.bjs
1 {
2  "name" : "ClutterFiles",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/alan/gitlive/app.Builder.js/src/Builder4/ClutterFiles.bjs",
6  "permname" : "",
7  "modOrder" : "",
8  "build_module" : "builder",
9  "items" : [
10   {
11    "id" : "ClutterFiles",
12    "|  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 ",
13    "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
14    "xtype" : "Actor",
15    "|  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    \n    this.project_title_name.el.text = pr.name;\n    this.project_title_path.el.text = pr.firstPath();\n    \n    // file items contains a reference until we reload ...\n    this.fileitems = new Gee.ArrayList<Object>();\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    // folders...\n    \n    if (!(pr is Project.Gtk)) {\n        print (\"not gtk... skipping files\");\n        return;\n    }\n    var gpr = (Project.Gtk)pr;\n     var def = gpr.compilegroups.get(\"_default_\");\n     var items  = def.sources;\n     \n     \n     \n    for(var i =0 ; i < items.size; i++) {\n        print (\"cheking folder %s\\n\", items.get(i));\n         var files = gpr.files(items.get(i));\n         if (files.size < 1) {\n            continue;\n         }\n\n        // add the directory... items.get(i);\n        var x = new Xcls_folderitem(this,items.get(i));\n        this.fileitems.add(x);\n        this.filelayout.el.add_child(x.el);\n        \n        for(var j =0 ; j < files.size; j++) {\n            print (\"adding file %s\\n\", files.get(j));\n        \n            var y = new Xcls_folderfile(this, files.get(j));\n            this.fileitems.add(y);\n            x.el.add_child(y.el);\n\n            // add file to files.get(j);\n            \n        }\n        \n        \n        //this.el.set_value(citer, 1,   items.get(i) );\n    }\n    \n   \n    \n    this.el.show();\n}\n",
16    "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
17    "@ void open" : "(JsRender.JsRender file)",
18    "$ xns" : "Clutter",
19    "bool reactive" : true,
20    "|  void set_size" : "(float w, float h) \n{\n    \n     // called by window resize... with is alreaddy -50 (for the buttons?)\n     \n\n     if (this.el == null) {\n        print(\"object not ready yet?\");\n        return;\n    }\n   _this.filelayout_manager.el.max_column_width = w - 200;\n   \n    this.el.set_size(\n           // this.el.get_stage().width-150,\n           w,\n           h  // this.el.get_stage().height\n    );\n    \n    // 100 right for buttons ..\n    this.el.set_position(0,0);\n   \n   \n   this.scroller.el.set_size(\n           // this.el.get_stage().width-150,\n           w-150,\n           h  // this.el.get_stage().height\n    );\n    \n    // 100 right for buttons ..\n    this.scroller.el.set_position(75,50);\n}\n",
21    "# Gee.ArrayList<Object> fileitems" : "new Gee.ArrayList<Object>()",
22    "items" : [
23     {
24      "id" : "project_title",
25      "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\nthis.el.set_position(75,0);\n ",
26      "xtype" : "Actor",
27      "* pack" : "add_child",
28      "$ reactive" : true,
29      "$ xns" : "Clutter",
30      "items" : [
31       {
32        "id" : "project_title_manager",
33        "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
34        "xtype" : "FlowLayout",
35        "boolean homogeneous" : false,
36        "$ xns" : "Clutter",
37        "row_spacing" : 5,
38        "* prop" : "layout_manager",
39        "column_spacing" : 20
40       },
41       {
42        "xtype" : "FixedLayout",
43        "$ xns" : "Clutter",
44        "* prop" : "layout_manager"
45       },
46       {
47        "* ctor" : "new Clutter.Text.full(\"Sans 20px\", \"\",  Clutter.Color.from_string(\"#eee\"))",
48        "id" : "project_title_name",
49        "float x" : "0.0f",
50        "* pack" : "add_child",
51        "xtype" : "Text",
52        "float y" : "10.0f",
53        "boolean x_expand" : false,
54        "$ xns" : "Clutter"
55       },
56       {
57        "* ctor" : "new Clutter.Text.full(\"Sans 10px\", \"\",  Clutter.Color.from_string(\"#ccc\"))",
58        "id" : "project_title_path",
59        "float x" : "0.0f",
60        "* pack" : "add_child",
61        "xtype" : "Text",
62        "float y" : "35.0f",
63        "$ xns" : "Clutter"
64       }
65      ]
66     },
67     {
68      "listeners" : {
69       "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}"
70      },
71      "# Gee.ArrayList<Xcls_fileitem> fileitems" : "new Gee.ArrayList<Xcls_fileitem>()",
72      "id" : "scroller",
73      "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
74      "xtype" : "ScrollActor",
75      "* pack" : "add_child",
76      "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
77      "$ xns" : "Clutter",
78      "bool reactive" : true,
79      "items" : [
80       {
81        "id" : "filelayout",
82        "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\n\n ",
83        "xtype" : "Actor",
84        "* pack" : "add_child",
85        "$ reactive" : true,
86        "$ xns" : "Clutter",
87        "items" : [
88         {
89          "id" : "filelayout_manager",
90          "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
91          "bool homogeneous" : true,
92          "xtype" : "FlowLayout",
93          "float max_column_width" : 120,
94          "$ xns" : "Clutter",
95          "row_spacing" : 20,
96          "* prop" : "layout_manager",
97          "column_spacing" : 20
98         },
99         {
100          "listeners" : {
101           "button_press_event" : "  (  event) => {\n    _this.open(this.file);\n    return false;\n} ",
102           "enter_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#333\");\n        return false;\n}",
103           "leave_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#000\");\n    return false;\n}"
104          },
105          "id" : "*fileitem",
106          "* args" : "JsRender.JsRender file",
107          "* init" : "this.file = file;\nthis.el.set_size(100,100);",
108          "* pack" : true,
109          "xtype" : "Actor",
110          "# JsRender.JsRender file" : "",
111          "$ reactive" : true,
112          "$ xns" : "Clutter",
113          "items" : [
114           {
115            "spacing" : 4,
116            "xtype" : "BoxLayout",
117            "orientation" : "Clutter.Orientation.VERTICAL",
118            "$ xns" : "Clutter",
119            "* prop" : "layout_manager"
120           },
121           {
122            "$ margin_right" : 5,
123            "$ margin_top" : 5,
124            "id" : "+image",
125            "* args" : "JsRender.JsRender file",
126            "* init" : "{\n    Gdk.Pixbuf pixbuf= null;\n    \n    var fname = file.getIconFileName(false);\n\n    try {\n        if (FileUtils.test(fname, FileTest.EXISTS)) {\n            pixbuf = new Gdk.Pixbuf.from_file(fname);\n        } \n    } catch (Error e) {\n        // noop\n    \n    }\n    if (pixbuf == null) {\n        \n        try {\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        } catch (Error e) {\n            // noop?\n        }\n    }\n    try {\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    } catch (Error e) {\n        // noop?\n    }\n     // should probably do smarter scaling...\n    \n    \n    this.el.set_size(90, 70);\n}\n",
127            "* pack" : "add_child",
128            "xtype" : "Actor",
129            "bool x_expand" : false,
130            "$ y_align" : "Clutter.ActorAlign.START",
131            "$ margin_left" : 5,
132            "$ xns" : "Clutter",
133            "bool y_expand" : false,
134            "$ x_align" : "Clutter.ActorAlign.START"
135           },
136           {
137            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickType(),  Clutter.Color.from_string(\"#fff\"))",
138            "id" : "+typetitle",
139            "* args" : "JsRender.JsRender file",
140            "* pack" : "add_child",
141            "xtype" : "Text",
142            "bool x_expand" : false,
143            "$ y_align" : "Clutter.ActorAlign.START",
144            "$ xns" : "Clutter",
145            "bool y_expand" : false,
146            "$ x_align" : "Clutter.ActorAlign.START"
147           },
148           {
149            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickName(),  Clutter.Color.from_string(\"#fff\"))",
150            "id" : "+title",
151            "* args" : "JsRender.JsRender file",
152            "* pack" : "add_child",
153            "xtype" : "Text",
154            "bool x_expand" : false,
155            "$ y_align" : "Clutter.ActorAlign.START",
156            "$ xns" : "Clutter",
157            "bool y_expand" : false,
158            "$ x_align" : "Clutter.ActorAlign.START"
159           }
160          ]
161         },
162         {
163          "id" : "*folderitem",
164          "* args" : "string folderpath",
165          "* init" : " \n//this.el.set_size(100,100);",
166          "* pack" : true,
167          "xtype" : "Actor",
168          "$ reactive" : true,
169          "$ xns" : "Clutter",
170          "items" : [
171           {
172            "spacing" : 2,
173            "xtype" : "BoxLayout",
174            "orientation" : "Clutter.Orientation.VERTICAL",
175            "$ xns" : "Clutter",
176            "* prop" : "layout_manager"
177           },
178           {
179            "* ctor" : "new Clutter.Text.full(\"Sans 14px\", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string(\"#fff\"))",
180            "* args" : "string folderpath",
181            "id" : "+foldertitle",
182            "$ x_expand" : true,
183            "* pack" : "add_child",
184            "xtype" : "Text",
185            "$ y_align" : "Clutter.ActorAlign.START",
186            "$ xns" : "Clutter",
187            "bool y_expand" : false,
188            "$ x_align" : "Clutter.ActorAlign.START"
189           },
190           {
191            "listeners" : {
192             "button_press_event" : "  (  event) => {\n   // _this.open(this.filepath);\n    return false;\n} ",
193             "enter_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#333\");\n        return false;\n}",
194             "leave_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#000\");\n    return false;\n}"
195            },
196            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", GLib.Path.get_basename(filepath),  Clutter.Color.from_string(\"#fff\"))",
197            "* args" : "string filepath",
198            "id" : "*folderfile",
199            "* init" : "{\n    this.filepath = filepath;\n}\n",
200            "$ x_expand" : true,
201            "* pack" : "add_child",
202            "xtype" : "Text",
203            "$ y_align" : "Clutter.ActorAlign.START",
204            "string filepath" : "",
205            "$ xns" : "Clutter",
206            "bool reactive" : true,
207            "bool y_expand" : false,
208            "$ x_align" : "Clutter.ActorAlign.START"
209           }
210          ]
211         }
212        ]
213       }
214      ]
215     }
216    ]
217   }
218  ]
219 }