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    "* args" : "",
13    "|  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 ",
14    "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
15    "xtype" : "Actor",
16    "|  void loadProject" : "(Project.Project pr) {\n    // list all the files, and create new Xcls_fileitem for each one.\n    \n    this.project = pr;\n    \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.filesForOpen(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",
17    "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
18    "@ void open" : "(JsRender.JsRender file)",
19    "$ xns" : "Clutter",
20    "bool reactive" : true,
21    "Project.Project project" : "",
22    "|  void set_size" : "(float w, float h) \n{\n    \n     // called by window resize... with is alreaddy -50 (for the buttons?)\n     \n\n\n\n     if (this.el == null) {\n        print(\"object not ready yet?\");\n        return;\n    }\n    \n    print(\"recv width %f, filelayoutw = %f\", w, w-200);\n    \n    w = GLib.Math.floorf ( w/120.0f) * 120.0f;\n    \n    \n    \n    \n   //_this.filelayout_manager.el.max_column_width = w - 200;\n   _this.filelayout.el.width = w ;\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(75,0);\n   \n   \n   this.scroller.el.set_size(\n           // this.el.get_stage().width-150,\n           w-50,\n           h  // this.el.get_stage().height\n    );\n    \n    // 100 right for buttons ..\n    this.scroller.el.set_position(0,50);\n    // scroll...\n    _this.filelayout.el.y = 0.0f;\n    \n}\n",
23    "# Gee.ArrayList<Object> fileitems" : "new Gee.ArrayList<Object>()",
24    "items" : [
25     {
26      "id" : "project_title",
27      "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\nthis.el.set_position(0,0);\n ",
28      "xtype" : "Actor",
29      "* pack" : "add_child",
30      "$ reactive" : true,
31      "$ xns" : "Clutter",
32      "items" : [
33       {
34        "id" : "project_title_manager",
35        "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
36        "xtype" : "FlowLayout",
37        "boolean homogeneous" : false,
38        "$ xns" : "Clutter",
39        "row_spacing" : 5,
40        "* prop" : "layout_manager",
41        "column_spacing" : 20
42       },
43       {
44        "xtype" : "FixedLayout",
45        "$ xns" : "Clutter",
46        "* prop" : "layout_manager"
47       },
48       {
49        "* ctor" : "new Clutter.Text.full(\"Sans 20px\", \"\",  Clutter.Color.from_string(\"#eee\"))",
50        "id" : "project_title_name",
51        "float x" : "0.0f",
52        "* pack" : "add_child",
53        "xtype" : "Text",
54        "float y" : "10.0f",
55        "boolean x_expand" : false,
56        "$ xns" : "Clutter"
57       },
58       {
59        "* ctor" : "new Clutter.Text.full(\"Sans 10px\", \"\",  Clutter.Color.from_string(\"#ccc\"))",
60        "id" : "project_title_path",
61        "float x" : "0.0f",
62        "* pack" : "add_child",
63        "xtype" : "Text",
64        "float y" : "35.0f",
65        "$ xns" : "Clutter"
66       }
67      ]
68     },
69     {
70      "listeners" : {
71       "scroll_event" : "( event) => {\n   //Sprint(\"scroll event\");\n    var y = _this.filelayout.el.y;\n    var dir = event.direction;\n    \n    var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;\n    var bottompos = -1 * (  last_child_bottom - (0.5f * this.el.height));\n    \n    switch (dir) {\n        case Clutter.ScrollDirection.UP:\n            print(\"Scroll up by %f\\n\", event.y);\n            y += event.y /2;\n            y = float.min(0, y); // \n            break;\n            \n        case Clutter.ScrollDirection.DOWN:\n            print(\"Scroll down by %f\\n\", event.y);\n            y -= event.y /2 ;\n            y = float.max(bottompos, y);\n            \n            \n            break;\n        default:\n            return false;\n    }\n    // range of scroll -- can go up -- eg.. -ve value.\n    \n\n    \n    // to work out the max -ve number\n    // height of filelayout\n    // height of scrollactor..\n    \n/*\n    if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {\n        var nv =         _this.filelayout.el.y ;\n        if (nv != -1 * (  last_child_bottom - this.el.height)) {\n    \n            _this.filelayout.el.y = -1 * (  last_child_bottom - this.el.height);\n            return true;\n        }\n    \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   print(\"Set scroll to %f (lcb=%f / height = %f)\\n\", y, last_child_bottom, this.el.height);\n   \n    _this.filelayout.el.y = y;\n    return true;\n          \n}"
72      },
73      "# Gee.ArrayList<Xcls_fileitem> fileitems" : "new Gee.ArrayList<Xcls_fileitem>()",
74      "id" : "scroller",
75      "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
76      "xtype" : "ScrollActor",
77      "* pack" : "add_child",
78      "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
79      "$ xns" : "Clutter",
80      "bool reactive" : true,
81      "items" : [
82       {
83        "id" : "filelayout",
84        "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\n\n ",
85        "xtype" : "Actor",
86        "* pack" : "add_child",
87        "$ reactive" : true,
88        "$ xns" : "Clutter",
89        "items" : [
90         {
91          "id" : "filelayout_manager",
92          "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
93          "bool homogeneous" : false,
94          "xtype" : "FlowLayout",
95          "float max_column_width" : "100.0f",
96          "$ xns" : "Clutter",
97          "row_spacing" : 20,
98          "* prop" : "layout_manager",
99          "column_spacing" : 20
100         },
101         {
102          "listeners" : {
103           "button_press_event" : "  (  event) => {\n    _this.open(this.file);\n    return false;\n} ",
104           "enter_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#333\");\n    this.title.el.background_color =   Clutter.Color.from_string(\"#fff\");\n    this.typetitle.el.background_color =   Clutter.Color.from_string(\"#fff\");\n    this.title.el.color =   Clutter.Color.from_string(\"#000\");\n    this.typetitle.el.color =   Clutter.Color.from_string(\"#000\");\n    \n        return false;\n}",
105           "leave_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#000\");\n     this.title.el.background_color =   Clutter.Color.from_string(\"#000\");\n    this.typetitle.el.background_color =   Clutter.Color.from_string(\"#000\");\n    this.title.el.color =   Clutter.Color.from_string(\"#fff\");\n    this.typetitle.el.color =   Clutter.Color.from_string(\"#fff\");\n   \n    \n    return false;\n}"
106          },
107          "id" : "*fileitem",
108          "* args" : "JsRender.JsRender file",
109          "* init" : "this.file = file;\nthis.el.set_size(100,100);",
110          "* pack" : true,
111          "xtype" : "Actor",
112          "# JsRender.JsRender file" : "",
113          "$ reactive" : true,
114          "$ xns" : "Clutter",
115          "items" : [
116           {
117            "spacing" : 4,
118            "xtype" : "BoxLayout",
119            "orientation" : "Clutter.Orientation.VERTICAL",
120            "$ xns" : "Clutter",
121            "* prop" : "layout_manager"
122           },
123           {
124            "$ margin_right" : 5,
125            "$ margin_top" : 5,
126            "id" : "+image",
127            "* args" : "JsRender.JsRender file",
128            "* 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",
129            "* pack" : "add_child",
130            "xtype" : "Actor",
131            "bool x_expand" : false,
132            "$ y_align" : "Clutter.ActorAlign.START",
133            "$ margin_left" : 5,
134            "$ xns" : "Clutter",
135            "bool y_expand" : false,
136            "$ x_align" : "Clutter.ActorAlign.START"
137           },
138           {
139            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickType(),  Clutter.Color.from_string(\"#fff\"))",
140            "id" : "+typetitle",
141            "* args" : "JsRender.JsRender file",
142            "* pack" : "add_child",
143            "xtype" : "Text",
144            "bool x_expand" : false,
145            "$ y_align" : "Clutter.ActorAlign.START",
146            "$ xns" : "Clutter",
147            "bool y_expand" : false,
148            "$ x_align" : "Clutter.ActorAlign.START"
149           },
150           {
151            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickName(),  Clutter.Color.from_string(\"#fff\"))",
152            "id" : "+title",
153            "* args" : "JsRender.JsRender file",
154            "* pack" : "add_child",
155            "xtype" : "Text",
156            "bool x_expand" : false,
157            "$ y_align" : "Clutter.ActorAlign.START",
158            "$ xns" : "Clutter",
159            "bool y_expand" : false,
160            "$ x_align" : "Clutter.ActorAlign.START"
161           }
162          ]
163         },
164         {
165          "id" : "*folderitem",
166          "* args" : "string folderpath",
167          "* init" : " \n//this.el.set_size(100,100);",
168          "* pack" : true,
169          "xtype" : "Actor",
170          "$ reactive" : true,
171          "$ xns" : "Clutter",
172          "items" : [
173           {
174            "spacing" : 2,
175            "xtype" : "BoxLayout",
176            "orientation" : "Clutter.Orientation.VERTICAL",
177            "$ xns" : "Clutter",
178            "* prop" : "layout_manager"
179           },
180           {
181            "* ctor" : "new Clutter.Text.full(\"Sans bold 14px\", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string(\"#fff\"))",
182            "* args" : "string folderpath",
183            "id" : "+foldertitle",
184            "$ x_expand" : true,
185            "* pack" : "add_child",
186            "xtype" : "Text",
187            "$ y_align" : "Clutter.ActorAlign.START",
188            "$ xns" : "Clutter",
189            "bool y_expand" : false,
190            "$ x_align" : "Clutter.ActorAlign.START"
191           },
192           {
193            "listeners" : {
194             "button_press_event" : "  (  event) => {\n    \n   var f = JsRender.JsRender.factory(\"PlainFile\", _this.project, this.filepath);\n    _this.open(f);\n    return false;\n} ",
195             "enter_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#fff\");\n    this.el.color =  Clutter.Color.from_string(\"#000\");\n        return false;\n}",
196             "leave_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#000\");\n     this.el.color =   Clutter.Color.from_string(\"#fff\");\n    return false;\n}"
197            },
198            "id" : "+folderfile",
199            "xtype" : "Text",
200            "bool x_expand" : true,
201            "Clutter.ActorAlign y_align" : "Clutter.ActorAlign.START",
202            "string filepath" : "",
203            "$ xns" : "Clutter",
204            "Clutter.ActorAlign x_align" : "Clutter.ActorAlign.START",
205            "bool y_expand" : true
206           }
207          ]
208         }
209        ]
210       }
211      ]
212     }
213    ]
214   }
215  ]
216 }