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); }
294 // user defined functions
296 public class Xcls_view : Object
298 public WebKit.WebView el;
299 private Xcls_WindowRooView _this;
303 public string renderedData;
304 public bool refreshRequired;
305 public WebKit.WebInspector inspector;
307 public GLib.DateTime lastRedraw;
308 public string runhtml;
309 public bool pendingRedraw;
312 public Xcls_view(Xcls_WindowRooView _owner )
316 this.el = new WebKit.WebView();
319 this.renderedData = "";
320 this.refreshRequired = false;
322 this.lastRedraw = null;
324 this.pendingRedraw = false;
326 // set gobject values
331 // this may not work!?
332 var settings = this.el.get_settings();
333 settings.enable_developer_extras = true;
335 // this was an attempt to change the url perms.. did not work..
336 // settings.enable_file_access_from_file_uris = true;
337 // settings.enable_offline_web_application_cache - true;
338 // settings.enable_universal_access_from_file_uris = true;
345 // FIXME - base url of script..
346 // we need it so some of the database features work.
347 this.el.load_html( "Render not ready" ,
348 //fixme - should be a config option!
349 // or should we catch stuff and fix it up..
350 "http://localhost/app.Builder/"
354 //this.el.open('file:///' + __script_path__ + '/../builder.html');
359 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
360 null, // list of targets
361 Gdk.DragAction.COPY // what to do with data after dropped
364 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
365 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
367 GLib.Timeout.add_seconds(1, () =>{
368 //print("run refresh?");
369 if (this.el == null) {
379 this.el.script_dialog.connect( (dialog) => {
380 if (this.el == null) {
384 var msg = dialog.get_message();
385 if (msg.length < 4) {
388 if (msg.substring(0,4) != "IPC:") {
391 var ar = msg.split(":", 3);
397 _this.file.saveHTML(ar[2]);
404 this.el.show.connect( ( ) => {
405 this.initInspector();;
407 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
410 print("TARGET: drag-drop");
411 var is_valid_drop_site = true;
416 w, // will receive 'drag-data-received' signal
417 ctx, /* represents the current state of the DnD
418 this.get('/Window').atoms["STRING"], /* the target type we want
423 /* No target offered by source => error
426 return is_valid_drop_site;
431 // user defined functions
432 public void runRefresh ()
434 // this is run every 2 seconds from the init..
438 if (!this.refreshRequired) {
439 // print("no refresh required");
443 if (this.lastRedraw != null) {
444 // do not redraw if last redraw was less that 5 seconds ago.
445 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
450 if (_this.file == null) {
455 this.refreshRequired = false;
456 // print("HTML RENDERING");
459 //this.get('/BottomPane').el.show();
460 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
461 _this.file.webkit_page_id = this.el.get_page_id();
463 var js = _this.file.toSourcePreview();
472 var project = _this.file.project;
474 //print (project.fn);
475 // set it to non-empty.
477 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
480 // this.runhtml = this.runhtml || '';
483 // then we need to reload the browser using
484 // load_html_string..
486 // then trigger a redraw once it's loaded..
487 this.pendingRedraw = true;
489 var runhtml = "<script type=\"text/javascript\">\n" ;
493 GLib.FileUtils.get_contents(Builder4.Application.configDirectory() + "/resources/roo.builder.js", out builderhtml);
495 runhtml += builderhtml + "\n";
496 runhtml += "</script>\n" ;
498 // fix to make sure they are the same..
499 this.runhtml = project.runhtml;
500 // need to modify paths
503 var base_template = _this.file.project.base_template;
505 if (base_template.length > 0 && !FileUtils.test(
506 Builder4.Application.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
508 print("invalid base_template name - using default: %s\n", base_template);
513 GLib.FileUtils.get_contents(
514 Builder4.Application.configDirectory() + "/resources/" +
515 (base_template.length > 0 ? base_template : "roo.builder.html")
519 this.renderedData = js;
522 string js_src = js + "\n" +
523 "Roo.onReady(function() {\n" +
524 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
525 "Roo.XComponent.build();\n" +
528 // print("render js: " + js);
530 // console.log('not loaded yet');
532 this.lastRedraw = new DateTime.now_local();
534 var html = inhtml.replace("</head>", runhtml + this.runhtml +
536 "<script type=\"text/javascript\">\n" +
541 //print("LOAD HTML " + html);
543 var rootURL = _this.file.project.rootURL;
547 this.el.load_html( html ,
548 //fixme - should be a config option!
549 (rootURL.length > 0 ? rootURL : "http://localhost/app.Builder/")
552 // force the inspector...
553 this.initInspector();
555 // - no need for this, the builder javascript will call it when build is complete
556 //GLib.Timeout.add_seconds(1, () => {
557 // this.el.run_javascript("Builder.saveHTML()",null);
560 // print( "before render" + this.lastRedraw);
561 // print( "after render" + (new Date()));
564 public void initInspector () {
566 if (this.inspector == this.el.get_inspector()) {
567 this.inspector.show();
568 this.inspector.open_window();
569 print("init inspecter called, and inspector is the same as existing\n");
572 print("new inspector?\n");
574 this.inspector = this.el.get_inspector();
575 this.inspector.ref();
577 // got a new inspector...
579 this.inspector.open_window.connect(() => {
580 this.inspector = this.el.get_inspector();
581 print("inspector attach\n");
582 var wv = this.inspector.get_web_view();
584 print("got inspector web view\n");
585 _this.inspectorcontainer.el.add(wv);
588 //this.inspector.close();
590 //this.inspector = null;
597 this.inspector.closed.connect(() => {
598 print("inspector closed?!?");
599 // if this happens destroy the webkit..
601 this.el.stop_loading();
603 if (_this.viewbox.el.get_parent() == null) {
608 _this.viewbox.el.remove(_this.viewcontainer.el);
609 _this.el.remove(_this.inspectorcontainer.el);
611 // destory seems to cause problems.
613 //_this.viewcontainer.el.destroy();
614 //_this.inspectorcontainer.el.destroy();
617 var nv =new Xcls_viewcontainer(_this);
619 _this.viewbox.el.pack_end(nv.el,true,true,0);
621 var inv =new Xcls_inspectorcontainer(_this);
623 _this.el.pack2(inv.el,true,true);
627 //while(Gtk.events_pending ()) Gtk.main_iteration ();
628 //_this.view.renderJS(true);
629 _this.view.refreshRequired = true;
633 this.inspector.show();
635 public void renderJS (bool force) {
637 // this is the public redraw call..
638 // we refresh in a loop privately..
639 var autodraw = _this.AutoRedraw.el.active;
640 if (!autodraw && !force) {
641 print("Skipping redraw - no force, and autodraw off");
644 this.refreshRequired = true;
647 public class Xcls_inspectorcontainer : Object
649 public Gtk.ScrolledWindow el;
650 private Xcls_WindowRooView _this;
656 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
659 _this.inspectorcontainer = this;
660 this.el = new Gtk.ScrolledWindow( null, null );
664 // set gobject values
665 this.el.shadow_type = Gtk.ShadowType.IN;
669 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); }
671 // user defined functions