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 loadFile (JsRender.JsRender file)
45 this.view.renderJS(true);
47 public void createThumb () {
50 if (this.file == null) {
53 var filename = this.file.getIconFileName(false);
55 var win = this.el.get_parent_window();
56 var width = win.get_width();
57 var height = win.get_height();
59 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);
61 screenshot.save(filename,"png");
70 var p = new WebKit.PrintOperation(_this.view.el);
72 var ps = new Gtk.PrintSettings();
73 ps.set_printer("Print to File");
74 ps.set("output-file-format", "pdf");
75 ps.set("output-uri", "file://" + filename + ".pdf");
77 // find the printer...
80 var ar = Gtk.PaperSize.get_paper_sizes(false);
81 var psetup = new Gtk.PageSetup();
82 for(var i = 0; i < ar.length(); i++) {
83 if (ar.nth_data(i).get_name() =="iso_a4") {
84 psetup.set_paper_size(ar.nth_data(i));
87 psetup.set_orientation(Gtk.PageOrientation.LANDSCAPE);
90 p.set_page_setup(psetup);
92 p.set_print_settings(ps);
94 p.finished.connect(() => {
95 print("creating thumbnail for " + filename + ".pdf\n");
96 var s = new Cairo.PdfSurface(filename + ".pdf", 400,400);
98 s.write_to_png (filename);
100 // var f = GLib.File.new_for_path (filename + ".pdf");
107 // should we hold until it's printed...
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);
266 // user defined functions
268 public class Xcls_viewcontainer : Object
270 public Gtk.ScrolledWindow el;
271 private Xcls_WindowRooView _this;
277 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
280 _this.viewcontainer = this;
281 this.el = new Gtk.ScrolledWindow( null, null );
285 // set gobject values
286 this.el.shadow_type = Gtk.ShadowType.IN;
287 var child_0 = new Xcls_view( _this );
289 this.el.add ( child_0.el );
293 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
296 // user defined functions
298 public class Xcls_view : Object
300 public WebKit.WebView el;
301 private Xcls_WindowRooView _this;
305 public string renderedData;
306 public bool refreshRequired;
307 public WebKit.WebInspector inspector;
310 public GLib.DateTime lastRedraw;
311 public string runhtml;
312 public bool pendingRedraw;
315 public Xcls_view(Xcls_WindowRooView _owner )
319 this.el = new WebKit.WebView();
322 this.renderedData = "";
323 this.refreshRequired = false;
326 this.lastRedraw = null;
328 this.pendingRedraw = false;
330 // set gobject values
335 // this may not work!?
336 var settings = this.el.get_settings();
337 settings.enable_developer_extras = true;
340 var fs= new FakeServer(this.el);
342 // this was an attempt to change the url perms.. did not work..
343 // settings.enable_file_access_from_file_uris = true;
344 // settings.enable_offline_web_application_cache - true;
345 // settings.enable_universal_access_from_file_uris = true;
352 // FIXME - base url of script..
353 // we need it so some of the database features work.
354 this.el.load_html( "Render not ready" ,
355 //fixme - should be a config option!
356 // or should we catch stuff and fix it up..
357 "http://localhost/app.Builder/"
361 //this.el.open('file:///' + __script_path__ + '/../builder.html');
366 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
367 null, // list of targets
368 Gdk.DragAction.COPY // what to do with data after dropped
371 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
372 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
374 GLib.Timeout.add_seconds(1, () =>{
375 //print("run refresh?");
376 if (this.el == null) {
387 this.el.script_dialog.connect( (dialog) => {
388 if (this.el == null) {
392 var msg = dialog.get_message();
393 if (msg.length < 4) {
396 if (msg.substring(0,4) != "IPC:") {
399 var ar = msg.split(":", 3);
405 _this.file.saveHTML(ar[2]);
412 this.el.show.connect( ( ) => {
413 this.initInspector();;
415 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
418 print("TARGET: drag-drop");
419 var is_valid_drop_site = true;
424 w, // will receive 'drag-data-received' signal
425 ctx, /* represents the current state of the DnD
426 this.get('/Window').atoms["STRING"], /* the target type we want
431 /* No target offered by source => error
434 return is_valid_drop_site;
437 this.el.load_changed.connect( (le) => {
438 if (le != WebKit.LoadEvent.FINISHED) {
441 if (this.runjs.length < 1) {
444 // this.el.run_javascript(this.runjs, null);
449 // user defined functions
450 public void reInit () {
452 // if this happens destroy the webkit..
454 this.el.stop_loading();
456 if (_this.viewbox.el.get_parent() == null) {
461 _this.viewbox.el.remove(_this.viewcontainer.el);
462 _this.el.remove(_this.inspectorcontainer.el);
464 // destory seems to cause problems.
466 //_this.viewcontainer.el.destroy();
467 //_this.inspectorcontainer.el.destroy();
468 var inv =new Xcls_inspectorcontainer(_this);
470 _this.el.pack2(inv.el,true,true);
474 var nv =new Xcls_viewcontainer(_this);
476 _this.viewbox.el.pack_end(nv.el,true,true,0);
481 //while(Gtk.events_pending ()) Gtk.main_iteration ();
482 //_this.view.renderJS(true);
483 _this.view.refreshRequired = true;
485 public void runRefresh ()
487 // this is run every 2 seconds from the init..
491 if (!this.refreshRequired) {
492 // print("no refresh required");
496 if (this.lastRedraw != null) {
497 // do not redraw if last redraw was less that 5 seconds ago.
498 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
503 if (_this.file == null) {
508 this.refreshRequired = false;
509 // print("HTML RENDERING");
512 //this.get('/BottomPane').el.show();
513 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
514 _this.file.webkit_page_id = this.el.get_page_id();
516 var js = _this.file.toSourcePreview();
525 var project = _this.file.project;
527 //print (project.fn);
528 // set it to non-empty.
530 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
533 // this.runhtml = this.runhtml || '';
536 // then we need to reload the browser using
537 // load_html_string..
539 // then trigger a redraw once it's loaded..
540 this.pendingRedraw = true;
542 var runhtml = "<script type=\"text/javascript\">\n" ;
546 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
548 runhtml += builderhtml + "\n";
549 runhtml += "</script>\n" ;
551 // fix to make sure they are the same..
552 this.runhtml = project.runhtml;
553 // need to modify paths
556 var base_template = _this.file.project.base_template;
558 if (base_template.length > 0 && !FileUtils.test(
559 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
561 print("invalid base_template name - using default: %s\n", base_template);
566 GLib.FileUtils.get_contents(
567 BuilderApplication.configDirectory() + "/resources/" +
568 (base_template.length > 0 ? base_template : "roo.builder.html")
572 this.renderedData = js;
575 string js_src = js + "\n" +
576 "Roo.onReady(function() {\n" +
577 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
578 "Roo.XComponent.build();\n" +
581 // print("render js: " + js);
583 // console.log('not loaded yet');
585 this.lastRedraw = new DateTime.now_local();
588 //this.runjs = js_src;
589 var fc = FakeServerCache.factory_with_data(js_src);
592 var html = inhtml.replace("</head>", runhtml + this.runhtml +
593 "<script type=\"text/javascript\" src=\"xhttp://localhost/" + fc.fname + "\"></script>" +
594 // "<script type=\"text/javascript\">\n" +
599 //print("LOAD HTML " + html);
601 var rootURL = _this.file.project.rootURL;
605 this.el.load_html( html ,
606 //fixme - should be a config option!
607 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
610 // force the inspector...
611 // this.initInspector();
613 // - no need for this, the builder javascript will call it when build is complete
614 //GLib.Timeout.add_seconds(1, () => {
615 // this.el.run_javascript("Builder.saveHTML()",null);
618 // print( "before render" + this.lastRedraw);
619 // print( "after render" + (new Date()));
622 public void initInspector () {
624 /* if (this.inspector == this.el.get_inspector()) {
625 this.inspector.show();
626 this.inspector.open_window();
627 print("init inspecter called, and inspector is the same as existing\n");
630 print("new inspector?\n");
632 this.inspector = this.el.get_inspector();
633 this.inspector.ref();
635 // got a new inspector...
637 this.inspector.open_window.connect(() => {
638 this.inspector = this.el.get_inspector();
639 print("inspector attach\n");
640 var wv = this.inspector.get_web_view();
642 print("got inspector web view\n");
644 var cn = _this.inspectorcontainer.el.get_child();
646 _this.inspectorcontainer.el.remove(cn);
649 _this.inspectorcontainer.el.add(wv);
652 //this.inspector.close();
654 //this.inspector = null;
662 this.inspector.closed.connect(() => {
663 print("inspector closed?!?");
664 // if this happens destroy the webkit..
666 this.el.stop_loading();
668 if (_this.viewbox.el.get_parent() == null) {
673 _this.viewbox.el.remove(_this.viewcontainer.el);
674 _this.el.remove(_this.inspectorcontainer.el);
676 // destory seems to cause problems.
678 //_this.viewcontainer.el.destroy();
679 //_this.inspectorcontainer.el.destroy();
682 var nv =new Xcls_viewcontainer(_this);
684 _this.viewbox.el.pack_end(nv.el,true,true,0);
686 var inv =new Xcls_inspectorcontainer(_this);
688 _this.el.pack2(inv.el,true,true);
692 //while(Gtk.events_pending ()) Gtk.main_iteration ();
693 //_this.view.renderJS(true);
694 _this.view.refreshRequired = true;
699 this.inspector.show();
701 public void renderJS (bool force) {
703 // this is the public redraw call..
704 // we refresh in a loop privately..
705 var autodraw = _this.AutoRedraw.el.active;
706 if (!autodraw && !force) {
707 print("Skipping redraw - no force, and autodraw off");
711 this.refreshRequired = true;
714 public class Xcls_inspectorcontainer : Object
716 public Gtk.ScrolledWindow el;
717 private Xcls_WindowRooView _this;
723 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
726 _this.inspectorcontainer = this;
727 this.el = new Gtk.ScrolledWindow( null, null );
731 // set gobject values
732 this.el.shadow_type = Gtk.ShadowType.IN;
736 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
739 // user defined functions