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.Paned( Gtk.Orientation.VERTICAL );
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.Box( Gtk.Orientation.VERTICAL, 0 );
138 // set gobject values
139 this.el.homogeneous = false;
140 var child_0 = new Xcls_Box3( _this );
142 this.el.pack_start ( child_0.el , false,true,0 );
143 var child_1 = new Xcls_viewcontainer( _this );
145 this.el.pack_end ( child_1.el , true,true,0 );
148 // user defined functions
150 public class Xcls_Box3 : Object
153 private Xcls_WindowRooView _this;
159 public Xcls_Box3(Xcls_WindowRooView _owner )
162 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
166 // set gobject values
167 this.el.homogeneous = true;
168 this.el.height_request = 20;
169 this.el.vexpand = false;
170 var child_0 = new Xcls_Button4( _this );
172 this.el.pack_start ( child_0.el , false,false,0 );
173 var child_1 = new Xcls_AutoRedraw( _this );
175 this.el.pack_start ( child_1.el , false,false,0 );
176 var child_2 = new Xcls_Button6( _this );
178 this.el.pack_start ( child_2.el , false,false,0 );
181 // user defined functions
183 public class Xcls_Button4 : Object
185 public Gtk.Button el;
186 private Xcls_WindowRooView _this;
192 public Xcls_Button4(Xcls_WindowRooView _owner )
195 this.el = new Gtk.Button();
199 // set gobject values
200 this.el.label = "Redraw";
203 this.el.clicked.connect( ( ) => {
204 _this.view.renderJS( true);
208 // user defined functions
211 public class Xcls_AutoRedraw : Object
213 public Gtk.CheckButton el;
214 private Xcls_WindowRooView _this;
220 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
223 _this.AutoRedraw = this;
224 this.el = new Gtk.CheckButton();
228 // set gobject values
229 this.el.active = true;
230 this.el.label = "Auto Redraw On";
233 this.el.toggled.connect( (state) => {
234 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
238 // user defined functions
241 public class Xcls_Button6 : Object
243 public Gtk.Button el;
244 private Xcls_WindowRooView _this;
250 public Xcls_Button6(Xcls_WindowRooView _owner )
253 this.el = new Gtk.Button();
257 // set gobject values
258 this.el.label = "Full Redraw";
261 this.el.clicked.connect( () => {
262 _this.view.redraws = 99;
263 _this.view.el.web_context.clear_cache();
264 //_this.view.renderJS(true);
265 FakeServerCache.clear();
271 // user defined functions
275 public class Xcls_viewcontainer : Object
277 public Gtk.ScrolledWindow el;
278 private Xcls_WindowRooView _this;
284 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
287 _this.viewcontainer = this;
288 this.el = new Gtk.ScrolledWindow( null, null );
292 // set gobject values
293 this.el.shadow_type = Gtk.ShadowType.IN;
294 var child_0 = new Xcls_view( _this );
296 this.el.add ( child_0.el );
300 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
303 // user defined functions
305 public class Xcls_view : Object
307 public WebKit.WebView el;
308 private Xcls_WindowRooView _this;
312 public string renderedData;
313 public bool refreshRequired;
314 public WebKit.WebInspector inspector;
317 public GLib.DateTime lastRedraw;
318 public string runhtml;
319 public bool pendingRedraw;
322 public Xcls_view(Xcls_WindowRooView _owner )
326 this.el = new WebKit.WebView();
329 this.renderedData = "";
330 this.refreshRequired = false;
333 this.lastRedraw = null;
335 this.pendingRedraw = false;
337 // set gobject values
342 // this may not work!?
343 var settings = this.el.get_settings();
344 settings.enable_developer_extras = true;
347 var fs= new FakeServer(this.el);
349 // this was an attempt to change the url perms.. did not work..
350 // settings.enable_file_access_from_file_uris = true;
351 // settings.enable_offline_web_application_cache - true;
352 // settings.enable_universal_access_from_file_uris = true;
359 // FIXME - base url of script..
360 // we need it so some of the database features work.
361 this.el.load_html( "Render not ready" ,
362 //fixme - should be a config option!
363 // or should we catch stuff and fix it up..
364 "http://localhost/app.Builder/"
368 //this.el.open('file:///' + __script_path__ + '/../builder.html');
373 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
374 null, // list of targets
375 Gdk.DragAction.COPY // what to do with data after dropped
378 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
379 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
381 GLib.Timeout.add_seconds(1, () =>{
382 //print("run refresh?");
383 if (this.el == null) {
394 this.el.script_dialog.connect( (dialog) => {
395 if (this.el == null) {
399 var msg = dialog.get_message();
400 if (msg.length < 4) {
403 if (msg.substring(0,4) != "IPC:") {
406 var ar = msg.split(":", 3);
412 _this.file.saveHTML(ar[2]);
419 this.el.show.connect( ( ) => {
420 this.initInspector();;
422 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
425 print("TARGET: drag-drop");
426 var is_valid_drop_site = true;
431 w, // will receive 'drag-data-received' signal
432 ctx, /* represents the current state of the DnD
433 this.get('/Window').atoms["STRING"], /* the target type we want
438 /* No target offered by source => error
441 return is_valid_drop_site;
444 this.el.load_changed.connect( (le) => {
445 if (le != WebKit.LoadEvent.FINISHED) {
448 if (this.runjs.length < 1) {
451 // this.el.run_javascript(this.runjs, null);
452 FakeServerCache.remove( this.runjs);
457 // user defined functions
458 public void reInit () {
460 // if this happens destroy the webkit..
462 this.el.stop_loading();
464 if (_this.viewbox.el.get_parent() == null) {
469 _this.viewbox.el.remove(_this.viewcontainer.el);
470 _this.el.remove(_this.inspectorcontainer.el);
472 // destory seems to cause problems.
474 //_this.viewcontainer.el.destroy();
475 //_this.inspectorcontainer.el.destroy();
476 var inv =new Xcls_inspectorcontainer(_this);
478 _this.el.pack2(inv.el,true,true);
482 var nv =new Xcls_viewcontainer(_this);
484 _this.viewbox.el.pack_end(nv.el,true,true,0);
489 //while(Gtk.events_pending ()) Gtk.main_iteration ();
490 //_this.view.renderJS(true);
491 _this.view.refreshRequired = true;
493 public void runRefresh ()
495 // this is run every 2 seconds from the init..
499 if (!this.refreshRequired) {
500 // print("no refresh required");
504 if (this.lastRedraw != null) {
505 // do not redraw if last redraw was less that 5 seconds ago.
506 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
511 if (_this.file == null) {
516 this.refreshRequired = false;
517 // print("HTML RENDERING");
520 //this.get('/BottomPane').el.show();
521 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
522 _this.file.webkit_page_id = this.el.get_page_id();
524 var js = _this.file.toSourcePreview();
533 var project = _this.file.project;
535 //print (project.fn);
536 // set it to non-empty.
538 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
541 // this.runhtml = this.runhtml || '';
544 // then we need to reload the browser using
545 // load_html_string..
547 // then trigger a redraw once it's loaded..
548 this.pendingRedraw = true;
550 var runhtml = "<script type=\"text/javascript\">\n" ;
554 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
559 runhtml += builderhtml + "\n";
560 runhtml += "</script>\n" ;
562 // fix to make sure they are the same..
563 this.runhtml = project.runhtml;
564 // need to modify paths
567 var base_template = _this.file.project.base_template;
569 if (base_template.length > 0 && !FileUtils.test(
570 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
572 print("invalid base_template name - using default: %s\n", base_template);
577 GLib.FileUtils.get_contents(
578 BuilderApplication.configDirectory() + "/resources/" +
579 (base_template.length > 0 ? base_template : "roo.builder.html")
585 this.renderedData = js;
588 string js_src = js + "\n" +
589 "Roo.onReady(function() {\n" +
590 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
591 "Roo.XComponent.build();\n" +
594 // print("render js: " + js);
596 // console.log('not loaded yet');
598 this.lastRedraw = new DateTime.now_local();
601 //this.runjs = js_src;
602 var fc = FakeServerCache.factory_with_data(js_src);
603 this.runjs = fc.fname;
605 var html = inhtml.replace("</head>", runhtml + this.runhtml +
606 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
607 // "<script type=\"text/javascript\">\n" +
612 //print("LOAD HTML " + html);
614 var rootURL = _this.file.project.rootURL;
618 this.el.load_html( html ,
619 //fixme - should be a config option!
620 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
623 // force the inspector...
624 // this.initInspector();
626 // - no need for this, the builder javascript will call it when build is complete
627 //GLib.Timeout.add_seconds(1, () => {
628 // this.el.run_javascript("Builder.saveHTML()",null);
631 // print( "before render" + this.lastRedraw);
632 // print( "after render" + (new Date()));
635 public void initInspector () {
637 /* if (this.inspector == this.el.get_inspector()) {
638 this.inspector.show();
639 this.inspector.open_window();
640 print("init inspecter called, and inspector is the same as existing\n");
643 print("new inspector?\n");
645 this.inspector = this.el.get_inspector();
646 this.inspector.ref();
648 // got a new inspector...
650 this.inspector.open_window.connect(() => {
651 this.inspector = this.el.get_inspector();
652 print("inspector attach\n");
653 var wv = this.inspector.get_web_view();
655 print("got inspector web view\n");
657 var cn = _this.inspectorcontainer.el.get_child();
659 _this.inspectorcontainer.el.remove(cn);
662 _this.inspectorcontainer.el.add(wv);
665 //this.inspector.close();
667 //this.inspector = null;
675 this.inspector.closed.connect(() => {
676 print("inspector closed?!?");
677 // if this happens destroy the webkit..
679 this.el.stop_loading();
681 if (_this.viewbox.el.get_parent() == null) {
686 _this.viewbox.el.remove(_this.viewcontainer.el);
687 _this.el.remove(_this.inspectorcontainer.el);
689 // destory seems to cause problems.
691 //_this.viewcontainer.el.destroy();
692 //_this.inspectorcontainer.el.destroy();
695 var nv =new Xcls_viewcontainer(_this);
697 _this.viewbox.el.pack_end(nv.el,true,true,0);
699 var inv =new Xcls_inspectorcontainer(_this);
701 _this.el.pack2(inv.el,true,true);
705 //while(Gtk.events_pending ()) Gtk.main_iteration ();
706 //_this.view.renderJS(true);
707 _this.view.refreshRequired = true;
712 this.inspector.show();
714 public void renderJS (bool force) {
716 // this is the public redraw call..
717 // we refresh in a loop privately..
718 var autodraw = _this.AutoRedraw.el.active;
719 if (!autodraw && !force) {
720 print("Skipping redraw - no force, and autodraw off");
724 this.refreshRequired = true;
730 public class Xcls_inspectorcontainer : Object
732 public Gtk.ScrolledWindow el;
733 private Xcls_WindowRooView _this;
739 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
742 _this.inspectorcontainer = this;
743 this.el = new Gtk.ScrolledWindow( null, null );
747 // set gobject values
748 this.el.shadow_type = Gtk.ShadowType.IN;
752 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
755 // user defined functions