X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Builder%2FWindow.js;h=ee270cf45c44df6e5cf736544169ed3682775593;hb=119290bc3234e9ece1c64dbd72ca486d9633b5b7;hp=7f91a896ac916f6cb03b4c8c716d907c6427dacd;hpb=db1ed5681c2ea9d50f14123db63e3a7e7a4d9b59;p=app.Builder.js diff --git a/Builder/Window.js b/Builder/Window.js index 7f91a896a..ee270cf45 100644 --- a/Builder/Window.js +++ b/Builder/Window.js @@ -7,13 +7,33 @@ GObject = imports.gi.GObject; GtkSource = imports.gi.GtkSource; WebKit = imports.gi.WebKit; Vte = imports.gi.Vte; +GtkClutter = imports.gi.GtkClutter; console = imports.console; XObject = imports.XObject.XObject; Window=new XObject({ xtype: Gtk.Window, - type : Gtk.WindowType.TOPLEVEL, - title : "Application Builder", + listeners : { + delete_event : function (self, event) { + return false; + }, + destroy : function (self) { + Gtk.main_quit(); + }, + show : function (self) { + print("WINDOW SHOWING - trying to hide"); + imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig(); + this.get('/MidPropTree').hideWin(); + this.get('/RightPalete').hide(); + this.get('/BottomPane').el.hide(); + //this.get('/Editor').el.show_all(); + + } + }, border_width : 0, + default_height : 500, + default_width : 800, + id : "Window", + title : "Application Builder", init : function() { this.atoms = { "STRING" : Gdk.atom_intern("STRING") @@ -32,28 +52,10 @@ Window=new XObject({ }, - default_width : 800, - default_height : 500, - id : "Window", setTitle : function(str) { this.el.set_title(this.title + ' - ' + str); }, - listeners : { - delete_event : function (self, event) { - return false; - }, - destroy : function (self) { - Gtk.main_quit(); - }, - show : function (self) { - print("WINDOW SHOWING - trying to hide"); - imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig(); - this.get('/MidPropTree').hideWin(); - this.get('/RightPalete').hide(); - this.get('/BottomPane').el.hide(); - - } - }, + type : Gtk.WindowType.TOPLEVEL, items : [ { xtype: Gtk.VBox, @@ -212,7 +214,7 @@ Window=new XObject({ activate : function (self, event) { var js = this.get('/LeftTree.model').toJS(); if (js && js[0]) { - this.get('/RightBrowser.view').renderJS(js[0]); + this.get('/RightBrowser.view').renderJS(js[0], true); } return false; } @@ -337,29 +339,20 @@ Window=new XObject({ xtype: Gtk.Expander, listeners : { activate : function (self) { - var nb = this.get('/LeftTopPanel.notebook'); - if (this.el.expanded) { - // now expanded.. - - var pm = imports.Builder.Provider.ProjectManager.ProjectManager; - - - var model = this.get('/LeftProjectTree.combomodel'); - // print ("loading Projects?") - //console.dump(pm.projects); - model.loadData(pm.projects); - - - nb.el.set_current_page(1); - //pm.on('changed', function() { - //console.log("CAUGHT project manager change"); - // _combo.model.loadData(pm.projects); - //} - return; - } - nb.el.set_current_page(0); + // this does not actually expand it.. + // that is done by GTK.. + + + + if (!this.el.expanded) { + this.onExpand(); + } else { + this.onCollapse(); + } + }, enter_notify_event : function (self, event) { + return; this.el.expanded = !this.el.expanded; //if (this.el.expanded ) { this.listeners.activate.call(this); @@ -371,22 +364,45 @@ Window=new XObject({ id : "expander", label : "Select Project or File", pack : "pack_start,false,true", + onCollapse : function() { + + var nb = this.get('/LeftTopPanel.notebook'); + nb.el.set_current_page(0); + }, init : function() { XObject.prototype.init.call(this); this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK ); + }, + onExpand : function() { + var nb = this.get('/LeftTopPanel.notebook'); + var pm = imports.Builder.Provider.ProjectManager.ProjectManager; + + + var model = this.get('/LeftProjectTree.combomodel'); + // print ("loading Projects?") + //console.dump(pm.projects); + model.loadData(pm.projects); + + + nb.el.set_current_page(1); + //pm.on('changed', function() { + //console.log("CAUGHT project manager change"); + // _combo.model.loadData(pm.projects); + //} + return; } }, { xtype: Gtk.Notebook, id : "notebook", - show_border : false, - show_tabs : false, pack : "pack_start,true,true", init : function() { XObject.prototype.init.call(this); this.el.set_current_page(0); }, + show_border : false, + show_tabs : false, items : [ { xtype: Gtk.ScrolledWindow, @@ -452,68 +468,6 @@ Window=new XObject({ items : [ { xtype: Gtk.TreeView, - pack : "add", - id : "view", - headers_visible : false, - enable_tree_lines : true, - tooltip_column : 1, - init : function() { - XObject.prototype.init.call(this); - var description = new Pango.FontDescription.c_new(); - description.set_size(8000); - this.el.modify_font(description); - - this.selection = this.el.get_selection(); - this.selection.set_mode( Gtk.SelectionMode.SINGLE); - var _this = this; - - // is this really needed?? - this.selection.signal['changed'].connect(function() { - _this.get('/LeftTree.view').listeners.cursor_changed.apply( - _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), ''] - ); - }); - - Gtk.drag_source_set ( - this.el, /* widget will be drag-able */ - Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */ - null, /* lists of target to support */ - 0, /* size of list */ - Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */ - ); - - Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList); - - Gtk.drag_source_add_text_targets(this.el); - Gtk.drag_dest_set - ( - this.el, /* widget that will accept a drop */ - Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, - null, /* lists of target to support */ - 0, /* size of list */ - Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */ - ); - - Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList); - Gtk.drag_dest_add_text_targets(this.el); - }, - highlight : function(treepath_ar) { - - // highlighting for drag/drop - if (treepath_ar.length && treepath_ar[0].length ) { - this.el.set_drag_dest_row( - new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]); - } else { - this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER); - } - - }, - selectNode : function(treepath_str) { - //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str)); - var tp = new Gtk.TreePath.from_string(treepath_str); - this.el.set_cursor(tp, null, false); - this.el.scroll_to_cell(tp, null, false, 0,0); - }, listeners : { button_press_event : function (self, ev) { console.log("button press?"); @@ -757,7 +711,7 @@ Window=new XObject({ // _g.button.set_label(''+value.get_string()); var pm =this.get('/RightPalete.model'); - pm.load( this.get('/RightPalete').provider.gatherList( + pm.load( this.get('/LeftTree').getPaleteProvider().gatherList( this.get('/LeftTree.model').listAllTypes())); @@ -770,6 +724,68 @@ Window=new XObject({ } }, + id : "view", + pack : "add", + tooltip_column : 1, + enable_tree_lines : true, + headers_visible : false, + highlight : function(treepath_ar) { + + // highlighting for drag/drop + if (treepath_ar.length && treepath_ar[0].length ) { + this.el.set_drag_dest_row( + new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]); + } else { + this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER); + } + + }, + init : function() { + XObject.prototype.init.call(this); + var description = new Pango.FontDescription.c_new(); + description.set_size(8000); + this.el.modify_font(description); + + this.selection = this.el.get_selection(); + this.selection.set_mode( Gtk.SelectionMode.SINGLE); + var _this = this; + + // is this really needed?? + this.selection.signal['changed'].connect(function() { + _this.get('/LeftTree.view').listeners.cursor_changed.apply( + _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), ''] + ); + }); + + Gtk.drag_source_set ( + this.el, /* widget will be drag-able */ + Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */ + null, /* lists of target to support */ + 0, /* size of list */ + Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */ + ); + + Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList); + + Gtk.drag_source_add_text_targets(this.el); + Gtk.drag_dest_set + ( + this.el, /* widget that will accept a drop */ + Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, + null, /* lists of target to support */ + 0, /* size of list */ + Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */ + ); + + Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList); + Gtk.drag_dest_add_text_targets(this.el); + }, + selectNode : function(treepath_str) { + //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str)); + var tp = new Gtk.TreePath.from_string(treepath_str); + this.el.set_cursor(tp, null, false); + this.el.scroll_to_cell(tp, null, false, 0,0); + }, items : [ { xtype: Gtk.TreeStore, @@ -778,7 +794,7 @@ Window=new XObject({ id : "model", pack : "set_model", changed : function(n, refresh) { - print("MODEL CHANGED CALLED" + this.activePath); + // print("MODEL CHANGED CALLED" + this.activePath); if (this.activePath) { var iter = new Gtk.TreeIter(); this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath)) @@ -788,8 +804,10 @@ Window=new XObject({ this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]); } //this.currentTree = this.toJS(false, true)[0]; + var d = new Date(); this.file.items = this.toJS(false, false); - print("AFTER CHANGED"); + print ("TO JS in " + ((new Date()) - d) + "ms"); + // print("AFTER CHANGED"); //console.dump(this.file.items); this.file.save(); this.currentTree = this.file.items[0]; @@ -1118,8 +1136,8 @@ Window=new XObject({ if (f.items.length && typeof(f.items[0]) == 'string') { - this.get('/RightEditor').el.show(); - this.get('/RightEditor.view').load( f.items[0]); + //this.get('/RightEditor').el.show(); + //this.get('/RightEditor.view').load( f.items[0]); return; } print("LOAD"); @@ -1143,7 +1161,8 @@ Window=new XObject({ //print("hide right editior"); - this.get('/RightEditor').el.hide(); + //this.get('/RightEditor').el.hide(); + this.get('/Editor').el.hide(); //print("set current tree"); this.currentTree = this.toJS(false, false)[0]; //console.dump(this.currentTree); @@ -1560,7 +1579,8 @@ Window=new XObject({ var nb = this.get('/LeftTopPanel.expander'); nb.el.expanded = false; - nb.listeners.activate.call(nb); + nb.onCollapse(); + //nb.listeners.activate.call(nb); //_expander.el.set_expanded(false); var ltm = this.get('/LeftTree.model'); @@ -1899,21 +1919,106 @@ Window=new XObject({ }, { xtype: Gtk.ScrolledWindow, + editing : false, id : "LeftPanel", pack : "add", - shadow_type : Gtk.ShadowType.IN, - editing : false, init : function() { XObject.prototype.init.call(this); this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); }, + shadow_type : Gtk.ShadowType.IN, items : [ { xtype: Gtk.TreeView, + listeners : { + button_press_event : function (self, ev) { + + + var res = { }; + + if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) { + return false; //not on a element. + } + + // right click. + if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) { + // show popup!. + if (res.column.title == 'value' && this.get('/LeftPanel').editing) { + return false; + } + //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init(); + var p = this.get('/LeftPanelPopup'); + if (!p.el) { + p.init(); + } + + p.el.set_screen(Gdk.Screen.get_default()); + p.el.show_all(); + p.el.popup(null, null, null, null, 3, ev.button.time); + //Seed.print("click:" + res.column.title); + + + return false; + } + + + if (res.column.title != 'value') { + // XObject.error("column is not value?"); + return false; // ignore.. - key click.. ??? should we do this?? + } + + // currently editing??? + // if ( this.activePath) { + + // this.activePath = false; + // stop editing!!!! + if (this.get('/Editor').dirty) { + //if (!this.get('/Editor.buffer').checkSyntax()) { + // this.get('/StandardErrorDialog').show("Fix errors in code and save.."); + // return true; + // // error Dialog + //} + if (!this.get('/Editor.view').save()) { + return true; + } + } + this.get('/LeftPanel').editableColumn.items[0].el.stop_editing(); + this.get('/LeftPanel').editing = false; + + // XObject.error("Currently editing?"); + // return false; + // } + + var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry.. + + var type = this.get('/LeftPanel.model').getType(res.path.to_string()); + + // get options for this type -- this is to support option lists etc.. + var provider = this.get('/LeftTree').getPaleteProvider(); + var opts = provider.findOptions(type); + + if (opts === false) { + // it's text etnry + this.get('/LeftPanel').editableColumn.setOptions([]); + renderer.has_entry = true; + } else { + this.get('/LeftPanel').editableColumn.setOptions(opts); + renderer.has_entry = false; + } + this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1); + + //Seed.print("click" + ev.type); + //console.dump(res); + return false; + + + + } + }, id : "view", tooltip_column : 5, - headers_visible : false, enable_tree_lines : true, + headers_visible : false, init : function() { XObject.prototype.init.call(this); @@ -1925,68 +2030,6 @@ Window=new XObject({ description.set_size(8000); this.el.modify_font(description); }, - listeners : { - button_press_event : function (self, ev) { - - - var res = { }; - if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) { - return false; //not on a element. - } - - - if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) { - - if (res.column.title != 'value') { - return false; // ignore.. - } - if ( this.get('/LeftPanel').editing) { - return false; - } - var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry.. - this.get('/LeftPanel').editableColumn.items[0].el.stop_editing(); - var type = this.get('/LeftPanel.model').getType(res.path.to_string()); - - - - var provider = this.get('/LeftTree').getPaleteProvider(); - - var opts = provider.findOptions(type); - - if (opts === false) { - this.get('/LeftPanel').editableColumn.setOptions([]); - renderer.has_entry = true; - } else { - LeftPanel.editableColumn.setOptions(opts); - renderer.has_entry = false; - } - - - //Seed.print("click" + ev.type); - //console.dump(res); - return false; - } - - - - if (res.column.title == 'value') { - return false; - } - //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init(); - var p = this.get('/LeftPanelPopup'); - if (!p.el) { - p.init(); - } - - p.el.set_screen(Gdk.Screen.get_default()); - p.el.show_all(); - p.el.popup(null, null, null, null, 3, ev.button.time); - //Seed.print("click:" + res.column.title); - - - return false; - } - }, items : [ { xtype: Gtk.TreeStore, @@ -2097,61 +2140,6 @@ Window=new XObject({ this.load(data); this.get('/LeftTree.model').changed(data, true); - }, - editSelected : function(e) { - print("EDIT SELECTED?"); - var iter = new Gtk.TreeIter(); - var s = this.get('/LeftPanel.view').selection; - s.get_selected(this.get('/LeftPanel.model').el, iter); - var m = this.get('/LeftPanel.model') - - var gval = new GObject.Value(''); - this.el.get_value(iter, 0 ,gval); - var val = '' + gval.value; - - gval = new GObject.Value(''); - this.el.get_value(iter, 1 ,gval); - var rval = gval.value; - var activePath = this.el.get_path(iter).to_string(); - this.activePath = activePath ; - // was activeIter... - // not listener... - - var showEditor = false; - - if (val[0] == '!') { - showEditor = true; - } - if (val[0] == '|') { - if (rval.match(/function/g) || rval.match(/\n/g)) { - showEditor = true; - } - } - - if (showEditor) { - var _this = this; - this.activePath = false; - GLib.timeout_add(0, 1, function() { - // Gdk.threads_enter(); - _this.get('/BottomPane').el.show(); - _this.get('/RightEditor').el.show(); - _this.get('/RightEditor.view').load( rval ); - - e.editing_done(); - e.remove_widget(); - _this.activePath = activePath ; - - // Gdk.threads_leave(); - return false; - }); - return; - } - this.get('/BottomPane').el.hide(); - this.get('/RightEditor').el.hide(); - - //var type = this.getValue(this.el.get_path(iter).to_string(),4); - - }, getIterValue : function(iter, col) { var gval = new GObject.Value(''); @@ -2161,18 +2149,22 @@ Window=new XObject({ getType : function(treepath) { return this.getValue(treepath, 4); }, - getValue : function(treepath_str, col) { - var iter = new Gtk.TreeIter(); + getValue : function(treepath_str, col) + { + // get's the value in a row.. - keys - returns string, values - formats it.. + + var iter = new Gtk.TreeIter(); this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str)); var gval = new GObject.Value(''); this.get('/LeftPanel.model').el.get_value(iter, col ,gval); var val = '' + gval.value; + if (col != 1) { return val; } var type = this.getType(this.el.get_path(iter).to_string()); - print("TYPE: " +type + " - val:" + val); + //print("TYPE: " +type + " - val:" + val); switch(type.toLowerCase()) { case 'number': case 'uint': @@ -2207,7 +2199,7 @@ Window=new XObject({ load : function(ar) { this.el.clear(); - this.get('/RightEditor').el.hide(); + //this.get('/RightEditor').el.hide(); if (ar === false) { return ; } @@ -2259,13 +2251,16 @@ Window=new XObject({ return ret; }, startEditing : function(path,col) { + + // alled by menu 'edit' currently.. /** * start editing path (or selected if not set..) * @param {String|false} path (optional) treepath to edit - selected tree gets * edited by default. * @param {Number} 0 or 1 (optional)- column to edit. */ - var tp; + // fix tp to be the 'treepath' string (eg. 0/1/2...) + var tp; if (typeof(path) == 'string') { tp = new Gtk.TreePath.from_string(path); } else { @@ -2279,8 +2274,12 @@ Window=new XObject({ // which colum is to be edited.. var colObj = false; + + // not sure what this does.. + if (typeof(col) == 'undefined') { var k = this.getValue(path, 0); + col = 1; colObj = (!k.length || k == '|') ? this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn; } else { @@ -2289,25 +2288,67 @@ Window=new XObject({ // make sure the pulldown is set correctly.. // not really needed for second col... - - var provider = this.get('/LeftTree').getPaleteProvider(); - - var type = this.get('/LeftPanel.model').getType(path); - var opts = provider.findOptions(type); - var renderer = this.get('/LeftPanel').editableColumn.items[0].el; + var showEditor = false; - if (opts === false) { - this.get('/LeftPanel').editableColumn.setOptions([]); - renderer.has_entry = true; /// probably does not have any effect. - } else { - this.get('/LeftPanel').editableColumn.setOptions(opts); - renderer.has_entry = false; + if (col) { + var provider = this.get('/LeftTree').getPaleteProvider(); + var type = this.get('/LeftPanel.model').getType(path); + var opts = provider.findOptions(type); + var renderer = this.get('/LeftPanel').editableColumn.items[0].el; + + if (opts === false) { + this.get('/LeftPanel').editableColumn.setOptions([]); + renderer.has_entry = true; + } else { + this.get('/LeftPanel').editableColumn.setOptions(opts); + renderer.has_entry = false;/// - pulldowns do not have entries + } + // determine if we should use the Text editor... + var keyname = this.getValue(path, 0); + var data_value = this.getValue(path, 1); + + if ((keyname[0] == '|') || + ( + (typeof(data_value) == 'string' ) && + ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20)) + )) { + showEditor = true; + } + print("SHOW EDITOR" + showEditor ? 'YES' :'no'); + } + var _this = this; + // end editing.. + this.get('/BottomPane').el.hide(); + //this.get('/RightEditor').el.hide(); + this.get('/Editor').el.hide(); - var _this=this; + if (showEditor) { + + this.activePath = false; + _this.get('/Editor').el.show_all(); + GLib.timeout_add(0, 1, function() { + + //_this.get('/BottomPane').el.show(); + //_this.get('/RightEditor').el.show(); + + _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) ); + + //e.editing_done(); + //e.remove_widget(); + _this.activePath = path ; + + return false; + }); + return; + } + + + + // iter now has row... GLib.timeout_add(0, 100, function() { - + _this.activePath = path; colObj.items[0].el.editable = true; // esp. need for col 0.. _this.get('/LeftPanel.view').el.set_cursor_on_cell( tp, @@ -2390,11 +2431,12 @@ Window=new XObject({ { xtype: Gtk.TreeViewColumn, pack : "append_column", + title : "value", init : function() { XObject.prototype.init.call(this); this.el.add_attribute(this.items[0].el , 'text', 3 ); this.el.add_attribute(this.items[0].el , 'sensitive', 3 ); - this.el.add_attribute(this.items[0].el , 'editable', 3 ); + //this.el.add_attribute(this.items[0].el , 'editable', 3 ); // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL); this.get('/LeftPanel').editableColumn= this; @@ -2413,30 +2455,34 @@ Window=new XObject({ items : [ { xtype: Gtk.CellRendererCombo, - pack : "pack_start", - editable : true, - has_entry : true, - text_column : 0, - init : function() { - XObject.prototype.init.call(this); - this.el.model = new Gtk.ListStore(); - this.el.model.set_column_types ( 1, [ - GObject.TYPE_STRING // 0 real key - ]); - }, listeners : { edited : function (self, object, p0) { this.get('/LeftPanel').editing = false; - print("EDITED? p:" + p0 + " t:" + p0); + var ap = this.get('/LeftPanel.model').activePath + print("EDITED? " + ap + " - p:" + p0 + " t:" + p0); this.get('/LeftPanel.model').changed(p0, true); this.get('/LeftPanel.model').activePath = false; + this.el.editable = false; }, editing_started : function (self, editable, path) { this.get('/LeftPanel').editing = true; // console.log('editing started'); // r.has_entry = false; - this.get('/LeftPanel.model').editSelected(editable); + + this.el.editable = false; // make sure it's not editor... + } + }, + editable : false, + pack : "pack_start", + text_column : 0, + has_entry : true, + init : function() { + XObject.prototype.init.call(this); + this.el.model = new Gtk.ListStore(); + this.el.model.set_column_types ( 1, [ + GObject.TYPE_STRING // 0 real key + ]); } } ] @@ -2584,7 +2630,18 @@ Window=new XObject({ items : [ { xtype: Gtk.ListStore, + id : "model", pack : "set_model", + getValue : function(treepath, col) + { + var tp = new Gtk.TreePath.from_string (treepath); + var iter = new Gtk.TreeIter(); + this.el.get_iter (iter, tp); + var value = new GObject.Value(''); + this.el.get_value(iter, col, value); + return value.value; + + }, init : function() { XObject.prototype.init.call(this); this.el.set_column_types ( 6, [ @@ -2597,16 +2654,6 @@ Window=new XObject({ ] ); }, - getValue : function(treepath, col) - { - var tp = new Gtk.TreePath.from_string (treepath); - var iter = new Gtk.TreeIter(); - this.el.get_iter (iter, tp); - var value = new GObject.Value(''); - this.el.get_value(iter, col, value); - return value.value; - - }, showData : function(type) { this.el.clear(); if (!this.get('/MidPropTree').activeElement || !type) { @@ -2626,7 +2673,9 @@ Window=new XObject({ this.get('/MidPropTree').shown = true; } - var elementList = palete.getPropertiesFor(fullpath, type); + var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) { + return a.name > b.name ? 1 : -1; + }); print ("GOT " + elementList.length + " items for " + fullpath + "|" + type); // console.dump(elementList); @@ -2651,8 +2700,7 @@ Window=new XObject({ } - }, - id : "model" + } }, { xtype: Gtk.TreeViewColumn, @@ -2719,30 +2767,67 @@ Window=new XObject({ id : "RightBrowser", pack : "add", items : [ + { + xtype: Gtk.HBox, + pack : "pack_start,false,true,0", + items : [ + { + xtype: Gtk.Button, + listeners : { + clicked : function (self) { + this.get('/RightBrowser.view').renderJS(null,true); + } + }, + label : "Redraw", + pack : "pack_start,false,false,0" + }, + { + xtype: Gtk.CheckButton, + listeners : { + toggled : function (self, state) { + this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off"); + } + }, + active : true, + id : "AutoRedraw", + label : "Auto Redraw On", + pack : "pack_start,false,false,0" + } + ] + }, { xtype: Gtk.ScrolledWindow, pack : "add", - shadow_type : Gtk.ShadowType.IN, init : function() { XObject.prototype.init.call(this); - this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); + this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); }, + shadow_type : Gtk.ShadowType.IN, items : [ { xtype: WebKit.WebView, listeners : { load_finished : function (self, object) { + print("load finished"); + // print("load_finished"); return; // if (this.ready) { // dont do it twice! // return; //} - - this.el.get_inspector().show(); + if (!this.inspectorShown) { + this.el.get_inspector().show(); + this.inspectorShown = true; + } + this.ready = true; - this.pendingRedraw = false; - var js = this.get('/LeftTree.model').toJS(); - if (js && js[0]) { - this.renderJS(js[0]); - } + + if (this.pendingRedraw) { + this.pendingRedraw = false; + this.refreshRequired = true; + } + //var js = this.get('/LeftTree.model').toJS(); + //if (js && js[0]) { + // this.renderJS(js[0]); + //} }, script_alert : function (self, object, p0) { @@ -2751,6 +2836,7 @@ Window=new XObject({ return true; // do not display anything... }, console_message : function (self, object, p0, p1) { + print(object); // console.log(object); if (!object.match(/^\{/)) { @@ -2888,10 +2974,12 @@ Window=new XObject({ Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time); return true; }, - resource_request_starting : function (self, object, p0, p1, p2) { - // this.get('/Terminal').feed( p1.get_uri() ); + create_web_view : function (self, object) { + print("CREATE WEB VIEW"); + return null; //new WebKit.WebView(); } }, + redraws : 0, id : "view", pack : "add", init : function() { @@ -2899,19 +2987,30 @@ Window=new XObject({ // this may not work!? var settings = this.el.get_settings(); settings.enable_developer_extras = true; - // settings.enable_file_access_from_file_uris = true; - // settings.enable_offline_web_application_cache - true; - // settings.enable_universal_access_from_file_uris = true; + + // this was an attempt to change the url perms.. did not work.. + // settings.enable_file_access_from_file_uris = true; + // settings.enable_offline_web_application_cache - true; + // settings.enable_universal_access_from_file_uris = true; var _this = this; + // init inspector.. this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) { - _this.get('/BottomPane.inspector').el.show(); - return _this.get('/BottomPane.inspector').el; - //create_inspector_cb + _this.get('/BottomPane.inspector').el.show(); + return _this.get('/BottomPane.inspector').el; + }); - - this.el.open('file:///' + __script_path__ + '/../builder.html'); + // FIXME - base url of script.. + // we need it so some of the database features work. + this.el.load_html_string( "Render not ready" , + //fixme - should be a config option! + // or should we catch stuff and fix it up.. + 'http://localhost/app.Builder/' + ); + + + //this.el.open('file:///' + __script_path__ + '/../builder.html'); Gtk.drag_dest_set ( @@ -2924,31 +3023,75 @@ Window=new XObject({ // print("RB: TARGETS : " + LeftTree.atoms["STRING"]); Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList); - }, - renderJS : function(data) { - print("HTML RENDERING"); - this.get('/BottomPane').el.show(); - this.get('/BottomPane').el.set_current_page(2);// webkit view! - /// prevent looping.. - //if (this.pendingRedraw) { - // print("pending redraw active?!"); - // return; - //} + + GLib.timeout_add_seconds(0, 1, function() { + // print("run refresh?"); + _this.runRefresh(); + return true; + }); - if (!this.get('/Window.LeftTree').getActiveFile()) { + }, + renderJS : function(data, force) { + + // this is the public redraw call.. + // we refresh in a loop privately.. + var autodraw = this.get('/RightBrowser.AutoRedraw').el.active; + if (!autodraw && !force) { + print("Skipping redraw - no force, and autodraw off"); + return; + } + this.refreshRequired = true; + }, + runRefresh : function() + { + // this is run every 2 seconds from the init.. + + + + if (!this.refreshRequired) { + // print("no refresh required"); return; } + + if (this.lastRedraw) { + // do not redraw if last redraw was less that 5 seconds ago. + if (((new Date()) - this.lastRedraw) < 5000) { + return; + } + } + + + - var project = this.get('/Window.LeftTree').getActiveFile().project; - //print (project.fn); + if (!this.get('/Window.LeftTree').getActiveFile()) { + return; + } + this.refreshRequired = false; + // print("HTML RENDERING"); + + this.get('/BottomPane').el.show(); + this.get('/BottomPane').el.set_current_page(2);// webkit inspector + - project.runhtml = project.runhtml || ''; + var js = this.get('/LeftTree.model').toJS(); + if (!js || !js.length) { + print("no data"); + return; + } + var data = js[0]; + this.redraws++; + + var project = this.get('/Window.LeftTree').getActiveFile().project; + //print (project.fn); + // set it to non-empty. + project.runhtml = project.runhtml || ''; + project.runhtml = project.runhtml.length ? project.runhtml : ''; - this.runhtml = this.runhtml || ''; + this.runhtml = this.runhtml || ''; - if (project.runhtml != this.runhtml) { + if ((project.runhtml != this.runhtml) || (this.redraws > 10)) { // then we need to reload the browser using // load_html_string.. @@ -2957,13 +3100,6 @@ Window=new XObject({ var runhtml = ''+ "\n" ; - // this.runhtml = ''+ "\n" ; - // this.runhtml += ''+ "\n" ; - // this.runhtml += ''+ "\n" ; this.runhtml = project.runhtml; // need to modify paths @@ -2975,15 +3111,14 @@ Window=new XObject({ print("LOAD HTML " + html); this.el.load_html_string( html , //fixme - should be a config option! - 'http://www.akbkhome.com/e/' + 'http://localhost/app.Builder/' ); - // should trigger load_finished! + this.redraws = 0; + // should trigger load_finished! - which in truns shoudl set refresh Required; return; } - this.pendingRedraw = false; - this.renderedData = data; var str = JSON.stringify(data) ; @@ -2991,11 +3126,12 @@ Window=new XObject({ 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) + ");"); - + this.lastRedraw = new Date(); + this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");"); - + print( "before render" + this.lastRedraw); + print( "after render" + (new Date())); + } } ] @@ -3020,19 +3156,21 @@ Window=new XObject({ this.highlightWidget = false; this.withDebug = false; - - if (this.renderedEl) { - this.get('view').el.remove(this.renderedEl); - this.renderedEl.destroy(); - this.renderedEl = false; + while (this.get('view').el.get_children().length) { + var c = this.get('view').el.get_children()[0]; + this.get('view').el.remove(c); + c.destroy(); } - if (!data) { - return; + if (!data) { + return; } + var tree = this.get('/LeftTree.model').toJS(false,true)[0]; // in theory tree is actually window.. try { - this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el); + + this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el); + } catch (e) { print(e.message); return; @@ -3040,11 +3178,12 @@ Window=new XObject({ this.get('view').el.set_size_request( tree.default_width * 1 || 400, tree.default_height * 1 || 400 ) ; - - this.renderedEl.set_size_request( - tree.default_width || 600, - tree.default_height || 400 - ); + if (this.renderedEl) { + this.renderedEl.set_size_request( + tree.default_width || 600, + tree.default_height || 400 + ); + } this.get('view').el.show_all(); @@ -3112,6 +3251,10 @@ Window=new XObject({ } print("CREATE: " + item['|xns'] + '.' + item['xtype']); var type = item['|xns'] + '.' + item['xtype']; + + if (item['|xns'] == 'GtkClutter') { // we can not add this yet! + return false; + } var ns = imports.gi[item['|xns']]; var ctr = ns[item['xtype']]; var ctr_args = { }; @@ -3591,94 +3734,11 @@ Window=new XObject({ pack : "add", init : function() { XObject.prototype.init.call(this); - this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" })); - this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" })); - this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" })); + //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" })); + this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" })); + this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" })); }, items : [ - { - xtype: Gtk.ScrolledWindow, - pack : "add", - id : "RightEditor", - items : [ - { - xtype: GtkSource.View, - pack : "add", - id : "view", - init : function() { - XObject.prototype.init.call(this); - var description = Pango.Font.description_from_string("monospace") - description.set_size(8000); - this.el.modify_font(description); - - }, - load : function(str) { - - // show the help page for the active node.. - this.get('/Help').show(); - - - this.get('/BottomPane').el.set_current_page(0); - this.el.get_buffer().set_text(str, str.length); - var lm = GtkSource.LanguageManager.get_default(); - - this.el.get_buffer().set_language(lm.get_language('js')); - var buf = this.el.get_buffer(); - var cursor = buf.get_mark("insert"); - var iter= new Gtk.TextIter; - buf.get_iter_at_mark(iter, cursor); - iter.set_line(1); - iter.set_line_offset(4); - buf.move_mark(cursor, iter); - - - cursor = buf.get_mark("selection_bound"); - iter= new Gtk.TextIter; - buf.get_iter_at_mark(iter, cursor); - iter.set_line(1); - iter.set_line_offset(4); - buf.move_mark(cursor, iter); - - this.el.grab_focus(); - }, - insert_spaces_instead_of_tabs : true, - indent_width : 4, - auto_indent : true, - show_line_numbers : true, - items : [ - { - xtype: GtkSource.Buffer, - pack : "set_buffer", - listeners : { - changed : function (self) { - var s = new Gtk.TextIter(); - var e = new Gtk.TextIter(); - this.el.get_start_iter(s); - this.el.get_end_iter(e); - var str = this.el.get_text(s,e,true); - try { - Seed.check_syntax('var e = ' + str); - } catch (e) { - this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({ - red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC - })); - print("SYNTAX ERROR IN EDITOR"); - print(e); - console.dump(e); - return; - } - this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({ - red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF - })); - - this.get('/LeftPanel.model').changed( str , false); - } - } - } - ] - } - ] - }, { xtype: Gtk.ScrolledWindow, pack : "add",