Fix #8037 - bug on zoom
[roobuilder] / src / Builder4 / DialogPluginWebkit.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "$ xns" : "Gtk",
6    "@ void complete" : "(string result)",
7    "gboolean deletable" : true,
8    "gboolean modal" : true,
9    "gint default_height" : 500,
10    "gint default_width" : 750,
11    "id" : "DialogPluginWebkit",
12    "items" : [
13     {
14      "$ xns" : "Gtk",
15      "* pack" : "get_content_area().append",
16      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
17      "bool homogeneous" : false,
18      "items" : [
19       {
20        "$ xns" : "Gtk",
21        "* init" : [
22         "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
23         " ",
24         ""
25        ],
26        "* pack" : "append",
27        "bool hexpand" : true,
28        "bool vexpand" : true,
29        "items" : [
30         {
31          "$ xns" : "WebKit",
32          "* init" : [
33           " {",
34           "    // this may not work!?",
35           "    var settings =  this.el.get_settings();",
36           "    settings.enable_write_console_messages_to_stdout = true;",
37           "     ",
38           "    var fs= new FakeServer(this.el);",
39           "    fs.ref();",
40           "    // this was an attempt to change the url perms.. did not work..",
41           "    // settings.enable_file_access_from_file_uris = true;",
42           "    // settings.enable_offline_web_application_cache - true;",
43           "    // settings.enable_universal_access_from_file_uris = true;",
44           "   ",
45           "     ",
46           "    ",
47           "    ",
48           "    ",
49           "",
50           "     // FIXME - base url of script..",
51           "     // we need it so some of the database features work.",
52           "    this.el.load_html( \"Render not ready\" , ",
53           "            //fixme - should be a config option!",
54           "            // or should we catch stuff and fix it up..",
55           "            \"xhttp://localhost/roobuilder/\"",
56           "    );",
57           "        ",
58           "        ",
59           "    ",
60           "    ",
61           "}",
62           ""
63          ],
64          "* pack" : "set_child",
65          "id" : "webview",
66          "listeners" : {
67           "script_dialog" : [
68            " (dialog) => {",
69            "    if (this.el == null) {",
70            "        return true;",
71            "    }",
72            "    ",
73            "     var msg = dialog.get_message();",
74            "     if (msg.length < 4) {",
75            "        return false;",
76            "     }",
77            "     if (msg.substring(0,4) != \"IPC:\") {",
78            "         return false;",
79            "     }",
80            "     var ar = msg.split(\":\", 3);",
81            "    if (ar.length < 3) {",
82            "        return false;",
83            "    }",
84            "    print(\"CMD: %s\\n\",ar[1]);",
85            "    print(\"ARGS: %s\\n\",ar[2]);",
86            "    switch(ar[1]) {",
87            "    ",
88            "        case \"SAVEHTML\":",
89            "            // print(\"%sw\",ar[2]);",
90            "            //  _this.file.saveHTML(ar[2]);",
91            "            return true;",
92            "            ",
93            "        case \"OUT\":",
94            "            _this.result_json = ar[2];",
95            "            return true;",
96            "            ",
97            "        default:",
98            "            return true;",
99            "    }",
100            "    ",
101            "}"
102           ]
103          },
104          "xtype" : "WebView"
105         }
106        ],
107        "xtype" : "ScrolledWindow"
108       }
109      ],
110      "xtype" : "Box"
111     },
112     {
113      "$ xns" : "Gtk",
114      "* pack" : "add_action_widget,3",
115      "label" : "Reload",
116      "xtype" : "Button"
117     },
118     {
119      "$ xns" : "Gtk",
120      "* pack" : "add_action_widget,0",
121      "label" : "Cancel",
122      "xtype" : "Button"
123     },
124     {
125      "$ xns" : "Gtk",
126      "* pack" : "add_action_widget,1",
127      "label" : "OK",
128      "xtype" : "Button"
129     }
130    ],
131    "listeners" : {
132     "response" : [
133      "(response_id) => {",
134      "",
135      " \t\t ",
136      "\t\t     if (response_id == 1) { // OK...",
137      "\t\t         var loop = new MainLoop();",
138      "\t\t         // run toBJS to get the data... (calls back into alert handler)",
139      "\t\t            _this.result_json = \"\";",
140      "\t\t             this.webview.el.run_javascript.begin(\"Editor.\" + this.cls + \".panel.toBJS();\", null, (obj, res) => {",
141      "\t\t                 try {",
142      "\t\t                    this.webview.el.run_javascript.end(res);",
143      "\t\t                } catch(Error e) {",
144      "\t\t            ",
145      "\t\t                 }",
146      "\t\t                 loop.quit();",
147      "\t\t             });",
148      "\t\t             loop.run();",
149      "\t\t             _this.complete(_this.result_json);",
150      "\t\t             ",
151      "\t\t         ",
152      "\t\t//           print(\"LOOP END?\");",
153      "\t\t         // try and get the resopse...",
154      "\t\t        break;",
155      "\t\t     }",
156      "\t\t    if (response_id < 1) {",
157      "\t\t        this.el.hide();",
158      "\t\t         _this.complete(\"\");",
159      "\t\t    }",
160      "\t\t    // keep showing...?",
161      " \t\t}",
162      ""
163     ]
164    },
165    "string cls" : "",
166    "string result_json" : "",
167    "string tmpjs" : "",
168    "utf8 title" : "Add / Edit Component",
169    "xtype" : "Dialog",
170    "| bool has_plugin" : [
171     "(string cls) {",
172     "",
173     "     return GLib.FileUtils.test(",
174     "            BuilderApplication.configDirectory() + \"/resources/Editors/Editor.\" + cls + \".js\",",
175     "            GLib.FileTest.IS_REGULAR",
176     "      );",
177     "    ",
178     "",
179     "",
180     "}",
181     ""
182    ],
183    "| void showIt" : [
184     " // for result hook into complete",
185     " ",
186     " (Gtk.Window ?parent, Project.Project project, string cls, string tbl) {// JsRender.Node node) {",
187     " ",
188     " \tthis.cls = cls;",
189     " ",
190     "    if (parent  != null) {",
191     "        this.el.set_transient_for(parent);",
192     "        this.el.modal = true;",
193     "    }",
194     "    this.result_json = \"\";",
195     "     var  db = project.roo_database;",
196     "      ",
197     "     this.el.show();",
198     "      ",
199     " ",
200     "    ",
201     "        var runhtml = \"<script type=\\\"text/javascript\\\">\\n\" ;",
202     "        string builderhtml;",
203     "        ",
204     "        try {",
205     "            GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + \"/resources/roo.builder.js\", out builderhtml);",
206     "        } catch (Error e) {",
207     "            builderhtml = \"\";",
208     "        }",
209     "        ",
210     "",
211     "        runhtml += builderhtml + \"\\n\";",
212     "        ",
213     "        ",
214     "        runhtml += \"\\n\" +",
215     "            \"Builder.saveHTML = function() {};\\n\" + ",
216     "\t    \"Roo.onReady(function() {\\n\" +",
217     "",
218     "\t    \"Roo.XComponent.build();\\n\" +",
219     "\t    \"});\\n\";",
220     "\t",
221     "\t",
222     "        ",
223     "",
224     "        var ar = db.readForeignKeys(tbl);",
225     "        var  generator = new Json.Generator ();",
226     "        var  root = new Json.Node(Json.NodeType.OBJECT);",
227     "        root.init_object(ar);",
228     "        generator.set_root (root);",
229     "        ",
230     "        generator.pretty = true;",
231     "        generator.indent = 4;",
232     "        ",
233     "        runhtml += \"\\n\" +",
234     "        \" Roo.XComponent.on('buildcomplete', function() {\\n\" +",
235     "         \"    Editor.\" + cls + \".panel.loadData(\" + generator.to_data (null) + \"); \" +",
236     "        \"});\\n\";",
237     "",
238     "        ",
239     "\t",
240     "\t",
241     "",
242     "        runhtml += \"</script>\\n\" ;",
243     "",
244     "        print(runhtml);",
245     "        // fix to make sure they are the same..",
246     "        ",
247     "        // need to modify paths",
248     "",
249     "        string inhtml;",
250     "        try {",
251     "            GLib.FileUtils.get_contents(",
252     "                BuilderApplication.configDirectory() + \"/resources/roo.builder.html\"",
253     "                    , out inhtml);",
254     "        ",
255     "        } catch (Error e) {",
256     "            inhtml = \"\";",
257     "        }",
258     "        // fetch the json from the database...",
259     "        ",
260     "        //print(runhtml);",
261     "        ",
262     "        var html = inhtml.replace(\"</head>\", runhtml + // + this.runhtml + ",
263     "            \"<script type=\\\"text/javascript\\\" src=\\\"resources://localhost/Editors/Editor.\" + cls + \".js\\\"></script>\" + ",
264     "      ",
265     "                        ",
266     "        \"</head>\");",
267     "        //print(\"LOAD HTML \" + html);",
268     "        ",
269     "         //var rootURL = _this.file.project.rootURL;",
270     "   ",
271     "        ",
272     "        ",
273     "        this.webview.el.load_html( html , ",
274     "            //fixme - should be a config option!",
275     "            \"xhttp://localhost/roobuilder/\"",
276     "        );",
277     "    ",
278     "       ",
279     "    ",
280     "    ",
281     "    ",
282     "}",
283     ""
284    ]
285   }
286  ],
287  "modOrder" : "",
288  "name" : "DialogPluginWebkit",
289  "parent" : "",
290  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/DialogPluginWebkit.bjs",
291  "permname" : "",
292  "title" : ""
293 }