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    "# Gee.ArrayList<Xcls_fileitem> fileitems" : "new Gee.ArrayList<Xcls_fileitem>()",
12    "id" : "ClutterFiles",
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    // 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    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();\n}\n",
17    "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
18    "@ void open" : "(JsRender.JsRender file)",
19    "$ xns" : "Clutter",
20    "bool reactive" : true,
21    "|  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 - 75;\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.scoller.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.scoller.el.set_position(75,50);\n}\n",
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(100,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" : "100.0f",
50        "* pack" : "add_child",
51        "xtype" : "Text",
52        "Clutter.ActorAlign y_align" : "Clutter.ActorAlign.END",
53        "boolean x_expand" : false,
54        "$ xns" : "Clutter",
55        "Clutter.ActorAlign x_align" : "Clutter.ActorAlign.START",
56        "boolean y_expand" : false
57       },
58       {
59        "* ctor" : "new Clutter.Text.full(\"Sans 10px\", \"\",  Clutter.Color.from_string(\"#ccc\"))",
60        "id" : "project_title_path",
61        "* pack" : "add_child",
62        "xtype" : "Text",
63        "Clutter.ActorAlign y_align" : "Clutter.ActorAlign.END",
64        "boolean x_expand" : false,
65        "$ xns" : "Clutter",
66        "Clutter.ActorAlign x_align" : "Clutter.ActorAlign.START",
67        "boolean y_expand" : false
68       }
69      ]
70     },
71     {
72      "listeners" : {
73       "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}"
74      },
75      "# Gee.ArrayList<Xcls_fileitem> fileitems" : "new Gee.ArrayList<Xcls_fileitem>()",
76      "id" : "scoller",
77      "Clutter.ScrollMode scroll_mode" : "Clutter.ScrollMode.VERTICALLY",
78      "xtype" : "ScrollActor",
79      "* pack" : "add_child",
80      "# Gdk.Pixbuf missing_thumb_pixbuf" : "null",
81      "$ xns" : "Clutter",
82      "bool reactive" : true,
83      "items" : [
84       {
85        "id" : "filelayout",
86        "* init" : "\nthis.el.add_constraint(\n    new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)\n);\n\n ",
87        "xtype" : "Actor",
88        "* pack" : "add_child",
89        "$ reactive" : true,
90        "$ xns" : "Clutter",
91        "items" : [
92         {
93          "id" : "filelayout_manager",
94          "$ orientation" : "Clutter.FlowOrientation.HORIZONTAL",
95          "xtype" : "FlowLayout",
96          "$ xns" : "Clutter",
97          "row_spacing" : 20,
98          "* prop" : "layout_manager",
99          "column_spacing" : 20,
100          "$ homogeneous" : true
101         },
102         {
103          "listeners" : {
104           "button_press_event" : "  (  event) => {\n    _this.open(this.file);\n    return false;\n} ",
105           "enter_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#333\");\n        return false;\n}",
106           "leave_event" : "(  event)  => {\n    this.el.background_color =   Clutter.Color.from_string(\"#000\");\n    return false;\n}"
107          },
108          "id" : "*fileitem",
109          "* args" : "JsRender.JsRender file",
110          "* init" : "this.file = file;\nthis.el.set_size(100,100);",
111          "* pack" : true,
112          "xtype" : "Actor",
113          "# JsRender.JsRender file" : "",
114          "$ reactive" : true,
115          "$ xns" : "Clutter",
116          "items" : [
117           {
118            "spacing" : 4,
119            "xtype" : "BoxLayout",
120            "orientation" : "Clutter.Orientation.VERTICAL",
121            "$ xns" : "Clutter",
122            "* prop" : "layout_manager"
123           },
124           {
125            "$ margin_right" : 5,
126            "$ margin_top" : 5,
127            "id" : "+image",
128            "* args" : "JsRender.JsRender file",
129            "* 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",
130            "$ x_expand" : true,
131            "* pack" : "add_child",
132            "xtype" : "Actor",
133            "$ y_align" : "Clutter.ActorAlign.START",
134            "$ margin_left" : 5,
135            "$ xns" : "Clutter",
136            "$ y_expand" : true,
137            "$ x_align" : "Clutter.ActorAlign.START"
138           },
139           {
140            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickType(),  Clutter.Color.from_string(\"#fff\"))",
141            "* args" : "JsRender.JsRender file",
142            "id" : "+typetitle",
143            "$ x_expand" : true,
144            "* pack" : "add_child",
145            "xtype" : "Text",
146            "$ y_align" : "Clutter.ActorAlign.START",
147            "$ xns" : "Clutter",
148            "$ y_expand" : true,
149            "$ x_align" : "Clutter.ActorAlign.START"
150           },
151           {
152            "* ctor" : "new Clutter.Text.full(\"Sans 10px\", file.nickName(),  Clutter.Color.from_string(\"#fff\"))",
153            "* args" : "JsRender.JsRender file",
154            "id" : "+title",
155            "$ x_expand" : true,
156            "* pack" : "add_child",
157            "xtype" : "Text",
158            "$ y_align" : "Clutter.ActorAlign.START",
159            "$ xns" : "Clutter",
160            "$ y_expand" : true,
161            "$ x_align" : "Clutter.ActorAlign.START"
162           }
163          ]
164         }
165        ]
166       }
167      ]
168     }
169    ]
170   }
171  ]
172 }