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);
60 screenshot.save(filename,"png");
73 public void requestRedraw () {
74 this.view.renderJS(false);
76 public class Xcls_viewbox : Object
79 private Xcls_WindowRooView _this;
85 public Xcls_viewbox(Xcls_WindowRooView _owner )
89 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
94 this.el.homogeneous = false;
95 var child_0 = new Xcls_Box3( _this );
97 this.el.pack_start ( child_0.el , false,true,0 );
98 var child_1 = new Xcls_viewcontainer( _this );
100 this.el.pack_end ( child_1.el , true,true,0 );
103 // user defined functions
105 public class Xcls_Box3 : Object
108 private Xcls_WindowRooView _this;
114 public Xcls_Box3(Xcls_WindowRooView _owner )
117 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
121 // set gobject values
122 this.el.homogeneous = true;
123 this.el.height_request = 20;
124 this.el.vexpand = false;
125 var child_0 = new Xcls_Button4( _this );
127 this.el.pack_start ( child_0.el , false,false,0 );
128 var child_1 = new Xcls_AutoRedraw( _this );
130 this.el.pack_start ( child_1.el , false,false,0 );
131 var child_2 = new Xcls_Button6( _this );
133 this.el.pack_start ( child_2.el , false,false,0 );
136 // user defined functions
138 public class Xcls_Button4 : Object
140 public Gtk.Button el;
141 private Xcls_WindowRooView _this;
147 public Xcls_Button4(Xcls_WindowRooView _owner )
150 this.el = new Gtk.Button();
154 // set gobject values
155 this.el.label = "Redraw";
158 this.el.clicked.connect( ( ) => {
159 _this.view.renderJS( true);
163 // user defined functions
166 public class Xcls_AutoRedraw : Object
168 public Gtk.CheckButton el;
169 private Xcls_WindowRooView _this;
175 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
178 _this.AutoRedraw = this;
179 this.el = new Gtk.CheckButton();
183 // set gobject values
184 this.el.active = true;
185 this.el.label = "Auto Redraw On";
188 this.el.toggled.connect( (state) => {
189 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
193 // user defined functions
196 public class Xcls_Button6 : Object
198 public Gtk.Button el;
199 private Xcls_WindowRooView _this;
205 public Xcls_Button6(Xcls_WindowRooView _owner )
208 this.el = new Gtk.Button();
212 // set gobject values
213 this.el.label = "Full Redraw";
216 this.el.clicked.connect( () => {
217 _this.view.redraws = 99;
218 _this.view.el.web_context.clear_cache();
219 //_this.view.renderJS(true);
220 FakeServerCache.clear();
226 // user defined functions
230 public class Xcls_viewcontainer : Object
232 public Gtk.ScrolledWindow el;
233 private Xcls_WindowRooView _this;
239 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
242 _this.viewcontainer = this;
243 this.el = new Gtk.ScrolledWindow( null, null );
247 // set gobject values
248 this.el.shadow_type = Gtk.ShadowType.IN;
249 var child_0 = new Xcls_view( _this );
251 this.el.add ( child_0.el );
255 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
258 // user defined functions
260 public class Xcls_view : Object
262 public WebKit.WebView el;
263 private Xcls_WindowRooView _this;
267 public string renderedData;
268 public bool refreshRequired;
269 public WebKit.WebInspector inspector;
272 public GLib.DateTime lastRedraw;
273 public string runhtml;
274 public bool pendingRedraw;
277 public Xcls_view(Xcls_WindowRooView _owner )
281 this.el = new WebKit.WebView();
284 this.renderedData = "";
285 this.refreshRequired = false;
288 this.lastRedraw = null;
290 this.pendingRedraw = false;
292 // set gobject values
297 // this may not work!?
298 var settings = this.el.get_settings();
299 settings.enable_developer_extras = true;
302 var fs= new FakeServer(this.el);
304 // this was an attempt to change the url perms.. did not work..
305 // settings.enable_file_access_from_file_uris = true;
306 // settings.enable_offline_web_application_cache - true;
307 // settings.enable_universal_access_from_file_uris = true;
314 // FIXME - base url of script..
315 // we need it so some of the database features work.
316 this.el.load_html( "Render not ready" ,
317 //fixme - should be a config option!
318 // or should we catch stuff and fix it up..
319 "http://localhost/app.Builder/"
323 //this.el.open('file:///' + __script_path__ + '/../builder.html');
328 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
329 null, // list of targets
330 Gdk.DragAction.COPY // what to do with data after dropped
333 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
334 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
336 GLib.Timeout.add_seconds(1, () =>{
337 //print("run refresh?");
338 if (this.el == null) {
349 this.el.script_dialog.connect( (dialog) => {
350 if (this.el == null) {
354 var msg = dialog.get_message();
355 if (msg.length < 4) {
358 if (msg.substring(0,4) != "IPC:") {
361 var ar = msg.split(":", 3);
367 _this.file.saveHTML(ar[2]);
374 this.el.show.connect( ( ) => {
375 this.initInspector();;
377 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
380 print("TARGET: drag-drop");
381 var is_valid_drop_site = true;
386 w, // will receive 'drag-data-received' signal
387 ctx, /* represents the current state of the DnD
388 this.get('/Window').atoms["STRING"], /* the target type we want
393 /* No target offered by source => error
396 return is_valid_drop_site;
399 this.el.load_changed.connect( (le) => {
400 if (le != WebKit.LoadEvent.FINISHED) {
403 if (this.runjs.length < 1) {
406 // this.el.run_javascript(this.runjs, null);
407 FakeServerCache.remove( this.runjs);
412 // user defined functions
413 public void reInit () {
415 // if this happens destroy the webkit..
417 this.el.stop_loading();
419 if (_this.viewbox.el.get_parent() == null) {
424 _this.viewbox.el.remove(_this.viewcontainer.el);
425 _this.el.remove(_this.inspectorcontainer.el);
427 // destory seems to cause problems.
429 //_this.viewcontainer.el.destroy();
430 //_this.inspectorcontainer.el.destroy();
431 var inv =new Xcls_inspectorcontainer(_this);
433 _this.el.pack2(inv.el,true,true);
437 var nv =new Xcls_viewcontainer(_this);
439 _this.viewbox.el.pack_end(nv.el,true,true,0);
444 //while(Gtk.events_pending ()) Gtk.main_iteration ();
445 //_this.view.renderJS(true);
446 _this.view.refreshRequired = true;
448 public void runRefresh ()
450 // this is run every 2 seconds from the init..
454 if (!this.refreshRequired) {
455 // print("no refresh required");
459 if (this.lastRedraw != null) {
460 // do not redraw if last redraw was less that 5 seconds ago.
461 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
466 if (_this.file == null) {
471 this.refreshRequired = false;
472 // print("HTML RENDERING");
475 //this.get('/BottomPane').el.show();
476 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
477 _this.file.webkit_page_id = this.el.get_page_id();
479 var js = _this.file.toSourcePreview();
488 var project = _this.file.project;
490 //print (project.fn);
491 // set it to non-empty.
493 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
496 // this.runhtml = this.runhtml || '';
499 // then we need to reload the browser using
500 // load_html_string..
502 // then trigger a redraw once it's loaded..
503 this.pendingRedraw = true;
505 var runhtml = "<script type=\"text/javascript\">\n" ;
509 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
514 runhtml += builderhtml + "\n";
515 runhtml += "</script>\n" ;
517 // fix to make sure they are the same..
518 this.runhtml = project.runhtml;
519 // need to modify paths
522 var base_template = _this.file.project.base_template;
524 if (base_template.length > 0 && !FileUtils.test(
525 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
527 print("invalid base_template name - using default: %s\n", base_template);
532 GLib.FileUtils.get_contents(
533 BuilderApplication.configDirectory() + "/resources/" +
534 (base_template.length > 0 ? base_template : "roo.builder.html")
540 this.renderedData = js;
543 string js_src = js + "\n" +
544 "Roo.onReady(function() {\n" +
545 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
546 "Roo.XComponent.build();\n" +
549 // print("render js: " + js);
551 // console.log('not loaded yet');
553 this.lastRedraw = new DateTime.now_local();
556 //this.runjs = js_src;
557 var fc = FakeServerCache.factory_with_data(js_src);
558 this.runjs = fc.fname;
560 var html = inhtml.replace("</head>", runhtml + this.runhtml +
561 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
562 // "<script type=\"text/javascript\">\n" +
567 //print("LOAD HTML " + html);
569 var rootURL = _this.file.project.rootURL;
573 this.el.load_html( html ,
574 //fixme - should be a config option!
575 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
578 // force the inspector...
579 // this.initInspector();
581 // - no need for this, the builder javascript will call it when build is complete
582 //GLib.Timeout.add_seconds(1, () => {
583 // this.el.run_javascript("Builder.saveHTML()",null);
586 // print( "before render" + this.lastRedraw);
587 // print( "after render" + (new Date()));
590 public void initInspector () {
592 /* if (this.inspector == this.el.get_inspector()) {
593 this.inspector.show();
594 this.inspector.open_window();
595 print("init inspecter called, and inspector is the same as existing\n");
598 print("new inspector?\n");
600 this.inspector = this.el.get_inspector();
601 this.inspector.ref();
603 // got a new inspector...
605 this.inspector.open_window.connect(() => {
606 this.inspector = this.el.get_inspector();
607 print("inspector attach\n");
608 var wv = this.inspector.get_web_view();
610 print("got inspector web view\n");
612 var cn = _this.inspectorcontainer.el.get_child();
614 _this.inspectorcontainer.el.remove(cn);
617 _this.inspectorcontainer.el.add(wv);
620 //this.inspector.close();
622 //this.inspector = null;
630 this.inspector.closed.connect(() => {
631 print("inspector closed?!?");
632 // if this happens destroy the webkit..
634 this.el.stop_loading();
636 if (_this.viewbox.el.get_parent() == null) {
641 _this.viewbox.el.remove(_this.viewcontainer.el);
642 _this.el.remove(_this.inspectorcontainer.el);
644 // destory seems to cause problems.
646 //_this.viewcontainer.el.destroy();
647 //_this.inspectorcontainer.el.destroy();
650 var nv =new Xcls_viewcontainer(_this);
652 _this.viewbox.el.pack_end(nv.el,true,true,0);
654 var inv =new Xcls_inspectorcontainer(_this);
656 _this.el.pack2(inv.el,true,true);
660 //while(Gtk.events_pending ()) Gtk.main_iteration ();
661 //_this.view.renderJS(true);
662 _this.view.refreshRequired = true;
667 this.inspector.show();
669 public void renderJS (bool force) {
671 // this is the public redraw call..
672 // we refresh in a loop privately..
673 var autodraw = _this.AutoRedraw.el.active;
674 if (!autodraw && !force) {
675 print("Skipping redraw - no force, and autodraw off");
679 this.refreshRequired = true;
685 public class Xcls_inspectorcontainer : Object
687 public Gtk.ScrolledWindow el;
688 private Xcls_WindowRooView _this;
694 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
697 _this.inspectorcontainer = this;
698 this.el = new Gtk.ScrolledWindow( null, null );
702 // set gobject values
703 this.el.shadow_type = Gtk.ShadowType.IN;
707 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
710 // user defined functions