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);
261 FakeServerCache.clear();
267 // user defined functions
269 public class Xcls_viewcontainer : Object
271 public Gtk.ScrolledWindow el;
272 private Xcls_WindowRooView _this;
278 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
281 _this.viewcontainer = this;
282 this.el = new Gtk.ScrolledWindow( null, null );
286 // set gobject values
287 this.el.shadow_type = Gtk.ShadowType.IN;
288 var child_0 = new Xcls_view( _this );
290 this.el.add ( child_0.el );
294 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
297 // user defined functions
299 public class Xcls_view : Object
301 public WebKit.WebView el;
302 private Xcls_WindowRooView _this;
306 public string renderedData;
307 public bool refreshRequired;
308 public WebKit.WebInspector inspector;
311 public GLib.DateTime lastRedraw;
312 public string runhtml;
313 public bool pendingRedraw;
316 public Xcls_view(Xcls_WindowRooView _owner )
320 this.el = new WebKit.WebView();
323 this.renderedData = "";
324 this.refreshRequired = false;
327 this.lastRedraw = null;
329 this.pendingRedraw = false;
331 // set gobject values
336 // this may not work!?
337 var settings = this.el.get_settings();
338 settings.enable_developer_extras = true;
341 var fs= new FakeServer(this.el);
343 // this was an attempt to change the url perms.. did not work..
344 // settings.enable_file_access_from_file_uris = true;
345 // settings.enable_offline_web_application_cache - true;
346 // settings.enable_universal_access_from_file_uris = true;
353 // FIXME - base url of script..
354 // we need it so some of the database features work.
355 this.el.load_html( "Render not ready" ,
356 //fixme - should be a config option!
357 // or should we catch stuff and fix it up..
358 "http://localhost/app.Builder/"
362 //this.el.open('file:///' + __script_path__ + '/../builder.html');
367 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
368 null, // list of targets
369 Gdk.DragAction.COPY // what to do with data after dropped
372 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
373 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
375 GLib.Timeout.add_seconds(1, () =>{
376 //print("run refresh?");
377 if (this.el == null) {
388 this.el.script_dialog.connect( (dialog) => {
389 if (this.el == null) {
393 var msg = dialog.get_message();
394 if (msg.length < 4) {
397 if (msg.substring(0,4) != "IPC:") {
400 var ar = msg.split(":", 3);
406 _this.file.saveHTML(ar[2]);
413 this.el.show.connect( ( ) => {
414 this.initInspector();;
416 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
419 print("TARGET: drag-drop");
420 var is_valid_drop_site = true;
425 w, // will receive 'drag-data-received' signal
426 ctx, /* represents the current state of the DnD
427 this.get('/Window').atoms["STRING"], /* the target type we want
432 /* No target offered by source => error
435 return is_valid_drop_site;
438 this.el.load_changed.connect( (le) => {
439 if (le != WebKit.LoadEvent.FINISHED) {
442 if (this.runjs.length < 1) {
445 // this.el.run_javascript(this.runjs, null);
446 FakeServerCache.remove( this.runjs);
451 // user defined functions
452 public void reInit () {
454 // if this happens destroy the webkit..
456 this.el.stop_loading();
458 if (_this.viewbox.el.get_parent() == null) {
463 _this.viewbox.el.remove(_this.viewcontainer.el);
464 _this.el.remove(_this.inspectorcontainer.el);
466 // destory seems to cause problems.
468 //_this.viewcontainer.el.destroy();
469 //_this.inspectorcontainer.el.destroy();
470 var inv =new Xcls_inspectorcontainer(_this);
472 _this.el.pack2(inv.el,true,true);
476 var nv =new Xcls_viewcontainer(_this);
478 _this.viewbox.el.pack_end(nv.el,true,true,0);
483 //while(Gtk.events_pending ()) Gtk.main_iteration ();
484 //_this.view.renderJS(true);
485 _this.view.refreshRequired = true;
487 public void runRefresh ()
489 // this is run every 2 seconds from the init..
493 if (!this.refreshRequired) {
494 // print("no refresh required");
498 if (this.lastRedraw != null) {
499 // do not redraw if last redraw was less that 5 seconds ago.
500 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
505 if (_this.file == null) {
510 this.refreshRequired = false;
511 // print("HTML RENDERING");
514 //this.get('/BottomPane').el.show();
515 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
516 _this.file.webkit_page_id = this.el.get_page_id();
518 var js = _this.file.toSourcePreview();
527 var project = _this.file.project;
529 //print (project.fn);
530 // set it to non-empty.
532 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
535 // this.runhtml = this.runhtml || '';
538 // then we need to reload the browser using
539 // load_html_string..
541 // then trigger a redraw once it's loaded..
542 this.pendingRedraw = true;
544 var runhtml = "<script type=\"text/javascript\">\n" ;
548 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
550 runhtml += builderhtml + "\n";
551 runhtml += "</script>\n" ;
553 // fix to make sure they are the same..
554 this.runhtml = project.runhtml;
555 // need to modify paths
558 var base_template = _this.file.project.base_template;
560 if (base_template.length > 0 && !FileUtils.test(
561 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
563 print("invalid base_template name - using default: %s\n", base_template);
568 GLib.FileUtils.get_contents(
569 BuilderApplication.configDirectory() + "/resources/" +
570 (base_template.length > 0 ? base_template : "roo.builder.html")
574 this.renderedData = js;
577 string js_src = js + "\n" +
578 "Roo.onReady(function() {\n" +
579 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
580 "Roo.XComponent.build();\n" +
583 // print("render js: " + js);
585 // console.log('not loaded yet');
587 this.lastRedraw = new DateTime.now_local();
590 //this.runjs = js_src;
591 var fc = FakeServerCache.factory_with_data(js_src);
592 this.runjs = fc.fname;
594 var html = inhtml.replace("</head>", runhtml + this.runhtml +
595 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
596 // "<script type=\"text/javascript\">\n" +
601 //print("LOAD HTML " + html);
603 var rootURL = _this.file.project.rootURL;
607 this.el.load_html( html ,
608 //fixme - should be a config option!
609 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
612 // force the inspector...
613 // this.initInspector();
615 // - no need for this, the builder javascript will call it when build is complete
616 //GLib.Timeout.add_seconds(1, () => {
617 // this.el.run_javascript("Builder.saveHTML()",null);
620 // print( "before render" + this.lastRedraw);
621 // print( "after render" + (new Date()));
624 public void initInspector () {
626 /* if (this.inspector == this.el.get_inspector()) {
627 this.inspector.show();
628 this.inspector.open_window();
629 print("init inspecter called, and inspector is the same as existing\n");
632 print("new inspector?\n");
634 this.inspector = this.el.get_inspector();
635 this.inspector.ref();
637 // got a new inspector...
639 this.inspector.open_window.connect(() => {
640 this.inspector = this.el.get_inspector();
641 print("inspector attach\n");
642 var wv = this.inspector.get_web_view();
644 print("got inspector web view\n");
646 var cn = _this.inspectorcontainer.el.get_child();
648 _this.inspectorcontainer.el.remove(cn);
651 _this.inspectorcontainer.el.add(wv);
654 //this.inspector.close();
656 //this.inspector = null;
664 this.inspector.closed.connect(() => {
665 print("inspector closed?!?");
666 // if this happens destroy the webkit..
668 this.el.stop_loading();
670 if (_this.viewbox.el.get_parent() == null) {
675 _this.viewbox.el.remove(_this.viewcontainer.el);
676 _this.el.remove(_this.inspectorcontainer.el);
678 // destory seems to cause problems.
680 //_this.viewcontainer.el.destroy();
681 //_this.inspectorcontainer.el.destroy();
684 var nv =new Xcls_viewcontainer(_this);
686 _this.viewbox.el.pack_end(nv.el,true,true,0);
688 var inv =new Xcls_inspectorcontainer(_this);
690 _this.el.pack2(inv.el,true,true);
694 //while(Gtk.events_pending ()) Gtk.main_iteration ();
695 //_this.view.renderJS(true);
696 _this.view.refreshRequired = true;
701 this.inspector.show();
703 public void renderJS (bool force) {
705 // this is the public redraw call..
706 // we refresh in a loop privately..
707 var autodraw = _this.AutoRedraw.el.active;
708 if (!autodraw && !force) {
709 print("Skipping redraw - no force, and autodraw off");
713 this.refreshRequired = true;
716 public class Xcls_inspectorcontainer : Object
718 public Gtk.ScrolledWindow el;
719 private Xcls_WindowRooView _this;
725 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
728 _this.inspectorcontainer = this;
729 this.el = new Gtk.ScrolledWindow( null, null );
733 // set gobject values
734 this.el.shadow_type = Gtk.ShadowType.IN;
738 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
741 // user defined functions