src/Builder4/PopoverFileDetails.bjs
[app.Builder.js] / src / Builder4 / PopoverFileDetails.bjs
1 {
2  "name" : "PopoverFileDetails",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/alan/gitlive/app.Builder.js/src/Builder4/PopoverFileDetails.bjs",
6  "permname" : "",
7  "modOrder" : "",
8  "build_module" : "builder",
9  "items" : [
10   {
11    "listeners" : {
12     "closed" : "() => {\n  if (!this.done) {\n    _this.el.show();\n  \n  }\n} "
13    },
14    "|   void updateFileFromEntry" : "() {\n\n        _this.file.title = _this.title.el.get_text();\n        _this.file.region = _this.region.el.get_text();            \n        _this.file.parent = _this.parent.el.get_text();                        \n        _this.file.permname = _this.permname.el.get_text();                                    \n        _this.file.modOrder = _this.modOrder.el.get_text();\n        \n        if (_this.file.name.length  > 0 && _this.file.name != _this.name.el.get_text()) {\n            _this.file.renameTo(_this.name.el.get_text());\n        }\n        // store the module...\n        _this.file.build_module = \"\";        \n         Gtk.TreeIter iter; \n        if (_this.build_module.el.get_active_iter (out iter)) {\n             Value vfname;\n             this.dbmodel.el.get_value (iter, 0, out vfname);\n             if (((string)vfname).length > 0) {\n                 _this.file.build_module = (string)vfname;\n             }\n    \n        }\n        \n        \n\n                                                    \n}    ",
15    "@ void success" : "(Project.Project pr, JsRender.JsRender file)",
16    "id" : "PopoverFileDetails",
17    "| void show" : "(JsRender.JsRender c, Gtk.Widget btn) \n{\n    this.project = c.project;\n    this.done = false;\n    \n    \n    //if (!this.el) {\n        //this.init();\n     //}\n    \n    _this.name.el.set_text(c.name);\n    _this.title.el.set_text(c.title);\n    _this.parent.el.set_text(c.parent);    \n    _this.region.el.set_text(c.region);\n    _this.modOrder.el.set_text(c.modOrder);\n     _this.permname.el.set_text(c.permname);\n    \n    \n    \n    \n    \n    \n    \n    if (c.path.length > 0) {\n\t\t \n\t    this.save_btn.el.set_label(\"Save\");\n    } else {\n        this.save_btn.el.set_label(\"Create\");\n        \n\t   \n    }\n    \n     var ar = new Gee.ArrayList<string>();\n     _this.dbmodel.loadData(ar,\"\");\n    // load the modules... if relivant..\n    if (this.project.xtype == \"Gtk\") {\n        var p = (Project.Gtk)c.project;\n          var cg = p.compilegroups;\n\n        var iter = cg.map_iterator();\n       while(iter.next()) {\n            var key = iter.get_key();\n            if (key == \"_default_\") {\n                continue;\n            }\n            ar.add(key);\n        };\n        _this.dbmodel.loadData(ar, c.build_module);\n\n    }\n    \n     \n    _this.file = c;\n    //console.log('show all');\n   this.el.set_modal(true);\n    this.el.set_relative_to(btn);\n\n    this.el.set_position(Gtk.PositionType.RIGHT);\n    \n    // window + header?\n     print(\"SHOWALL - POPIP\\n\");\n    this.el.show_all();\n    this.name.el.grab_focus();\n    \n    \n    \n    if (c.path.length > 0) {\n\t\t_this.filetype.el.hide();\n\t\t_this.filetypelbl.el.hide();\n \n    } else {\n        \n        _this.ftdbmodel.loadData(\"bjs\"); // fixme - need to determine type..\n\t    _this.filetype.el.show();\n\t    _this.filetypelbl.el.show();\n    }\n    \n    \n    //this.success = c.success;\n    \n    \n}",
18    "bool done" : false,
19    "# Project.Project project" : "",
20    "xtype" : "Popover",
21    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
22    "# JsRender.JsRender file" : "null",
23    "$ xns" : "Gtk",
24    "Xcls_MainWindow mainwindow" : "null",
25    "bool modal" : true,
26    "uint border_width" : 0,
27    "items" : [
28     {
29      "bool homogeneous" : false,
30      "xtype" : "Box",
31      "$ pack" : "add",
32      "$ xns" : "Gtk",
33      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
34      "items" : [
35       {
36        "* pack" : "pack_start,false,true,0",
37        "xtype" : "HeaderBar",
38        "$ xns" : "Gtk",
39        "string title" : "Add / Edit File"
40       },
41       {
42        "id" : "grid",
43        "int margin_right" : 4,
44        "* pack" : "pack_start,false,false,4",
45        "xtype" : "Grid",
46        "uint row_spacing" : 2,
47        "n_columns" : 2,
48        "$ xns" : "Gtk",
49        "n_rows" : 7,
50        "$ homogeneous" : true,
51        "int margin_left" : 4,
52        "items" : [
53         {
54          "label" : "File type",
55          "id" : "filetypelbl",
56          "xalign" : 0.90000000000000002,
57          "* pack" : "attach,0,0,1,1",
58          "xtype" : "Label",
59          "$ justify" : "Gtk.Justification.RIGHT",
60          "x_options" : 4,
61          "$ xns" : "Gtk"
62         },
63         {
64          "listeners" : {
65           "changed" : "() => {\n\tGtk.TreeIter iter;\n\tbool is_bjs = true;\n\tif (this.el.get_active_iter(out iter)) {\n\t\tValue vfname;\n\t\t_this.ftdbmodel.el.get_value (iter, 0, out vfname);\n\t\t is_bjs = ((string)vfname) == \"bjs\";\n\t}\n    \n   for (var i = 2; i < 9;i++) {\n\t\tvar el = _this.grid.el.get_child_at(0,i);\n\t\tif (is_bjs) {\n\t\t   el.show();\n\t\t} else {\n\t\t\tel.hide();\n\t\t}\n\t\t el = _this.grid.el.get_child_at(1,i);\n\t\tif (is_bjs) {\n\t\t   el.show();\n\t\t} else {\n\t\t\tel.hide();\n\t\t}     \n    }\n     \n     \n\n\n}"
66          },
67          "id" : "filetype",
68          "* init" : "this.el.add_attribute(_this.ftdbcellrenderer.el , \"markup\", 1 );",
69          "* pack" : "attach,1,0,1,1",
70          "xtype" : "ComboBox",
71          "$ xns" : "Gtk",
72          "items" : [
73           {
74            "id" : "ftdbcellrenderer",
75            "* pack" : "pack_start,true",
76            "xtype" : "CellRendererText",
77            "$ xns" : "Gtk"
78           },
79           {
80            "id" : "ftdbmodel",
81            "* pack" : "set_model",
82            "xtype" : "ListStore",
83            "$ columns" : "typeof(string),typeof(string)",
84            "n_columns" : 2,
85            "$ xns" : "Gtk",
86            "| void loadData" : "  (string cur) {\n    this.el.clear();                                    \n    Gtk.TreeIter iter;\n    var el = this.el;\n    \n   /// el.append(out iter);\n    \n     \n   // el.set_value(iter, 0, \"\");\n   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");\n\n    el.append(out iter);\n\n    \n    el.set_value(iter, 0, \"bjs\");\n    el.set_value(iter, 1, \"User Interface File (bjs)\");\n    _this.filetype.el.set_active_iter(iter);\n\n    el.append(out iter);\n    \n    el.set_value(iter, 0, \"vala\");\n    el.set_value(iter, 1, \"Vala\");\n\tif (cur == \"vala\") {\n\t    _this.filetype.el.set_active_iter(iter);\n    }\n\n\n\n    el.append(out iter);\n    \n    el.set_value(iter, 0, \"js\");\n    el.set_value(iter, 1, \"Javascript\");\n\n\tif (cur == \"js\") {\n\t    _this.filetype.el.set_active_iter(iter);\n    }\n\n    el.append(out iter);\n    \n    el.set_value(iter, 0, \"css\");\n    el.set_value(iter, 1, \"CSS\");\n\n\tif (cur == \"css\") {\n\t    _this.filetype.el.set_active_iter(iter);\n    }\n                                     \n}\n"
87           }
88          ]
89         },
90         {
91          "label" : "Component Name",
92          "xalign" : 0.90000000000000002,
93          "* pack" : "attach,0,1,1,1",
94          "xtype" : "Label",
95          "$ justify" : "Gtk.Justification.RIGHT",
96          "x_options" : 4,
97          "$ xns" : "Gtk"
98         },
99         {
100          "id" : "name",
101          "$ visible" : true,
102          "xtype" : "Entry",
103          "* pack" : "attach,1,1,1,1",
104          "$ xns" : "Gtk"
105         },
106         {
107          "label" : "Title",
108          "$ visible" : true,
109          "xalign" : 0.90000000000000002,
110          "* pack" : "attach,0,2,1,1",
111          "xtype" : "Label",
112          "$ justify" : "Gtk.Justification.RIGHT",
113          "x_options" : 4,
114          "$ xns" : "Gtk"
115         },
116         {
117          "id" : "title",
118          "$ visible" : true,
119          "xtype" : "Entry",
120          "* pack" : "attach,1,2,1,1",
121          "$ xns" : "Gtk"
122         },
123         {
124          "label" : "Region",
125          "$ visible" : true,
126          "tooltip_text" : "center, north, south, east, west",
127          "xalign" : 0.90000000000000002,
128          "* pack" : "attach,0,3,1,1",
129          "xtype" : "Label",
130          "$ justify" : "Gtk.Justification.RIGHT",
131          "x_options" : 4,
132          "$ xns" : "Gtk"
133         },
134         {
135          "id" : "region",
136          "$ visible" : true,
137          "xtype" : "Entry",
138          "* pack" : "attach,1,3,1,1",
139          "$ xns" : "Gtk"
140         },
141         {
142          "label" : "Parent Name",
143          "$ visible" : true,
144          "xalign" : 0.90000000000000002,
145          "* pack" : "attach,0,4,1,1",
146          "xtype" : "Label",
147          "$ justify" : "Gtk.Justification.RIGHT",
148          "x_options" : 4,
149          "$ xns" : "Gtk"
150         },
151         {
152          "id" : "parent",
153          "$ visible" : true,
154          "xtype" : "Entry",
155          "* pack" : "attach,1,4,1,1",
156          "$ xns" : "Gtk"
157         },
158         {
159          "label" : "Permission Name",
160          "$ visible" : true,
161          "xalign" : 0.90000000000000002,
162          "* pack" : "attach,0,5,1,1",
163          "xtype" : "Label",
164          "$ justify" : "Gtk.Justification.RIGHT",
165          "x_options" : 4,
166          "$ xns" : "Gtk"
167         },
168         {
169          "id" : "permname",
170          "$ visible" : true,
171          "xtype" : "Entry",
172          "* pack" : "attach,1,5,1,1",
173          "$ xns" : "Gtk"
174         },
175         {
176          "label" : "Order (for tabs)",
177          "$ visible" : true,
178          "xalign" : 0.90000000000000002,
179          "* pack" : "attach,0,6,1,1",
180          "xtype" : "Label",
181          "$ justify" : "Gtk.Justification.RIGHT",
182          "x_options" : 4,
183          "$ xns" : "Gtk"
184         },
185         {
186          "id" : "modOrder",
187          "$ visible" : true,
188          "xtype" : "Entry",
189          "* pack" : "attach,1,6,1,1",
190          "$ xns" : "Gtk"
191         },
192         {
193          "label" : "Module to build (Vala only)",
194          "$ visible" : true,
195          "xalign" : 0.90000000000000002,
196          "* pack" : "attach,0,7,1,1",
197          "xtype" : "Label",
198          "$ justify" : "Gtk.Justification.RIGHT",
199          "x_options" : 4,
200          "$ xns" : "Gtk"
201         },
202         {
203          "id" : "build_module",
204          "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
205          "* pack" : "attach,1,7,1,1",
206          "xtype" : "ComboBox",
207          "$ xns" : "Gtk",
208          "items" : [
209           {
210            "id" : "dbcellrenderer",
211            "xtype" : "CellRendererText",
212            "* pack" : "pack_start,true",
213            "$ xns" : "Gtk"
214           },
215           {
216            "id" : "dbmodel",
217            "xtype" : "ListStore",
218            "* pack" : "set_model",
219            "$ columns" : "typeof(string),typeof(string)",
220            "n_columns" : 2,
221            "$ xns" : "Gtk",
222            "| void loadData" : "  (Gee.ArrayList<string> data, string cur) {\n    this.el.clear();                                    \n    Gtk.TreeIter iter;\n    var el = this.el;\n    \n   /// el.append(out iter);\n    \n     \n   // el.set_value(iter, 0, \"\");\n   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");\n\n    el.append(out iter);\n\n    \n    el.set_value(iter, 0, \"\");\n    el.set_value(iter, 1, \"-- select a module --\");\n    _this.build_module.el.set_active_iter(iter);\n    \n    for (var i = 0; i < data.size;i++) {\n    \n\n        el.append(out iter);\n        \n        el.set_value(iter, 0, data.get(i));\n        el.set_value(iter, 1, data.get(i));\n        \n        if (data.get(i) == cur) {\n            _this.build_module.el.set_active_iter(iter);\n        }\n        \n    }\n     this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          \n                                     \n}\n"
223           }
224          ]
225         },
226         {
227          "label" : "Directory",
228          "$ visible" : true,
229          "xalign" : 0.90000000000000002,
230          "* pack" : "attach,0,8",
231          "xtype" : "Label",
232          "$ justify" : "Gtk.Justification.RIGHT",
233          "x_options" : 4,
234          "$ xns" : "Gtk"
235         },
236         {
237          "id" : "dir",
238          "* init" : "this.el.add_attribute(_this.dircellrenderer.el , \"markup\", 1 );",
239          "* pack" : "attach,1,8",
240          "xtype" : "ComboBox",
241          "$ xns" : "Gtk",
242          "items" : [
243           {
244            "id" : "dircellrenderer",
245            "* pack" : "pack_start,true",
246            "xtype" : "CellRendererText",
247            "$ xns" : "Gtk"
248           },
249           {
250            "id" : "dirmodel",
251            "* pack" : "set_model",
252            "xtype" : "ListStore",
253            "$ columns" : "typeof(string),typeof(string)",
254            "n_columns" : 2,
255            "$ xns" : "Gtk",
256            "| void loadData" : "  (Gee.ArrayList<string> data, string cur) {\n    this.el.clear();                                    \n    Gtk.TreeIter iter;\n    var el = this.el;\n    \n   /// el.append(out iter);\n    \n     \n   // el.set_value(iter, 0, \"\");\n   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");\n\n    el.append(out iter);\n\n    \n    el.set_value(iter, 0, \"\");\n    el.set_value(iter, 1, \"-- select a module --\");\n    _this.build_module.el.set_active_iter(iter);\n    \n    for (var i = 0; i < data.size;i++) {\n    \n\n        el.append(out iter);\n        \n        el.set_value(iter, 0, data.get(i));\n        el.set_value(iter, 1, data.get(i));\n        \n        if (data.get(i) == cur) {\n            _this.build_module.el.set_active_iter(iter);\n        }\n        \n    }\n     this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          \n                                     \n}\n"
257           }
258          ]
259         }
260        ]
261       },
262       {
263        "int margin_bottom" : 4,
264        "int margin_right" : 4,
265        "* pack" : "pack_end,false,true,0",
266        "xtype" : "HButtonBox",
267        "$ xns" : "Gtk",
268        "int margin_left" : 4,
269        "items" : [
270         {
271          "listeners" : {
272           "clicked" : "() => { \n\n  _this.done = true;\n    _this.el.hide(); \n}"
273          },
274          "string label" : "Cancel",
275          "* pack" : "add",
276          "xtype" : "Button",
277          "$ xns" : "Gtk"
278         },
279         {
280          "listeners" : {
281           "clicked" : "( ) =>  { \n\n \n\n\n\tif (_this.name.el.get_text().length  < 1) {\n\t    StandardErrorDialog.show(\n\t        _this.mainwindow.el,\n\t        \"You have to set Component name \"\n\t    );\n\t     \n\t    return;\n\t}\n\t// what does this do?\n\t\n\tvar isNew = _this.file.name.length  > 0 ? false : true;\n\t/*\n\tif (!isNew && this.file.name != _this.name.el.get_text()) {\n\t    Xcls_StandardErrorDialog.singleton().show(\n\t        this.el,\n\t        \"Sorry changing names does not work yet. \"\n\t    );\n\t     \n\t    return;\n\t}\n\t*/\n\t \n\t\n  \n\t// FIXME - this may be more complicated...\n\t//for (var i in this.def) {\n\t//    this.file[i] =  this.get(i).el.get_text();\n\t//}\n\n\tif (!isNew) {\n\t    try {\n\t         _this.updateFileFromEntry();\n\t     } catch( JsRender.Error.RENAME_FILE_EXISTS er) {\n\t          Xcls_StandardErrorDialog.singleton().show(\n\t            _this.mainwindow.el,\n\t            \"The name you used already exists \"\n\t        );\n\t        return;\n\t         \n\t     }\n\n\t      _this.done = true;\n\t    _this.file.save();\n\t    _this.el.hide();\n\t    return;\n\t}\n\t\n\t// ---------------- NEW FILES...\n\t\n\tvar fn = _this.name.el.get_text();\n\tvar dir = _this.project.firstPath();   // fixme.. should be based on a pulldown?\n\t\n\tvar targetfile = dir + \"/\" + fn;\n\t\n\t// strip the file type off the end..\n\tGtk.TreeIter iter;\n\n\tif (!_this.filetype.el.get_active_iter(out iter)) {\n\t\t// should not happen...\n\t\t// so we are jut going to return without \n\t\tStandardErrorDialog.show(\n\t        _this.mainwindow.el,\n\t        \"You must select a file type. \"\n\t    );\n\t}\n\tValue ftypename;\n\t_this.ftdbmodel.el.get_value (iter, 0, out ftypename);\n\tvar ext = ((string)ftypename);\n\t\n    var rx = new GLib.Regex(\"\\\\.\" + ext + \"$\",GLib.RegexCompileFlags.CASELESS);\n    targetfile = rx.replace(targetfile, targetfile.length, 0, \"\"); \n   \n\tif (GLib.FileUtils.test(targetfile + \".\" + ext, GLib.FileTest.EXISTS)) {\n\t    Xcls_StandardErrorDialog.singleton().show(\n\t        _this.mainwindow.el,\n\t        \"That file already exists\"\n\t    ); \n\t    return;\n\t}\n   \n   var f =  JsRender.JsRender.factory(\n\t\text == \"bjs\" ? _this.file.project.xtype : \"PlainFile\",  \n\t\t_this.file.project, \n\t\ttargetfile + \".\" + ext);\n\n\t_this.file = f;\n\t\n\n\t\n\t_this.updateFileFromEntry();\n\t_this.file.loaded = true;\n\t_this.file.save();\n\tif (ext == \"bjs\") {\n\t\t_this.file.project.addFile(_this.file);\n\t}\n\t\n \n\t// what about .js ?\n   _this.done = true;\n\t_this.el.hide();\n\n// hopefull this will work with bjs files..\n\t\n\t_this.success(_this.project, _this.file);\n   \n}"
282          },
283          "id" : "save_btn",
284          "xtype" : "Button",
285          "* pack" : "add",
286          "string label" : "Save",
287          "$ xns" : "Gtk"
288         }
289        ]
290       }
291      ]
292     }
293    ]
294   }
295  ]
296 }