X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Sample%2FWindow.js;h=022dd008787b3386c1e514d0dc8b8b2aa241075a;hb=53e66abba6c3ed7d74cb57e92aeb15120801b7a5;hp=ab4d498e4e80b261a0c2b85cc47b8b4925475e79;hpb=fde22158fff3ba900c5b1650bcb4dd60e6c6035c;p=app.Builder.js diff --git a/Sample/Window.js b/Sample/Window.js index ab4d498e4..022dd0087 100644 --- a/Sample/Window.js +++ b/Sample/Window.js @@ -247,14 +247,15 @@ Window=new XObject({ var model = this.get('model'); if (render) { render.renderJS(model.toJS(false,true)[0]); + } else { + print("NO RENDER JS METHOD?"); } }, getRenderer : function() { - var model = this.get('model'); - // print("RENDER VIEW?" + model.file.getType()); - switch( model.file.getType()) { + + switch( this.getActiveFile().getType()) { case 'Roo': - this.get('/RightBrowser.view'); + return this.get('/RightBrowser.view'); case 'Gtk': return this.get('/RightGtkView'); } @@ -271,6 +272,23 @@ Window=new XObject({ view.selection.get_selected(model.el, iter); return model.el.get_path(iter).to_string(); }, + getActiveFile : function() { + return this.get('model').file; + }, + getActiveElement : function() { + + var path = this.getActivePath(); + if (!path) { + return false; + } + var iter = new Gtk.TreeIter(); + this.get('model').el.get_iter_from_string(iter, path); + + var value = new GObject.Value(''); + this.get('model').el.get_value(iter, 2, value); + + return JSON.parse(value.value); + }, items : [ { xtype: Gtk.TreeView, @@ -566,7 +584,7 @@ Window=new XObject({ // var val = ""; - value = new GObject.Value(''); + var value = new GObject.Value(''); this.get('/LeftTree.model').el.get_value(iter, 2, value); this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string(); @@ -1371,16 +1389,18 @@ Window=new XObject({ }, loadProject : function(pr) { + print("LOAD PROJECT"); this.el.clear(); if (!pr) { return; } + this.get('/LeftProjectTree').project = pr; this.load(pr.toTree()); this.get('/LeftProjectTree.view').el.expand_all(); }, load : function(tr,iter) { - console.dump(tr); + // console.dump(tr); console.log('Project tree load: ' + tr.length); var citer = new Gtk.TreeIter(); //this.insert(citer,iter,0); @@ -2036,6 +2056,8 @@ Window=new XObject({ case 'number': case 'uint': case 'int': + case 'float': + case 'gfloat': return parseFloat(val); // Nan ?? invalid!!? case 'boolean': return val == 'true' ? true : false; @@ -2469,6 +2491,9 @@ Window=new XObject({ xtype: Gtk.VBox, pack : "add", id : "RightBrowser", + listeners : { + + }, items : [ { xtype: Gtk.HBox, @@ -2477,13 +2502,83 @@ Window=new XObject({ { xtype: Gtk.Button, pack : "pack_start,false,false,0", - label : "Dump HTML to console", + label : "Redraw", + listeners : { + "button_press_event":function (self, event) { + var js = this.get('/LeftTree.model').toJS(); + if (js && js[0]) { + this.get('/RightBrowser.view').renderJS(js[0]); + } + return false; + } + } + }, + { + xtype: Gtk.Button, + pack : "pack_start,false,false,0", + label : "Set extra HTML in render", + listeners : { + "button_press_event":function (self, event) { + this.get('/RooProjectProperties').show(); + return false; + } + } + }, + { + xtype: Gtk.Button, + pack : "pack_start,false,false,0", + label : "test in Firefox", listeners : { - "activate":function (self) { - this.get('/RightBrowser.view').el.execute_script( - "console.log(document.body.innerHTML);"); - this.get('/RightBrowser.view').el.execute_script( - "console.log(Builder.dump(Builder));"); + "button_press_event":function (self, event) + { + /* Firefox testing for debugging.. + - we can create a /tmp directory, and put. + builder.html, builder.html.js, link roojs1 + add at the end of builder.html Roo.onload(function() { + */ + if (!this.get('/Window.LeftTree').getActiveFile()) { + return; + } + + var js = this.get('/LeftTree.model').toJS(); + if (!js || !js[0]) { + return; + } + var project = this.get('/Window.LeftTree').getActiveFile().project; + //print (project.fn); + + project.runhtml = project.runhtml || ''; + + + var File = imports.File.File; + + var target = "/tmp/firetest"; // fixme.. + if (!File.isDirectory(target)) { + File.mkdir(target); + } + File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE); + if (!File.exists( target+ '/roojs1')) { + File.link( target+ '/roojs1', __script_path__ + '/../roojs1'); + } + + + + var html = imports.File.File.read(__script_path__ + '/../builder.html'); + html = html.replace('', project.runhtml + ''); + + + var jsstr = JSON.stringify(js[0]); + + var runbuilder = ''; + + html = html.replace('', runbuilder + ''); + + File.write( target+ '/builder.html', html); + + + return false; } } } @@ -2506,7 +2601,7 @@ Window=new XObject({ XObject.prototype.init.call(this); // this may not work!? this.el.open('file:///' + __script_path__ + '/../builder.html'); - + Gtk.drag_dest_set ( this.el, /* widget that will accept a drop */ @@ -2520,24 +2615,70 @@ Window=new XObject({ Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList); }, renderJS : function(data) { + print("HTML RENDERING"); + /// prevent looping.. + //if (this.pendingRedraw) { + // print("pending redraw active?!"); + // return; + //} + + + if (!this.get('/Window.LeftTree').getActiveFile()) { + return; + } + + var project = this.get('/Window.LeftTree').getActiveFile().project; + //print (project.fn); + + project.runhtml = project.runhtml || ''; + + + this.runhtml = this.runhtml || ''; + + if (project.runhtml != this.runhtml) { + // then we need to reload the browser using + // load_html_string.. + + // then trigger a redraw once it's loaded.. + this.pendingRedraw = true; + + this.runhtml = project.runhtml; + + var html = imports.File.File.read(__script_path__ + '/../builder.html'); + html = html.replace('', this.runhtml + ''); + print("LOAD HTML " + html); + this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html'); + // should trigger load_finished! + return; + + } + + this.pendingRedraw = false; + + this.renderedData = data; var str = JSON.stringify(data) ; if (!this.ready) { console.log('not loaded yet'); } - Seed.print("RENDER:" + str); - imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");"); + //Seed.print("RENDER:" + str); + //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");"); + this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");"); }, listeners : { "load_finished":function (self, object) { - if (this.ready) { // dont do it twice! - return; - } + // if (this.ready) { // dont do it twice! + // return; + //} this.ready = true; + this.pendingRedraw = false; + var js = this.get('/LeftTree.model').toJS(); + if (js && js[0]) { + this.renderJS(js[0]); + } - this.renderJS(this.get('/LeftTree.model').toJS()[0]); }, "script_alert":function (self, object, p0) { print(p0); @@ -2545,11 +2686,13 @@ Window=new XObject({ return true; // do not display anything... }, "console_message":function (self, object, p0, p1) { - console.log(object); + // console.log(object); if (!object.match(/^\{/)) { - return false; // do not handle!!! -> later maybe in console.. + + this.get('/Terminal').feed(object); + return true; // do not handle!!! -> later maybe in console.. } - console.log(object); + // console.log(object); var val = JSON.parse(object); if (typeof(val['hover-node']) != 'undefined') { @@ -2690,6 +2833,7 @@ Window=new XObject({ id : "RightGtkView", renderJS : function(data, withDebug) { + this.highlightWidget = false; if (!data) { return; } @@ -2814,16 +2958,17 @@ Window=new XObject({ } catch(e) { continue; } k = k.substring(1); - print(k + '=' + kv); + // print(k + '=' + kv); } if (k[0] == '|') { // should be boolean or number.. k = k.substring(1); - print(k + '=' + kv); + //print(k + '=' + kv); } if (k == 'show_tabs') { // force tab showing for notebooks. kv = true; } + print(k + '=' + typeof(kv) + " : " + kv); ctr_args[k] = kv; } @@ -2905,18 +3050,55 @@ Window=new XObject({ return el; }, - widgetExposeEvent : function(widget, evt, ud, item) { + widgetExposeEvent : function(w, evt, ud, item) { + var widget = w; if (this.inRender) { return false; } + + if ( this.highlightWidget) { + this.inRender = true; + if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) { + Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h); + } + this.inRender = false; + return false; + } + + if (this.activePath != item.xtreepath) { return false; } - print("HIGHLIGHT: " + item.xtreepath ); // draw highlight?? + + // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight?? // work out the coords of the window.. - var r = widget.get_allocation(); + if (!this.gc) { + var dr = widget.window; + this.gc = (new Gdk.GC.c_new(dr)); + this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 })); + this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND); + } + + + var r = evt.expose.area; + // console.dump([r.x, r.y, r.width, r.height ] ); + //return false; + // print(widget.get_parent().toString().match(/GtkScrolledWindow/); + if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak + // happens with gtkscrollview embedded stuff.. + var np =this.activePath.split(':'); + np.pop(); + this.activePath = np.join(':'); + this.renderedEl.queue_draw(); + return true; + + + } + + - var box = { + + this.box = { x : r.x - 2, y : r.y - 2, w: r.width + 4, @@ -2924,13 +3106,16 @@ Window=new XObject({ }; // let's draw it.. this.inRender = true; - var dr = this.get('/Window').el.window; - var gc = (new Gdk.GC.c_new(dr)).copy(); - var dr = widget.get_window(); - gc.set_line_attributes(2, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND); - gc.set_foreground(new Gdk.Color({ red: 0xFFFF, green: 0, blue: 0})); - Gdk.draw_rectangle(dr, gc, false, box.x , box.y, box.w, box.h); + + this.highlightWidget = widget; + + + + + // print("DRAW BOX"); + //console.dump(this.box); + Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h); this.inRender = false; return false; }, @@ -2956,6 +3141,7 @@ Window=new XObject({ return false; }, redraw : function() { + this.highlightWidget = false; print("REDRAW CALLED"); this.activePath = this.get('/LeftTree').getActivePath(); if (this.renderedEl) { @@ -2974,22 +3160,19 @@ Window=new XObject({ label : "Run The Application", listeners : { "button_press_event":function (self, event) { - // call render on left tree - with special option!?! + // call render on left tree - with special option!?! - - - print("GET PROEJCT"); - var pr = this.get('/LeftProjectTree').getActiveProject(); + //print("GET PROEJCT"); + var pr = this.get('/LeftProjectTree').getActiveProject(); - var dir = ''; - for (var i in pr.paths) { - dir = i; - break; - } - var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js'; - print ("RUN DIR:" + dir); - this.get('/BottomPane').el.show(); - this.get('/BottomPane').el.set_current_page(1); + var dir = ''; + for (var i in pr.paths) { + dir = i; + break; + } + var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js'; + this.get('/Terminal').feed("RUN DIR:" + dir); + this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__) , false,false,false); var cmd = "/usr/bin/seed " + runner + " " + dir + "\n"; @@ -3173,6 +3356,25 @@ Window=new XObject({ xtype: Gtk.ScrolledWindow, pack : "add", id : "Help", + show : function() { + + var file = this.get('/LeftTree').getActiveFile(); + if (!file) { + return; + } + var activeEl = this.get('/LeftTree').getActiveElement(); + var xtype = file.guessName( activeEl ) + if (!xtype || !xtype.length) { + return; + } + this.get('/Window.view-help-nb').el.set_current_page(1); + + // get the active element being edited. + var helpurl = file.getHelpUrl(xtype); + + // now load the help info in the page.. + this.get('help-view').el.open(helpurl); + }, items : [ { xtype: WebKit.WebView, @@ -3183,7 +3385,8 @@ Window=new XObject({ this.get('/Window.help-view').el.open( "http://devel.akbkhome.com/seed/"); - } + }, + zoom_level : 0.8 } ] } @@ -3220,14 +3423,7 @@ Window=new XObject({ load : function(str) { // show the help page for the active node.. - this.get('/Window.view-help-nb').el.set_current_page(1); - - // get the active element being edited. - var xtype = this.get('/LeftTree.model').file.guessName( - this.get('/MidPropTree').activeElement); - // now load the help info in the page.. - this.get('/Window.help-view').el.open( - "http://devel.akbkhome.com/seed/" + xtype + ".html"); + this.get('/Help').show(); this.get('/BottomPane').el.set_current_page(0); @@ -3299,9 +3495,20 @@ Window=new XObject({ xtype: Vte.Terminal, pack : "add", id : "Terminal", - feed : function(str) { - this.el.feed(str,str.length); - } + feed : function(istr) { + var str = istr.replace(/\n/g, "\r\n") + "\r\n"; + // we should make ourselves visable!!! + this.get('/BottomPane').el.show(); + this.get('/BottomPane').el.set_current_page(1); + + this.el.feed(str ,str.length); + }, + scroll_on_output : true, + init : function() { + XObject.prototype.init.call(this); + this.el.set_size (80, 1000); + }, + scrollback_lines : 1000 } ] }