1 static Xcls_WindowRooView _WindowRooView;
3 public class Xcls_WindowRooView : Object
6 private Xcls_WindowRooView _this;
8 public static Xcls_WindowRooView singleton()
10 if (_WindowRooView == null) {
11 _WindowRooView= new Xcls_WindowRooView();
13 return _WindowRooView;
15 public Xcls_viewbox viewbox;
16 public Xcls_AutoRedraw AutoRedraw;
17 public Xcls_viewcontainer viewcontainer;
18 public Xcls_view view;
19 public Xcls_inspectorcontainer inspectorcontainer;
22 public JsRender.JsRender file;
25 public Xcls_WindowRooView()
28 this.el = new Gtk.VPaned();
33 var child_0 = new Xcls_viewbox( _this );
35 this.el.pack1 ( child_0.el , true,true );
36 var child_1 = new Xcls_inspectorcontainer( _this );
38 this.el.pack2 ( child_1.el , true,true );
41 // user defined functions
42 public void createThumb () {
45 if (this.file == null) {
48 var filename = this.file.getIconFileName(false);
50 var win = this.el.get_parent_window();
51 var width = win.get_width();
52 var height = win.get_height();
54 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);
56 screenshot.save(filename,"png");
65 var p = new WebKit.PrintOperation(_this.view.el);
67 var ps = new Gtk.PrintSettings();
68 ps.set_printer("Print to File");
69 ps.set("output-file-format", "pdf");
70 ps.set("output-uri", "file://" + filename + ".pdf");
72 // find the printer...
75 var ar = Gtk.PaperSize.get_paper_sizes(false);
76 var psetup = new Gtk.PageSetup();
77 for(var i = 0; i < ar.length(); i++) {
78 if (ar.nth_data(i).get_name() =="iso_a4") {
79 psetup.set_paper_size(ar.nth_data(i));
82 psetup.set_orientation(Gtk.PageOrientation.LANDSCAPE);
85 p.set_page_setup(psetup);
87 p.set_print_settings(ps);
89 p.finished.connect(() => {
90 print("creating thumbnail for " + filename + ".pdf\n");
91 var s = new Cairo.PdfSurface(filename + ".pdf", 400,400);
93 s.write_to_png (filename);
95 // var f = GLib.File.new_for_path (filename + ".pdf");
102 // should we hold until it's printed...
113 public void loadFile (JsRender.JsRender file)
116 this.view.renderJS(true);
118 public void requestRedraw () {
119 this.view.renderJS(false);
121 public class Xcls_viewbox : Object
124 private Xcls_WindowRooView _this;
130 public Xcls_viewbox(Xcls_WindowRooView _owner )
133 _this.viewbox = this;
134 this.el = new Gtk.VBox( false, 0 );
138 // set gobject values
139 var child_0 = new Xcls_HBox3( _this );
141 this.el.pack_start ( child_0.el , false,true,0 );
142 var child_1 = new Xcls_viewcontainer( _this );
144 this.el.pack_end ( child_1.el , true,true,0 );
147 // user defined functions
149 public class Xcls_HBox3 : Object
152 private Xcls_WindowRooView _this;
158 public Xcls_HBox3(Xcls_WindowRooView _owner )
161 this.el = new Gtk.HBox( true, 0 );
165 // set gobject values
166 this.el.height_request = 20;
167 this.el.vexpand = false;
168 var child_0 = new Xcls_Button4( _this );
170 this.el.pack_start ( child_0.el , false,false,0 );
171 var child_1 = new Xcls_AutoRedraw( _this );
173 this.el.pack_start ( child_1.el , false,false,0 );
174 var child_2 = new Xcls_Button6( _this );
176 this.el.pack_start ( child_2.el , false,false,0 );
179 // user defined functions
181 public class Xcls_Button4 : Object
183 public Gtk.Button el;
184 private Xcls_WindowRooView _this;
190 public Xcls_Button4(Xcls_WindowRooView _owner )
193 this.el = new Gtk.Button();
197 // set gobject values
198 this.el.label = "Redraw";
201 this.el.clicked.connect( ( ) => {
202 _this.view.renderJS( true);
206 // user defined functions
208 public class Xcls_AutoRedraw : Object
210 public Gtk.CheckButton el;
211 private Xcls_WindowRooView _this;
217 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
220 _this.AutoRedraw = this;
221 this.el = new Gtk.CheckButton();
225 // set gobject values
226 this.el.active = true;
227 this.el.label = "Auto Redraw On";
230 this.el.toggled.connect( (state) => {
231 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
235 // user defined functions
237 public class Xcls_Button6 : Object
239 public Gtk.Button el;
240 private Xcls_WindowRooView _this;
246 public Xcls_Button6(Xcls_WindowRooView _owner )
249 this.el = new Gtk.Button();
253 // set gobject values
254 this.el.label = "Full Redraw";
257 this.el.clicked.connect( () => {
258 _this.view.redraws = 99;
259 _this.view.el.web_context.clear_cache();
260 _this.view.renderJS(true);
265 // user defined functions
267 public class Xcls_viewcontainer : Object
269 public Gtk.ScrolledWindow el;
270 private Xcls_WindowRooView _this;
276 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
279 _this.viewcontainer = this;
280 this.el = new Gtk.ScrolledWindow( null, null );
284 // set gobject values
285 this.el.shadow_type = Gtk.ShadowType.IN;
286 var child_0 = new Xcls_view( _this );
288 this.el.add ( child_0.el );
292 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
295 // user defined functions
297 public class Xcls_view : Object
299 public WebKit.WebView el;
300 private Xcls_WindowRooView _this;
304 public string renderedData;
305 public bool refreshRequired;
306 public WebKit.WebInspector inspector;
308 public GLib.DateTime lastRedraw;
309 public string runhtml;
310 public bool pendingRedraw;
313 public Xcls_view(Xcls_WindowRooView _owner )
317 this.el = new WebKit.WebView();
320 this.renderedData = "";
321 this.refreshRequired = false;
323 this.lastRedraw = null;
325 this.pendingRedraw = false;
327 // set gobject values
332 // this may not work!?
333 var settings = this.el.get_settings();
334 settings.enable_developer_extras = true;
337 var fs= new FakeServer(this.el);
339 // this was an attempt to change the url perms.. did not work..
340 // settings.enable_file_access_from_file_uris = true;
341 // settings.enable_offline_web_application_cache - true;
342 // settings.enable_universal_access_from_file_uris = true;
349 // FIXME - base url of script..
350 // we need it so some of the database features work.
351 this.el.load_html( "Render not ready" ,
352 //fixme - should be a config option!
353 // or should we catch stuff and fix it up..
354 "http://localhost/app.Builder/"
358 //this.el.open('file:///' + __script_path__ + '/../builder.html');
363 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
364 null, // list of targets
365 Gdk.DragAction.COPY // what to do with data after dropped
368 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
369 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
371 GLib.Timeout.add_seconds(1, () =>{
372 //print("run refresh?");
373 if (this.el == null) {
384 this.el.script_dialog.connect( (dialog) => {
385 if (this.el == null) {
389 var msg = dialog.get_message();
390 if (msg.length < 4) {
393 if (msg.substring(0,4) != "IPC:") {
396 var ar = msg.split(":", 3);
402 _this.file.saveHTML(ar[2]);
409 this.el.show.connect( ( ) => {
410 this.initInspector();;
412 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
415 print("TARGET: drag-drop");
416 var is_valid_drop_site = true;
421 w, // will receive 'drag-data-received' signal
422 ctx, /* represents the current state of the DnD
423 this.get('/Window').atoms["STRING"], /* the target type we want
428 /* No target offered by source => error
431 return is_valid_drop_site;
436 // user defined functions
437 public void runRefresh ()
439 // this is run every 2 seconds from the init..
443 if (!this.refreshRequired) {
444 // print("no refresh required");
448 if (this.lastRedraw != null) {
449 // do not redraw if last redraw was less that 5 seconds ago.
450 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
455 if (_this.file == null) {
460 this.refreshRequired = false;
461 // print("HTML RENDERING");
464 //this.get('/BottomPane').el.show();
465 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
466 _this.file.webkit_page_id = this.el.get_page_id();
468 var js = _this.file.toSourcePreview();
477 var project = _this.file.project;
479 //print (project.fn);
480 // set it to non-empty.
482 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
485 // this.runhtml = this.runhtml || '';
488 // then we need to reload the browser using
489 // load_html_string..
491 // then trigger a redraw once it's loaded..
492 this.pendingRedraw = true;
494 var runhtml = "<script type=\"text/javascript\">\n" ;
498 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
500 runhtml += builderhtml + "\n";
501 runhtml += "</script>\n" ;
503 // fix to make sure they are the same..
504 this.runhtml = project.runhtml;
505 // need to modify paths
508 var base_template = _this.file.project.base_template;
510 if (base_template.length > 0 && !FileUtils.test(
511 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
513 print("invalid base_template name - using default: %s\n", base_template);
518 GLib.FileUtils.get_contents(
519 BuilderApplication.configDirectory() + "/resources/" +
520 (base_template.length > 0 ? base_template : "roo.builder.html")
524 this.renderedData = js;
527 string js_src = js + "\n" +
528 "Roo.onReady(function() {\n" +
529 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
530 "Roo.XComponent.build();\n" +
533 // print("render js: " + js);
535 // console.log('not loaded yet');
537 this.lastRedraw = new DateTime.now_local();
539 var html = inhtml.replace("</head>", runhtml + this.runhtml +
541 "<script type=\"text/javascript\">\n" +
546 //print("LOAD HTML " + html);
548 var rootURL = _this.file.project.rootURL;
552 this.el.load_html( html ,
553 //fixme - should be a config option!
554 (rootURL.length > 0 ? rootURL : "http://localhost/app.Builder/")
557 // force the inspector...
558 this.initInspector();
560 // - no need for this, the builder javascript will call it when build is complete
561 //GLib.Timeout.add_seconds(1, () => {
562 // this.el.run_javascript("Builder.saveHTML()",null);
565 // print( "before render" + this.lastRedraw);
566 // print( "after render" + (new Date()));
569 public void initInspector () {
571 if (this.inspector == this.el.get_inspector()) {
572 this.inspector.show();
573 this.inspector.open_window();
574 print("init inspecter called, and inspector is the same as existing\n");
577 print("new inspector?\n");
579 this.inspector = this.el.get_inspector();
580 this.inspector.ref();
582 // got a new inspector...
584 this.inspector.open_window.connect(() => {
585 this.inspector = this.el.get_inspector();
586 print("inspector attach\n");
587 var wv = this.inspector.get_web_view();
589 print("got inspector web view\n");
590 _this.inspectorcontainer.el.add(wv);
593 //this.inspector.close();
595 //this.inspector = null;
602 this.inspector.closed.connect(() => {
603 print("inspector closed?!?");
604 // if this happens destroy the webkit..
606 this.el.stop_loading();
608 if (_this.viewbox.el.get_parent() == null) {
613 _this.viewbox.el.remove(_this.viewcontainer.el);
614 _this.el.remove(_this.inspectorcontainer.el);
616 // destory seems to cause problems.
618 //_this.viewcontainer.el.destroy();
619 //_this.inspectorcontainer.el.destroy();
622 var nv =new Xcls_viewcontainer(_this);
624 _this.viewbox.el.pack_end(nv.el,true,true,0);
626 var inv =new Xcls_inspectorcontainer(_this);
628 _this.el.pack2(inv.el,true,true);
632 //while(Gtk.events_pending ()) Gtk.main_iteration ();
633 //_this.view.renderJS(true);
634 _this.view.refreshRequired = true;
638 this.inspector.show();
640 public void renderJS (bool force) {
642 // this is the public redraw call..
643 // we refresh in a loop privately..
644 var autodraw = _this.AutoRedraw.el.active;
645 if (!autodraw && !force) {
646 print("Skipping redraw - no force, and autodraw off");
649 this.refreshRequired = true;
652 public class Xcls_inspectorcontainer : Object
654 public Gtk.ScrolledWindow el;
655 private Xcls_WindowRooView _this;
661 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
664 _this.inspectorcontainer = this;
665 this.el = new Gtk.ScrolledWindow( null, null );
669 // set gobject values
670 this.el.shadow_type = Gtk.ShadowType.IN;
674 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
677 // user defined functions