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;
309 public GLib.DateTime lastRedraw;
310 public string runhtml;
311 public bool pendingRedraw;
314 public Xcls_view(Xcls_WindowRooView _owner )
318 this.el = new WebKit.WebView();
321 this.renderedData = "";
322 this.refreshRequired = false;
324 this.lastRedraw = null;
326 this.pendingRedraw = false;
328 // set gobject values
333 // this may not work!?
334 var settings = this.el.get_settings();
335 settings.enable_developer_extras = true;
338 var fs= new FakeServer(this.el);
340 // this was an attempt to change the url perms.. did not work..
341 // settings.enable_file_access_from_file_uris = true;
342 // settings.enable_offline_web_application_cache - true;
343 // settings.enable_universal_access_from_file_uris = true;
350 // FIXME - base url of script..
351 // we need it so some of the database features work.
352 this.el.load_html( "Render not ready" ,
353 //fixme - should be a config option!
354 // or should we catch stuff and fix it up..
355 "http://localhost/app.Builder/"
359 //this.el.open('file:///' + __script_path__ + '/../builder.html');
364 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
365 null, // list of targets
366 Gdk.DragAction.COPY // what to do with data after dropped
369 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
370 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
372 GLib.Timeout.add_seconds(1, () =>{
373 //print("run refresh?");
374 if (this.el == null) {
385 this.el.script_dialog.connect( (dialog) => {
386 if (this.el == null) {
390 var msg = dialog.get_message();
391 if (msg.length < 4) {
394 if (msg.substring(0,4) != "IPC:") {
397 var ar = msg.split(":", 3);
403 _this.file.saveHTML(ar[2]);
410 this.el.show.connect( ( ) => {
411 this.initInspector();;
413 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
416 print("TARGET: drag-drop");
417 var is_valid_drop_site = true;
422 w, // will receive 'drag-data-received' signal
423 ctx, /* represents the current state of the DnD
424 this.get('/Window').atoms["STRING"], /* the target type we want
429 /* No target offered by source => error
432 return is_valid_drop_site;
437 // user defined functions
438 public void reInit () {
440 // if this happens destroy the webkit..
442 this.el.stop_loading();
444 if (_this.viewbox.el.get_parent() == null) {
449 _this.viewbox.el.remove(_this.viewcontainer.el);
450 _this.el.remove(_this.inspectorcontainer.el);
452 // destory seems to cause problems.
454 //_this.viewcontainer.el.destroy();
455 //_this.inspectorcontainer.el.destroy();
456 var inv =new Xcls_inspectorcontainer(_this);
458 _this.el.pack2(inv.el,true,true);
462 var nv =new Xcls_viewcontainer(_this);
464 _this.viewbox.el.pack_end(nv.el,true,true,0);
469 //while(Gtk.events_pending ()) Gtk.main_iteration ();
470 //_this.view.renderJS(true);
471 _this.view.refreshRequired = true;
473 public void runRefresh ()
475 // this is run every 2 seconds from the init..
479 if (!this.refreshRequired) {
480 // print("no refresh required");
484 if (this.lastRedraw != null) {
485 // do not redraw if last redraw was less that 5 seconds ago.
486 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
491 if (_this.file == null) {
496 this.refreshRequired = false;
497 // print("HTML RENDERING");
500 //this.get('/BottomPane').el.show();
501 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
502 _this.file.webkit_page_id = this.el.get_page_id();
504 var js = _this.file.toSourcePreview();
513 var project = _this.file.project;
515 //print (project.fn);
516 // set it to non-empty.
518 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
521 // this.runhtml = this.runhtml || '';
524 // then we need to reload the browser using
525 // load_html_string..
527 // then trigger a redraw once it's loaded..
528 this.pendingRedraw = true;
530 var runhtml = "<script type=\"text/javascript\">\n" ;
534 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
536 runhtml += builderhtml + "\n";
537 runhtml += "</script>\n" ;
539 // fix to make sure they are the same..
540 this.runhtml = project.runhtml;
541 // need to modify paths
544 var base_template = _this.file.project.base_template;
546 if (base_template.length > 0 && !FileUtils.test(
547 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
549 print("invalid base_template name - using default: %s\n", base_template);
554 GLib.FileUtils.get_contents(
555 BuilderApplication.configDirectory() + "/resources/" +
556 (base_template.length > 0 ? base_template : "roo.builder.html")
560 this.renderedData = js;
563 string js_src = js + "\n" +
564 "Roo.onReady(function() {\n" +
565 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
566 "Roo.XComponent.build();\n" +
569 // print("render js: " + js);
571 // console.log('not loaded yet');
573 this.lastRedraw = new DateTime.now_local();
575 var html = inhtml.replace("</head>", runhtml + this.runhtml +
577 "<script type=\"text/javascript\">\n" +
582 //print("LOAD HTML " + html);
584 var rootURL = _this.file.project.rootURL;
588 this.el.load_html( html ,
589 //fixme - should be a config option!
590 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
593 // force the inspector...
594 this.initInspector();
596 // - no need for this, the builder javascript will call it when build is complete
597 //GLib.Timeout.add_seconds(1, () => {
598 // this.el.run_javascript("Builder.saveHTML()",null);
601 // print( "before render" + this.lastRedraw);
602 // print( "after render" + (new Date()));
605 public void initInspector () {
607 if (this.inspector == this.el.get_inspector()) {
608 this.inspector.show();
609 this.inspector.open_window();
610 print("init inspecter called, and inspector is the same as existing\n");
613 print("new inspector?\n");
615 this.inspector = this.el.get_inspector();
616 this.inspector.ref();
618 // got a new inspector...
620 this.inspector.open_window.connect(() => {
621 this.inspector = this.el.get_inspector();
622 print("inspector attach\n");
623 var wv = this.inspector.get_web_view();
625 print("got inspector web view\n");
627 var cn = _this.inspectorcontainer.el.get_child();
629 _this.inspectorcontainer.el.remove(cn);
632 _this.inspectorcontainer.el.add(wv);
635 //this.inspector.close();
637 //this.inspector = null;
644 this.inspector.closed.connect(() => {
645 print("inspector closed?!?");
646 // if this happens destroy the webkit..
648 this.el.stop_loading();
650 if (_this.viewbox.el.get_parent() == null) {
655 _this.viewbox.el.remove(_this.viewcontainer.el);
656 _this.el.remove(_this.inspectorcontainer.el);
658 // destory seems to cause problems.
660 //_this.viewcontainer.el.destroy();
661 //_this.inspectorcontainer.el.destroy();
664 var nv =new Xcls_viewcontainer(_this);
666 _this.viewbox.el.pack_end(nv.el,true,true,0);
668 var inv =new Xcls_inspectorcontainer(_this);
670 _this.el.pack2(inv.el,true,true);
674 //while(Gtk.events_pending ()) Gtk.main_iteration ();
675 //_this.view.renderJS(true);
676 _this.view.refreshRequired = true;
680 this.inspector.show();
682 public void renderJS (bool force) {
684 // this is the public redraw call..
685 // we refresh in a loop privately..
686 var autodraw = _this.AutoRedraw.el.active;
687 if (!autodraw && !force) {
688 print("Skipping redraw - no force, and autodraw off");
692 this.refreshRequired = true;
695 public class Xcls_inspectorcontainer : Object
697 public Gtk.ScrolledWindow el;
698 private Xcls_WindowRooView _this;
704 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
707 _this.inspectorcontainer = this;
708 this.el = new Gtk.ScrolledWindow( null, null );
712 // set gobject values
713 this.el.shadow_type = Gtk.ShadowType.IN;
717 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
720 // user defined functions