X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Builder%2FWindow.js;h=ee270cf45c44df6e5cf736544169ed3682775593;hb=119290bc3234e9ece1c64dbd72ca486d9633b5b7;hp=7f8955a328f55385d2055f211cdbfbcef4915629;hpb=67b1ad2bfda2f9f60b412222edacf0ba6c8238bf;p=app.Builder.js diff --git a/Builder/Window.js b/Builder/Window.js index 7f8955a32..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,25 +52,10 @@ Window=new XObject({ }, - default_width : 800, - default_height : 500, - id : "Window", - 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(); - - } + setTitle : function(str) { + this.el.set_title(this.title + ' - ' + str); }, + type : Gtk.WindowType.TOPLEVEL, items : [ { xtype: Gtk.VBox, @@ -74,7 +79,7 @@ Window=new XObject({ use_underline : true, label : "New _Project", listeners : { - "activate":function (self) { + activate : function (self) { var _this = this; this.get('/EditProject').show({ success : function(pr) { @@ -89,7 +94,7 @@ Window=new XObject({ label : "_New File", use_underline : true, listeners : { - "activate":function (self) { + activate : function (self) { var fn = this.get('/LeftProjectTree.combo').getValue(); if (!fn) { this.get('/LeftProjectTree').showNoProjectSelected(); @@ -112,7 +117,7 @@ Window=new XObject({ pack : "add", label : "D_elete Project", listeners : { - "activate":function (self) { + activate : function (self) { var fn = this.get('/LeftProjectTree').get('combo').getValue(); if (!fn.length) { @@ -141,7 +146,7 @@ Window=new XObject({ label : "_Quit", use_underline : true, listeners : { - "activate":function (self) { + activate : function (self) { Gtk.main_quit(); } } @@ -152,7 +157,164 @@ Window=new XObject({ }, { xtype: Gtk.MenuItem, - label : "Help" + label : "_Edit", + use_underline : true, + pack : "add", + items : [ + { + xtype: Gtk.Menu, + pack : "set_submenu", + items : [ + { + xtype: Gtk.MenuItem, + listeners : { + activate : function (self) { + var fn = this.get('/LeftTree').getActiveFile(); + if (!fn) { + this.get('/StandardErrorDialog').show("No File active"); + return true; + } + + this.get('/DialogNewComponent').show(fn); + return true; + } + }, + label : "File _Properties", + pack : "add", + use_underline : true + }, + { + xtype: Gtk.MenuItem, + listeners : { + activate : function (self, event) { + this.get('/RooProjectProperties').show(); + return false; + } + }, + label : "Modify Project HTML ", + pack : "add", + use_underline : true + } + ] + } + ] + }, + { + xtype: Gtk.MenuItem, + label : "_View", + use_underline : true, + items : [ + { + xtype: Gtk.Menu, + pack : "set_submenu", + items : [ + { + xtype: Gtk.MenuItem, + listeners : { + activate : function (self, event) { + var js = this.get('/LeftTree.model').toJS(); + if (js && js[0]) { + this.get('/RightBrowser.view').renderJS(js[0], true); + } + return false; + } + }, + label : "_Redraw (Roo)", + pack : "add", + use_underline : true + }, + { + xtype: Gtk.MenuItem, + listeners : { + activate : 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], null, 4); + + var runbuilder = ''; + + html = html.replace('', runbuilder + ''); + + File.write( target+ '/builder.html', html); + + this.get('/Terminal').feed("RUN DIR:" + target); + + this.get('/Terminal').el.fork_command( null , [], [], target + , false,false,false); + var cmd = "firefox file://" + target + "/builder.html \n"; + this.get('/Terminal').el.feed_child(cmd, cmd.length); + return false; + } + }, + label : "_Test in Firefox (Roo)", + pack : "add", + use_underline : true + } + ] + } + ] + }, + { + xtype: Gtk.MenuItem, + label : "_Help", + use_underline : true, + pack : "add", + items : [ + { + xtype: Gtk.Menu, + pack : "set_submenu", + items : [ + { + xtype: Gtk.MenuItem, + pack : "add", + label : "_About", + use_underline : true, + listeners : { + activate : function (self) { + this.get('/About').el.run(); + } + } + } + ] + } + ] } ] }, @@ -175,38 +337,22 @@ Window=new XObject({ items : [ { xtype: Gtk.Expander, - label : "Select Project", - id : "expander", - pack : "pack_start,false,true", - init : function() { - XObject.prototype.init.call(this); - this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK ); - }, 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); + activate : function (self) { + // 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) { + enter_notify_event : function (self, event) { + return; this.el.expanded = !this.el.expanded; //if (this.el.expanded ) { this.listeners.activate.call(this); @@ -214,47 +360,90 @@ Window=new XObject({ return true; } + }, + 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, + id : "LeftTree", pack : "add", - shadow_type : Gtk.ShadowType.IN, - init : function() { - XObject.prototype.init.call(this); - this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + getActiveElement : function() { // return path to actie node. + + 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); + }, + getActiveFile : function() { + return this.get('model').file; + }, + getActivePath : function() { + var model = this.get('model'); + var view = this.get('view'); + if (view.selection.count_selected_rows() < 1) { + return false; + } + var iter = new Gtk.TreeIter(); + + view.selection.get_selected(model.el, iter); + return model.el.get_path(iter).to_string(); }, - id : "LeftTree", getPaleteProvider : function() { var model = this.get('model'); var pm = imports.Builder.Provider.ProjectManager.ProjectManager; return pm.getPalete(model.file.getType()); }, - renderView : function() { - var render = this.getRenderer(); - 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': return this.get('/RightBrowser.view'); case 'Gtk': @@ -262,84 +451,25 @@ Window=new XObject({ } }, - getActivePath : function() { + init : function() { + XObject.prototype.init.call(this); + this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + }, + renderView : function() { + var render = this.getRenderer(); var model = this.get('model'); - var view = this.get('view'); - if (view.selection.count_selected_rows() < 1) { - return false; + if (render) { + render.renderJS(model.toJS(false,true)[0]); + } else { + print("NO RENDER JS METHOD?"); } - var iter = new Gtk.TreeIter(); - - view.selection.get_selected(model.el, iter); - return model.el.get_path(iter).to_string(); }, + shadow_type : Gtk.ShadowType.IN, 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) { + button_press_event : function (self, ev) { console.log("button press?"); if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) { print("click" + ev.type); @@ -358,7 +488,7 @@ Window=new XObject({ print("click:" + res.path.to_string()); return false; }, - "drag_begin":function (self, drag_context) { + drag_begin : function (self, drag_context) { print('SOURCE: drag-begin'); this.targetData = false; // find what is selected in our tree... @@ -391,7 +521,7 @@ Window=new XObject({ return true; }, - "drag_end":function (self, drag_context) { + drag_end : function (self, drag_context) { Seed.print('LEFT-TREE: drag-end'); this.el.dragData = false; this.el.dropList = false; @@ -399,7 +529,7 @@ Window=new XObject({ this.get('/LeftTree.view').highlight(false); return true; }, - "drag_motion":function (self, ctx, x, y, time) { + drag_motion : function (self, ctx, x, y, time) { console.log("LEFT-TREE: drag-motion"); var src = Gtk.drag_get_source_widget(ctx); @@ -472,7 +602,7 @@ Window=new XObject({ return true; }, - "drag_drop":function (w, ctx, x, y, time) { + drag_drop : function (w, ctx, x, y, time) { Seed.print("TARGET: drag-drop"); Gtk.drag_get_data @@ -489,7 +619,7 @@ Window=new XObject({ return true; }, - "drag_data_received":function (self, ctx, x, y, sel_data, info, time) { + drag_data_received : function (self, ctx, x, y, sel_data, info, time) { print("Tree: drag-data-received"); var delete_selection_data = false; @@ -536,7 +666,7 @@ Window=new XObject({ Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time); return true; }, - "cursor_changed":function (self) { + cursor_changed : function (self) { if (this.blockChanges) { // probably not needed.. return true; } @@ -568,7 +698,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(); @@ -581,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())); @@ -594,22 +724,77 @@ 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, - pack : "set_model", - id : "model", - init : function() { - XObject.prototype.init.call(this); - this.el.set_column_types ( 3, [ - GObject.TYPE_STRING, // title - GObject.TYPE_STRING, // tip - GObject.TYPE_STRING // source.. - ] ); - }, activePath : false, + currentTree : false, + 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)) @@ -619,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]; @@ -642,76 +829,125 @@ Window=new XObject({ } }, - loadFile : function(f) { - //console.dump(f); - this.el.clear(); - this.file = f; - - if (!f) { - console.log('missing file'); - return; - } - - // load the file if not loaded.. - if (f.items === false) { - var _this = this; - f.loadItems(function() { - _this.loadFile(f); - }); - return; - - } - if (f.items.length && typeof(f.items[0]) == 'string') { - - this.get('/RightEditor').el.show(); - this.get('/RightEditor.view').load( f.items[0]); - return; - } - print("LOAD"); - //console.dump(f.items); - this.load(f.items); - this.get('/LeftTree.view').el.expand_all(); + deleteSelected : function() { + this.get('/LeftTree.view').blockChanges = true; + var old_iter = new Gtk.TreeIter(); + var s = this.get('/LeftTree.view').selection; + s.get_selected(this.el, old_iter); + var path = this.el.get_path(old_iter).to_string(); - if (!f.items.length) { - // single item.. - - this.get('/Window.leftvpaned').el.set_position(80); - // select first... - this.get('/LeftTree.view').el.set_cursor( - new Gtk.TreePath.from_string('0'), null, false); - - - } else { - this.get('/Window.leftvpaned').el.set_position(200); - } - - - //print("hide right editior"); - this.get('/RightEditor').el.hide(); - //print("set current tree"); - this.currentTree = this.toJS(false, false)[0]; - //console.dump(this.currentTree); - this.currentTree = this.currentTree || { items: [] }; - this.get('/LeftTree').renderView(); - //console.dump(this.map); - //var RightPalete = imports.Builder.RightPalete.RightPalete; - var pm = this.get('/RightPalete.model'); - // set up provider.. + this.activePath= false; + s.unselect_all(); + + this.activePath= false; + var iter = new Gtk.TreeIter(); + this.el.get_iter_from_string(iter, path); + this.el.remove(iter); + + // rebuild treemap. -- depreciated.!! + this.map = {}; + this.treemap = { }; + //this.toJS(null, true) // does not do anything? + this.activePath= false; + this.changed(false,true); + this.get('/LeftTree.view').blockChanges = false; + }, + dropNode : function(target_data, node) { + print("drop Node"); + // console.dump(node); + // console.dump(target_data); + var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false; + + print("add " + tp + "@" + target_data[1] ); + var parent = tp; + var after = false; + if (tp && target_data[1] < 2) { // before or after.. + var ar = target_data[0].split(':'); + ar.pop(); + parent = new Gtk.TreePath.from_string( ar.join(':') ); + after = tp; + } + var n_iter = new Gtk.TreeIter(); + var iter_par = new Gtk.TreeIter(); + var iter_after = after ? new Gtk.TreeIter() : false; + + + + if (parent !== false) { + this.el.get_iter(iter_par, parent); + } else { + iter_par = null; + } + + + if (tp && after) { + print(target_data[1] > 0 ? 'insert_after' : 'insert_before'); + this.el.get_iter(iter_after, after); + this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before']( + n_iter, iter_par, iter_after); - this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider(); + } else { + this.el.append(n_iter, iter_par); - if (!this.get('/RightPalete').provider) { - print ("********* PALETE PROVIDER MISSING?!!"); + } + + if (typeof(node) == 'string') { + var ar = node.split('.'); + var xtype = ar.pop(); + + node = { + '|xns' : ar.join('.'), + 'xtype' : xtype + }; + if (target_data.length == 3 && target_data[2].length) { + node['*prop'] = target_data[2]; } - this.get('/LeftTree').renderView(); + node = this.get('/DialogTemplateSelect').show(node); - pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes())); + } + // work out what kind of packing to use.. + if (typeof(node.pack) == 'undefined' && parent !== false) { + var pal = this.get('/LeftTree').getPaleteProvider(); + if (pal.name == 'Gtk') { + var pname = pal.guessName(this.singleNodeToJS(parent.to_string())); + var cname = pal.guessName(node); + node.pack = pal.getDefaultPack(pname, cname); + } + } + + + var xitems = []; + if (node.items) { + xitems = node.items; + delete node.items; + } + // load children - if it has any.. + + if (xitems) { + this.load(xitems, n_iter); + this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true); + } + if (tp && (xitems || after)) { + this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true); + } + // wee need to get the empty proptypes from somewhere.. + + //var olditer = this.activeIter; + this.activePath = this.el.get_path(n_iter).to_string(); + + // changed actually set's the node data.. + this.changed(node, true); + + + + this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false); + + //Builder.MidPropTree._model.load(node); + //Builder.MidPropTree._win.hideWin(); + //Builder.LeftPanel._model.load( node); + - - this.get('/Window.view-notebook').el.set_current_page( - this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1); - }, findDropNode : function(treepath_str, targets) { @@ -784,150 +1020,21 @@ Window=new XObject({ return []; }, - dropNode : function(target_data, node) { - print("drop Node"); - console.dump(node); - console.dump(target_data); - var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false; - - print("add " + tp + "@" + target_data[1] ); - var parent = tp; - var after = false; - if (tp && target_data[1] < 2) { // before or after.. - var ar = target_data[0].split(':'); - ar.pop(); - parent = new Gtk.TreePath.from_string( ar.join(':') ); - after = tp; - } - var n_iter = new Gtk.TreeIter(); - var iter_par = new Gtk.TreeIter(); - var iter_after = after ? new Gtk.TreeIter() : false; - - - - if (parent !== false) { - this.el.get_iter(iter_par, parent); - } else { - iter_par = null; - } - - - if (tp && after) { - print(target_data[1] > 0 ? 'insert_after' : 'insert_before'); - this.el.get_iter(iter_after, after); - this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before']( - n_iter, iter_par, iter_after); - - } else { - this.el.append(n_iter, iter_par); - - } - - if (typeof(node) == 'string') { - var ar = node.split('.'); - var xtype = ar.pop(); - - node = { - '|xns' : ar.join('.'), - 'xtype' : xtype - }; - if (target_data.length == 3 && target_data[2].length) { - node['*prop'] = target_data[2]; - } - - } - // work out what kind of packing to use.. - if (typeof(node.pack) == 'undefined' && parent !== false) { - var pal = this.get('/LeftTree').getPaleteProvider(); - - var pname = pal.guessName(this.singleNodeToJS(parent.to_string())); - print ("PNAME : " + pname); - var cname = pal.guessName(node); - print ("CNAME : " + cname); - node.pack = pal.getDefaultPack(pname, cname); - - - } - - - var xitems = []; - if (node.items) { - xitems = node.items; - delete node.items; - } - // load children - if it has any.. - - if (xitems) { - this.load(xitems, n_iter); - } - if (tp && (xitems || after)) { - this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true); - } - // wee need to get the empty proptypes from somewhere.. - - //var olditer = this.activeIter; - this.activePath = this.el.get_path(n_iter).to_string(); - - // changed actually set's the node data.. - this.changed(node, true); - - - - this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false); - - //Builder.MidPropTree._model.load(node); - //Builder.MidPropTree._win.hideWin(); - //Builder.LeftPanel._model.load( node); - - - }, - moveNode : function(target_data, action) { - //print("MOVE NODE"); - // console.dump(target_data); - var old_iter = new Gtk.TreeIter(); - var s = this.get('/LeftTree.view').selection; - s.get_selected(this.el, old_iter); - var node = this.nodeToJS(old_iter,false); - //console.dump(node); - - - // needs to drop first, otherwise the target_data - // treepath will be invalid. - - this.dropNode(target_data, node); - if (action & Gdk.DragAction.MOVE) { - // print("REMOVING OLD NODE"); - this.el.remove(old_iter); - - } - - this.activePath= false; - this.changed(false,true); + getIterValue : function (iter, col) { + var gval = new GObject.Value(''); + this.el.get_value(iter, col ,gval); + return gval.value; + + }, - deleteSelected : function() { - this.get('/LeftTree.view').blockChanges = true; - var old_iter = new Gtk.TreeIter(); - var s = this.get('/LeftTree.view').selection; - s.get_selected(this.el, old_iter); - var path = this.el.get_path(old_iter).to_string(); - - this.activePath= false; - s.unselect_all(); - - this.activePath= false; - var iter = new Gtk.TreeIter(); - this.el.get_iter_from_string(iter, path); - this.el.remove(iter); - - // rebuild treemap. -- depreciated.!! - this.map = {}; - this.treemap = { }; - //this.toJS(null, true) // does not do anything? - this.activePath= false; - this.changed(false,true); - this.get('/LeftTree.view').blockChanges = false; + init : function() { + XObject.prototype.init.call(this); + this.el.set_column_types ( 3, [ + GObject.TYPE_STRING, // title + GObject.TYPE_STRING, // tip + GObject.TYPE_STRING // source.. + ] ); }, - currentTree : false, listAllTypes : function() { var s = this.get('/LeftTree.view').selection; print ("LIST ALL TYPES: " + s.count_selected_rows() ); @@ -957,7 +1064,9 @@ Window=new XObject({ { li.forEach(function(el) { // this is specific to roo!!!? - + if (!el) { // skip empty? + return; + } var fullpath = _this.file.guessName(el); if (fullpath.length && ret.indexOf(fullpath) < 0) { ret.push(fullpath); @@ -985,94 +1094,163 @@ Window=new XObject({ return ret; }, - singleNodeToJS : function (treepath) + load : function(tr,iter) { - var iter = new Gtk.TreeIter(); - if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) { - return false; + var citer = new Gtk.TreeIter(); + //this.insert(citer,iter,0); + for(var i =0 ; i < tr.length; i++) { + if (iter) { + this.el.insert(citer,iter,-1); + } else { + this.el.append(citer); + } + + this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]); + this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]); + this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]); + if (tr[i].items && tr[i].items.length) { + this.load(tr[i].items, citer); + } + } + }, + loadFile : function(f) { + //console.dump(f); + this.el.clear(); + this.file = f; + + if (!f) { + console.log('missing file'); + return; } - var iv = this.getIterValue(iter, 2); - - return JSON.parse(iv); + // load the file if not loaded.. + if (f.items === false) { + var _this = this; + f.loadItems(function() { + _this.loadFile(f); + }); + return; + + } + this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name); - }, - nodeToJS : function (iter, with_id) - { - var par = new Gtk.TreeIter(); - var iv = this.getIterValue(iter, 2); - // print("IV" + iv); - var k = JSON.parse(iv); - if (k.json && !this.el.iter_parent( par, iter )) { - delete k.json; - } - - if (with_id) { - var treepath_str = this.el.get_path(iter).to_string(); - // not sure how we can handle mixed id stuff.. - if (typeof(k.id) == 'undefined') { - k.id = 'builder-'+ treepath_str ; - } - - // needed?? - this.treemap[ treepath_str ] = k; - k.xtreepath = treepath_str ; - - } - if (this.el.iter_has_child(iter)) { - citer = new Gtk.TreeIter(); - this.el.iter_children(citer, iter); - k.items = this.toJS(citer,with_id); - } - return k; - }, - toJS : function(iter, with_id) - { - //Seed.print("WITHID: "+ with_id); + if (f.items.length && typeof(f.items[0]) == 'string') { - var first = false; - if (!iter) { + //this.get('/RightEditor').el.show(); + //this.get('/RightEditor.view').load( f.items[0]); + return; + } + print("LOAD"); + print(JSON.stringify(f.items, null,4)); + //console.dump(f.items); + this.load(f.items); + this.get('/LeftTree.view').el.expand_all(); + + if (!f.items.length) { + // single item.. - this.treemap = { }; + this.get('/Window.leftvpaned').el.set_position(80); + // select first... + this.get('/LeftTree.view').el.set_cursor( + new Gtk.TreePath.from_string('0'), null, false); - iter = new Gtk.TreeIter(); - if (!this.el.get_iter_first(iter)) { - return []; - } - first = true; - } + + } else { + this.get('/Window.leftvpaned').el.set_position(200); + } + + + //print("hide right editior"); + //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); + this.currentTree = this.currentTree || { items: [] }; + this.get('/LeftTree').renderView(); + //console.dump(this.map); + //var RightPalete = imports.Builder.RightPalete.RightPalete; + var pm = this.get('/RightPalete.model'); + // set up provider.. + + this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider(); + + if (!this.get('/RightPalete').provider) { + print ("********* PALETE PROVIDER MISSING?!!"); + } + this.get('/LeftTree').renderView(); + + pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes())); + + + + this.get('/Window.view-notebook').el.set_current_page( + this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1); + + }, + moveNode : function(target_data, action) { + //print("MOVE NODE"); + // console.dump(target_data); + var old_iter = new Gtk.TreeIter(); + var s = this.get('/LeftTree.view').selection; + s.get_selected(this.el, old_iter); + var node = this.nodeToJS(old_iter,false); + //console.dump(node); + - var ar = []; - - while (true) { - - var k = this.nodeToJS(iter, with_id); - ar.push(k); - - - if (!this.el.iter_next(iter)) { - break; - } - } + // needs to drop first, otherwise the target_data + // treepath will be invalid. - return ar; - // convert the list into a json string.. - + this.dropNode(target_data, node); + if (action & Gdk.DragAction.MOVE) { + // print("REMOVING OLD NODE"); + this.el.remove(old_iter); + + } - }, - getIterValue : function (iter, col) { - var gval = new GObject.Value(''); - this.el.get_value(iter, col ,gval); - return gval.value; + this.activePath= false; + this.changed(false,true); + }, + nodeTip : function(c) { + var ret = this.nodeTitle(c,true); + var funcs = ''; + + for( var i in c) { + + if (!i.length || i[0] != '|') { + continue; + } + if (i == '|init') { + continue; + } + if (typeof(c[i]) != 'string') { + continue; + } + //print("prop : " + i + ':' + c[i]); + if (!c[i].match(new RegExp('function'))) { + continue; + } + funcs += "\n" + i.substring(1) + ' : ' + c[i].split(/\n/).shift(); + + } + if (funcs.length) { + ret+="\n\nMethods:" + funcs; + } + return ret; }, - nodeTitle : function(c) { + nodeTitle : function(c, renderfull) { var txt = []; c = c || {}; var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false; if (sr) txt.push(''); if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); } + + if (renderfull && c['|xns']) { + txt.push(c['|xns']); + } + if (c.xtype) { txt.push(c.xtype); } if (c.id) { txt.push('[id=' + c.id + ']'); } if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); } @@ -1097,6 +1275,43 @@ Window=new XObject({ if (sr) txt.push(''); return (txt.length == 0 ? "Element" : txt.join(" ")); }, + nodeToJS : function (treepath, with_id) + { + + var iter = treepath; // API used to be iter here.. + if (typeof(iter) == 'string') { + iter = new Gtk.TreeIter(); + if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) { + return false; + } + } + var par = new Gtk.TreeIter(); + var iv = this.getIterValue(iter, 2); + // print("IV" + iv); + var k = JSON.parse(iv); + if (k.json && !this.el.iter_parent( par, iter )) { + delete k.json; + } + + if (with_id) { + var treepath_str = this.el.get_path(iter).to_string(); + // not sure how we can handle mixed id stuff.. + if (typeof(k.id) == 'undefined') { + k.id = 'builder-'+ treepath_str ; + } + + // needed?? + this.treemap[ treepath_str ] = k; + k.xtreepath = treepath_str ; + + } + if (this.el.iter_has_child(iter)) { + citer = new Gtk.TreeIter(); + this.el.iter_children(citer, iter); + k.items = this.toJS(citer,with_id); + } + return k; + }, nodeToJSON : function(c) { var o = {} for (var i in c) { @@ -1107,52 +1322,61 @@ Window=new XObject({ } return JSON.stringify(o); }, - load : function(tr,iter) + singleNodeToJS : function (treepath) { - var citer = new Gtk.TreeIter(); - //this.insert(citer,iter,0); - for(var i =0 ; i < tr.length; i++) { - if (iter) { - this.el.insert(citer,iter,-1); - } else { - this.el.append(citer); - } - - this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]); - this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]); - this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]); - if (tr[i].items && tr[i].items.length) { - this.load(tr[i].items, citer); - } - } + var iter = new Gtk.TreeIter(); + if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) { + return false; + } + + var iv = this.getIterValue(iter, 2); + + return JSON.parse(iv); + }, - nodeTip : function(c) { - var ret = this.nodeTitle(c); - var funcs = ''; - - - for( var i in c) { - - if (!i.length || i[0] != '|') { - continue; - } - if (i == '|init') { - continue; + toJS : function(treepath, with_id) + { + //Seed.print("WITHID: "+ with_id); + var iter = treepath; // API used to be iter here.. + if (typeof(iter) == 'string') { + iter = new Gtk.TreeIter(); + if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) { + return false; } - if (typeof(c[i]) != 'string') { - continue; + } + var first = false; + if (!iter) { + + this.treemap = { }; + + iter = new Gtk.TreeIter(); + if (!this.el.get_iter_first(iter)) { + return []; } - //print("prop : " + i + ':' + c[i]); - if (!c[i].match(new RegExp('function'))) { - continue; + first = true; + } + + var ar = []; + + while (true) { + + var k = this.nodeToJS(iter, with_id); + ar.push(k); + + + if (!this.el.iter_next(iter)) { + break; } - funcs += "\n" + i.substring(1) + ' : ' + c[i].split(/\n/).shift(); - } - if (funcs.length) { - ret+="\n\nMethods:" + funcs; + + if (treepath === false) { + //dupe!!! + return JSON.parse(JSON.stringify(ar)); } - return ret; + + return ar; + // convert the list into a json string.. + } }, @@ -1182,11 +1406,30 @@ Window=new XObject({ pack : "add", label : "Delete Element", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftTree.model').deleteSelected(); } } + }, + { + xtype: Gtk.MenuItem, + listeners : { + activate : function (self) { + + var tree = this.get('/LeftTree'); + var model = this.get('/LeftTree.model'); + var el = tree.getActivePath(); + print(el); + var js = model.toJS(el, false); + // print(JSON.stringify(js[0], null,4)); + this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4)); + + + } + }, + label : "Save as Template", + pack : "add" } ] } @@ -1203,7 +1446,7 @@ Window=new XObject({ return this.project; }, listeners : { - "leave_notify_event":function (self, event) { + leave_notify_event : function (self, event) { return false; } }, @@ -1243,7 +1486,7 @@ Window=new XObject({ }); }, listeners : { - "changed":function (self) { + changed : function (self) { var fn = this.getValue(); var pm = imports.Builder.Provider.ProjectManager.ProjectManager; this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn)) @@ -1308,21 +1551,8 @@ Window=new XObject({ items : [ { xtype: Gtk.TreeView, - 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); - }, - id : "view", listeners : { - "cursor_changed":function (self) { + cursor_changed : function (self) { var iter = new Gtk.TreeIter(); if (this.selection.count_selected_rows() < 1) { @@ -1342,14 +1572,15 @@ Window=new XObject({ var file = this.get('/LeftProjectTree').project.getById(value.value); - + file.items = false; console.log(file); 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'); @@ -1358,6 +1589,19 @@ Window=new XObject({ return true; } }, + id : "view", + tooltip_column : 1, + enable_tree_lines : true, + headers_visible : false, + 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); + }, items : [ { xtype: Gtk.TreeStore, @@ -1384,7 +1628,7 @@ Window=new XObject({ 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); @@ -1437,9 +1681,6 @@ Window=new XObject({ }, { xtype: Gtk.VBox, - listeners : { - - }, items : [ { xtype: Gtk.HBox, @@ -1450,7 +1691,7 @@ Window=new XObject({ xtype: Gtk.Button, pack : "add", listeners : { - "button_press_event":function (self, event) { + button_press_event : function (self, event) { this.get('/MidPropTree.model').showData('props'); return false; } @@ -1479,7 +1720,7 @@ Window=new XObject({ xtype: Gtk.Button, pack : "add", listeners : { - "button_press_event":function (self, event) { + button_press_event : function (self, event) { this.get('/MidPropTree.model').showData('events'); return false; } @@ -1508,7 +1749,7 @@ Window=new XObject({ xtype: Gtk.Button, pack : "add", listeners : { - "button_press_event":function (self, ev) { + button_press_event : function (self, ev) { var p = this.get('/AddPropertyPopup'); if (!p.el) { p.init(); @@ -1548,7 +1789,7 @@ Window=new XObject({ tooltip_markup : "Using this.get('*someid') will find any id in an application.", label : "ID", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : 'id', @@ -1566,7 +1807,7 @@ Window=new XObject({ tooltip_markup : "Add what type of packing is to be used", label : "PACK", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : 'pack', @@ -1583,7 +1824,7 @@ Window=new XObject({ tooltip_markup : "Override the init method", label : "INIT", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : '|init', @@ -1604,7 +1845,7 @@ Window=new XObject({ tooltip_markup : "Add a user defined string property", label : "String", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : '', @@ -1621,7 +1862,7 @@ Window=new XObject({ tooltip_markup : "Add a user defined number property", label : "Number", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : '', @@ -1638,7 +1879,7 @@ Window=new XObject({ tooltip_markup : "Add a user defined boolean property", label : "Boolean", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : '', @@ -1659,7 +1900,7 @@ Window=new XObject({ tooltip_markup : "Add a user function boolean property", label : "Function", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').add( { key : '|', @@ -1678,162 +1919,126 @@ 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 : 1, - headers_visible : false, + tooltip_column : 5, enable_tree_lines : true, + headers_visible : false, init : function() { XObject.prototype.init.call(this); this.selection = this.el.get_selection(); this.selection.set_mode( Gtk.SelectionMode.SINGLE); - - - var description = new Pango.FontDescription.c_new(); - 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; - } + var description = new Pango.FontDescription.c_new(); + description.set_size(8000); + this.el.modify_font(description); }, items : [ { xtype: Gtk.TreeStore, - pack : "set_model", + activePath : false, id : "model", - init : function() { - XObject.prototype.init.call(this); - this.el.set_column_types ( 5, [ - GObject.TYPE_STRING, // 0 real key - GObject.TYPE_STRING, // 1 real value - GObject.TYPE_STRING, // 2 visable key - GObject.TYPE_STRING, // 3 visable value - GObject.TYPE_STRING, // 4 need to store type of!!! - - ]); - }, - toShort : function(str) { - var a = typeof(str) == 'string' ? str.split("\n") : []; - return a.length > 1 ? a[0] + '....' : '' + str; - }, - load : function(ar) { - this.el.clear(); - - this.get('/RightEditor').el.hide(); - if (ar === false) { - return ; - } - var ret = {}; - - - var provider = this.get('/LeftTree').getPaleteProvider(); - - // sort!!!? - var iter = new Gtk.TreeIter(); - for (var i in ar) { - if (typeof(ar[i]) == 'object') { - continue; - } - - var type = provider.findType(ar, i, ar[i]); - - this.el.append(iter); - var p = this.el.get_path(iter).to_string(); - ret[i] = p; - this.el.set_value(iter, 0, i); - this.el.set_value(iter, 1, '' + ar[i]); - this.el.set_value(iter, 2, i); - this.el.set_value(iter, 3, this.toShort(ar[i])); - this.el.set_value(iter, 4, type); - } - ar.listeners = ar.listeners || {}; - for (var i in ar.listeners ) { - this.el.append(iter); - var p = this.el.get_path(iter).to_string(); - ret['!' + i] = p; - - this.el.set_value(iter, 0, '!'+ i ); - this.el.set_value(iter, 1, '' + ar.listeners[i]); - this.el.set_value(iter, 2, ''+ i + ''); - - this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i])); - this.el.set_value(iter, 4, 'function'); - } - return ret; - }, + pack : "set_model", add : function(info) { // info includes key, val, skel, etype.. - console.dump(info); + console.dump(info); type = info.type.toLowerCase(); var data = this.toJS(); @@ -1851,7 +2056,7 @@ Window=new XObject({ if (typeof(info.val) == 'undefined') { info.val = ''; - if (info.type == 'boolean') { + if (info.type.toLowerCase() == 'boolean') { info.val = true; } if (type == 'number') { @@ -1887,65 +2092,21 @@ Window=new XObject({ ); */ }, - startEditing : function(path,col) { - /** - * 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; - if (typeof(path) == 'string') { - tp = new Gtk.TreePath.from_string(path); - } else { - var iter = new Gtk.TreeIter(); - var s = this.get('/LeftPanel.view').selection; - s.get_selected(this.el, iter); - tp = this.el.get_path(iter); - path = tp.to_string(); - } - - - // which colum is to be edited.. - var colObj = false; - if (typeof(col) == 'undefined') { - var k = this.getValue(path, 0); - colObj = (!k.length || k == '|') ? - this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn; - } else { - colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn; - } - - // make sure the pulldown is set correctly.. - // not really needed for second col... + changed : function(str, doRefresh) { + if (!this.activePath) { + return; + } + var iter = new Gtk.TreeIter(); + this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath)); + + this.el.set_value(iter, 1, '' +str); + this.el.set_value(iter, 3, '' + this.toShort(str)); + var type = this.getIterValue(iter, 4); - 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; /// probably does not have any effect. - } else { - this.get('/LeftPanel').editableColumn.setOptions(opts); - renderer.has_entry = false; - } - - var _this=this; - // iter now has row... - GLib.timeout_add(0, 100, function() { - - colObj.items[0].el.editable = true; // esp. need for col 0.. - _this.get('/LeftPanel.view').el.set_cursor_on_cell( - tp, - colObj.el, - colObj.items[0].el, - true - ); - }); - + this.el.set_value(iter, 5, type + ' : ' + str); + // update the tree... + + this.get('/LeftTree.model').changed(this.toJS(), doRefresh); }, deleteSelected : function() { var data = this.toJS(); @@ -1980,57 +2141,25 @@ Window=new XObject({ this.get('/LeftTree.model').changed(data, true); }, - activePath : false, - changed : function(str, doRefresh) { - if (!this.activePath) { - return; - } - var iter = new Gtk.TreeIter(); - this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath)); - - this.el.set_value(iter, 1, '' +str); - this.el.set_value(iter, 3, '' + this.toShort(str)); - // update the tree... - - this.get('/LeftTree.model').changed(this.toJS(), doRefresh); - }, - toJS : function() { - var iter = new Gtk.TreeIter(); - this.get('/LeftPanel.model').el.get_iter_first(iter); - var ar = {}; - - while (true) { - - var k = this.getValue(this.el.get_path(iter).to_string(), 0); - // Seed.print(k); - if (k[0] == '!') { - ar.listeners = ar.listeners || {}; - ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1); - - } else { - ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1); - } - - if (! this.get('/LeftPanel.model').el.iter_next(iter)) { - break; - } - } - - - //print(JSON.stringify(ar)); - return ar; - // convert the l + getIterValue : function(iter, col) { + var gval = new GObject.Value(''); + this.get('/LeftPanel.model').el.get_value(iter, col ,gval); + return '' + gval.value; }, 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; } @@ -2040,68 +2169,226 @@ Window=new XObject({ case 'number': case 'uint': case 'int': - return parseFloat(val); // Nan ?? invalid!!? + return parseFloat(val); // Nan ?? invalid!!? + case 'float': + case 'gfloat': + return 1.0 * parseFloat(val); // Nan ?? invalid!!? case 'boolean': return val == 'true' ? true : false; default: + var nv = parseFloat(val); + if (!isNaN(nv) && (val == ''+nv)) { + return nv; + } return val; } }, - 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; + init : function() { + XObject.prototype.init.call(this); + this.el.set_column_types ( 6, [ + GObject.TYPE_STRING, // 0 real key + GObject.TYPE_STRING, // 1 real value + GObject.TYPE_STRING, // 2 visable key + GObject.TYPE_STRING, // 3 visable value + GObject.TYPE_STRING, // 4 need to store type of!!! + GObject.TYPE_STRING // 5 tooltip + + ]); + }, + load : function(ar) { + this.el.clear(); + + //this.get('/RightEditor').el.hide(); + if (ar === false) { + return ; + } + var ret = {}; - 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; + var provider = this.get('/LeftTree').getPaleteProvider(); + var iter = new Gtk.TreeIter(); + + // sort!!!? + var keys = XObject.keys(ar); + keys.sort(); + ar.listeners = ar.listeners || {}; + + for (var i in ar.listeners ) { + this.el.append(iter); + var p = this.el.get_path(iter).to_string(); + ret['!' + i] = p; + + this.el.set_value(iter, 0, '!'+ i ); + this.el.set_value(iter, 1, '' + ar.listeners[i]); + this.el.set_value(iter, 2, ''+ i + ''); + + this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i])); + this.el.set_value(iter, 4, 'function'); + this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]); + } - if (val[0] == '!') { - showEditor = true; + + + var _this = this; + keys.forEach(function(i) { + if (typeof(ar[i]) == 'object') { + return; + } + + var type = provider.findType(ar, i, ar[i]); + + _this.el.append(iter); + var p = _this.el.get_path(iter).to_string(); + ret[i] = p; + _this.el.set_value(iter, 0, ''+i); + _this.el.set_value(iter, 1, '' + ar[i]); + _this.el.set_value(iter, 2, ''+i); + _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i])); + _this.el.set_value(iter, 4, ''+type); + _this.el.set_value(iter, 5, type + ' : ' + ar[i]); + }) + 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. + */ + // 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 { + var iter = new Gtk.TreeIter(); + var s = this.get('/LeftPanel.view').selection; + s.get_selected(this.el, iter); + tp = this.el.get_path(iter); + path = tp.to_string(); + } + + + // 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 { + colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn; } - if (val[0] == '|') { - if (rval.match(/function/g) || rval.match(/\n/g)) { + + // make sure the pulldown is set correctly.. + // not really needed for second col... + var showEditor = 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(); if (showEditor) { - var _this = this; + this.activePath = false; + _this.get('/Editor').el.show_all(); 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 ); + + //_this.get('/BottomPane').el.show(); + //_this.get('/RightEditor').el.show(); - e.editing_done(); - e.remove_widget(); - _this.activePath = activePath ; + _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) ); - // Gdk.threads_leave(); + //e.editing_done(); + //e.remove_widget(); + _this.activePath = path ; + 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); + // 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, + colObj.el, + colObj.items[0].el, + true + ); + }); + + }, + toJS : function() { + var iter = new Gtk.TreeIter(); + this.get('/LeftPanel.model').el.get_iter_first(iter); + var ar = {}; + + while (true) { + var k = this.getValue(this.el.get_path(iter).to_string(), 0); + // Seed.print(k); + if (k[0] == '!') { + ar.listeners = ar.listeners || {}; + ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1); + + } else { + ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1); + } + if (! this.get('/LeftPanel.model').el.iter_next(iter)) { + break; + } + } + + + //print(JSON.stringify(ar)); + return ar; + // convert the l + }, + toShort : function(str) { + var a = typeof(str) == 'string' ? str.split("\n") : []; + return a.length > 1 ? a[0] + '....' : '' + str; } }, { @@ -2119,12 +2406,12 @@ Window=new XObject({ xtype: Gtk.CellRendererText, pack : "pack_start", listeners : { - "editing_started":function (self, editable, path) { + editing_started : function (self, editable, path) { this.get('/LeftPanel.model').activePath = path; }, - "edited":function (self, object, p0) { + edited : function (self, object, p0) { var model = this.get('/LeftPanel.model'); var path = model.activePath; var iter = new Gtk.TreeIter(); @@ -2144,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; @@ -2167,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) { + 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) { + 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 + ]); } } ] @@ -2207,7 +2499,7 @@ Window=new XObject({ pack : "append", label : "Delete", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').deleteSelected(); } } @@ -2217,7 +2509,7 @@ Window=new XObject({ pack : "append", label : "Edit", listeners : { - "activate":function (self) { + activate : function (self) { this.get('/LeftPanel.model').startEditing(false, 0); } } @@ -2261,27 +2553,8 @@ Window=new XObject({ items : [ { xtype: Gtk.TreeView, - enable_tree_lines : true, - headers_visible : false, - tooltip_column : 2, - 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); - - - - - - }, - pack : "add", listeners : { - "cursor_changed":function (self) { + cursor_changed : function (self) { var iter = new Gtk.TreeIter(); //console.log('changed'); @@ -2308,7 +2581,7 @@ Window=new XObject({ this.get('/MidPropTree').hideWin(); - if (type == 'function') { + if (type.toLowerCase() == 'function') { if (etype != 'events') { key = '|' + key; @@ -2322,11 +2595,10 @@ Window=new XObject({ }) return; } - - if (type.indexOf('.') > -1 || - type == 'boolean') { - key = '|' + key; - } + // has dot in name, and is boolean???? this does not make sense.. + //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') { + // key = '|' + key; + // } this.get('/LeftPanel.model').add( { key : key, @@ -2335,11 +2607,41 @@ Window=new XObject({ etype : etype }) //, } + }, + pack : "add", + tooltip_column : 2, + enable_tree_lines : true, + headers_visible : false, + 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); + + + + + }, 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, [ @@ -2352,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) { @@ -2381,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); @@ -2406,8 +2700,7 @@ Window=new XObject({ } - }, - id : "model" + } }, { xtype: Gtk.TreeViewColumn, @@ -2457,13 +2750,13 @@ Window=new XObject({ items : [ { xtype: Gtk.Notebook, - pack : "add", id : "view-notebook", + pack : "add", tab_border : 0, init : function() { XObject.prototype.init.call(this); this.el.set_current_page(0); - print("SET LABEL?") + //print("SET LABEL?") this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" })); this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" })); }, @@ -2471,11 +2764,8 @@ Window=new XObject({ items : [ { xtype: Gtk.VBox, - pack : "add", id : "RightBrowser", - listeners : { - - }, + pack : "add", items : [ { xtype: Gtk.HBox, @@ -2483,81 +2773,77 @@ Window=new XObject({ items : [ { xtype: Gtk.Button, - pack : "pack_start,false,false,0", - label : "Dump HTML to console", 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));"); + 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, - pack : "add", - id : "view", - init : function() { - 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 */ - Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, - null, /* lists of target to support */ - 0, /* size of list */ - Gdk.DragAction.COPY /* what to do with data after dropped */ - ); - - // 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.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) + ");"); - this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");"); - }, listeners : { - "load_finished":function (self, object) { - if (this.ready) { // dont do it twice! - return; + load_finished : function (self, object) { + print("load finished"); + // print("load_finished"); return; + // if (this.ready) { // dont do it twice! + // return; + //} + if (!this.inspectorShown) { + this.el.get_inspector().show(); + this.inspectorShown = true; } + this.ready = true; + + if (this.pendingRedraw) { + this.pendingRedraw = false; + this.refreshRequired = true; + } + //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); + script_alert : function (self, object, p0) { + // print(p0); return false; return true; // do not display anything... }, - "console_message":function (self, object, p0, p1) { - console.log(object); + console_message : function (self, object, p0, p1) { + print(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') { @@ -2570,9 +2856,11 @@ Window=new XObject({ if (typeof(val['id']) != 'undefined') { // this.activeNode = val['id']; var tg = this.get('/LeftTree.model').findDropNode(val['id'], true); - if (!tg) { + if (!tg || typeof(tg[0]) == 'undefined') { return false; } + print("SELECT node " + tg[0]); + this.get('/LeftTree.view').selectNode(tg[0]); ret = true; @@ -2590,7 +2878,7 @@ Window=new XObject({ //Seed.print('c:'+c); return ret; }, - "drag_motion":function (w, ctx, x, y, time, ud) { + drag_motion : function (w, ctx, x, y, time, ud) { // console.log('DRAG MOTION'); // status: // if lastCurrentNode == this.currentNode.. -- don't change anything.. @@ -2630,7 +2918,7 @@ Window=new XObject({ // for tree we should handle this... return true; }, - "drag_drop":function (w, ctx, x, y,time, ud) { + drag_drop : function (w, ctx, x, y,time, ud) { print("TARGET: drag-drop"); var is_valid_drop_site = true; @@ -2649,7 +2937,7 @@ Window=new XObject({ return is_valid_drop_site; }, - "drag_data_received":function (w, ctx, x, y, sel_data, target_type, time, ud) + drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud) { print("Browser: drag-data-received"); var delete_selection_data = false; @@ -2685,7 +2973,165 @@ Window=new XObject({ Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time); return true; + }, + create_web_view : function (self, object) { + print("CREATE WEB VIEW"); + return null; //new WebKit.WebView(); + } + }, + redraws : 0, + id : "view", + pack : "add", + init : function() { + XObject.prototype.init.call(this); + // this may not work!? + var settings = this.el.get_settings(); + settings.enable_developer_extras = 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; + + }); + + // 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 + ( + 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 /* what to do with data after dropped */ + ); + + // print("RB: TARGETS : " + LeftTree.atoms["STRING"]); + Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList); + + GLib.timeout_add_seconds(0, 1, function() { + // print("run refresh?"); + _this.runRefresh(); + return true; + }); + + + }, + 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; } + } + + + + + 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 + + + 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 || ''; + + if ((project.runhtml != this.runhtml) || (this.redraws > 10)) { + // then we need to reload the browser using + // load_html_string.. + + // then trigger a redraw once it's loaded.. + this.pendingRedraw = true; + var runhtml = ''+ "\n" ; + + this.runhtml = project.runhtml; + // need to modify paths + + + + var html = imports.File.File.read(__script_path__ + '/../builder.html'); + html = html.replace('', runhtml + this.runhtml + ''); + print("LOAD HTML " + html); + this.el.load_html_string( html , + //fixme - should be a config option! + 'http://localhost/app.Builder/' + ); + this.redraws = 0; + // should trigger load_finished! - which in truns shoudl set refresh Required; + return; + + } + + + this.renderedData = data; + var str = JSON.stringify(data) ; + + if (!this.ready) { + console.log('not loaded yet'); + } + this.lastRedraw = new Date(); + + this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");"); + print( "before render" + this.lastRedraw); + print( "after render" + (new Date())); + } } ] @@ -2694,25 +3140,37 @@ Window=new XObject({ }, { xtype: Gtk.VBox, - pack : "add", id : "RightGtkView", + pack : "add", + redraw : function() { + this.highlightWidget = false; + print("REDRAW CALLED"); + this.activePath = this.get('/LeftTree').getActivePath(); + if (this.renderedEl) { + print("QUEUE DRAW CALLING"); + this.renderedEl.queue_draw(); + } + }, renderJS : function(data, withDebug) { - if (!data) { - return; - } + 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; } 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; @@ -2720,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(); @@ -2791,6 +3250,11 @@ Window=new XObject({ return; } 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 = { }; @@ -2822,16 +3286,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; } @@ -2839,7 +3304,7 @@ Window=new XObject({ var el = new ctr(ctr_args); - //print("PACK"); + print("PACK" + item.pack); //console.dump(item.pack); @@ -2886,7 +3351,22 @@ Window=new XObject({ var _this = this; item.items = item.items || []; - item.items.forEach(function(ch) { + item.items.forEach(function(ch,n) { + + print ("type:" + type); + + print ("ch.pack:" + ch.pack); + if (type == 'Gtk.Table' && ch.pack == 'add') { + var c = n % item.n_columns; + var r = Math.floor(n/item.n_columns); + ch.pack = [ 'attach', c, c+1, r, r+1, + typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options, + typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options, + typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding, + typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding + ].join(','); + } + _this.viewAdd(ch, el); }); @@ -2913,6 +3393,14 @@ Window=new XObject({ return el; }, + widgetDragDropEvent : function() { + print("WIDGET DRAGDROP"); + return true; + }, + widgetDragMotionEvent : function() { + print("WIDGET DRAGMOTION"); + return true; + }, widgetExposeEvent : function(w, evt, ud, item) { var widget = w; if (this.inRender) { @@ -2982,14 +3470,6 @@ Window=new XObject({ this.inRender = false; return false; }, - widgetDragMotionEvent : function() { - print("WIDGET DRAGMOTION"); - return true; - }, - widgetDragDropEvent : function() { - print("WIDGET DRAGDROP"); - return true; - }, widgetPressEvent : function(w,e,u,d) { if (this.get('view').pressed) { return false; @@ -3003,15 +3483,6 @@ Window=new XObject({ this.get('view').pressed = false; return false; }, - redraw : function() { - this.highlightWidget = false; - print("REDRAW CALLED"); - this.activePath = this.get('/LeftTree').getActivePath(); - if (this.renderedEl) { - print("QUEUE DRAW CALLING"); - this.renderedEl.queue_draw(); - } - }, items : [ { xtype: Gtk.HBox, @@ -3022,23 +3493,20 @@ Window=new XObject({ pack : "pack_start,false,false,0", label : "Run The Application", listeners : { - "button_press_event":function (self, event) { - // call render on left tree - with special option!?! + button_press_event : function (self, event) { + // 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"; @@ -3108,7 +3576,7 @@ Window=new XObject({ }, id : "view", listeners : { - "drag_motion":function (self, ctx, x, y, time) { + drag_motion : function (self, ctx, x, y, time) { // A) find out from drag all the places that node could be dropped. var src = Gtk.drag_get_source_widget(ctx); @@ -3145,7 +3613,7 @@ Window=new XObject({ // for tree we should handle this... return true; }, - "drag_drop":function (self,ctx, x, y, time) { + drag_drop : function (self,ctx, x, y, time) { Seed.print("TARGET: drag-drop"); var is_valid_drop_site = true; @@ -3165,7 +3633,7 @@ Window=new XObject({ return is_valid_drop_site; }, - "drag_data_received":function (w, ctx, x, y, sel_data, target_type, time, ud) + drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud) { Seed.print("GtkView: drag-data-received"); var delete_selection_data = false; @@ -3202,7 +3670,7 @@ Window=new XObject({ Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time); return true; }, - "button_press_event":function (self, event) { + button_press_event : function (self, event) { this.pressed = false; return false; } @@ -3220,8 +3688,27 @@ Window=new XObject({ }, { xtype: Gtk.ScrolledWindow, - pack : "add", id : "Help", + pack : "add", + 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, @@ -3232,7 +3719,8 @@ Window=new XObject({ this.get('/Window.help-view').el.open( "http://devel.akbkhome.com/seed/"); - } + }, + zoom_level : 0.8 } ] } @@ -3242,101 +3730,37 @@ Window=new XObject({ }, { xtype: Gtk.Notebook, + id : "BottomPane", 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[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" })); }, - id : "BottomPane", items : [ { xtype: Gtk.ScrolledWindow, pack : "add", - id : "RightEditor", items : [ { - xtype: GtkSource.View, + xtype: Vte.Terminal, 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); + id : "Terminal", + 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); }, - 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('/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(); + scroll_on_output : true, + init : function() { + XObject.prototype.init.call(this); + this.el.set_size (80, 1000); }, - 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); - } - } - } - ] + scrollback_lines : 1000 } ] }, @@ -3345,12 +3769,9 @@ Window=new XObject({ pack : "add", items : [ { - xtype: Vte.Terminal, - pack : "add", - id : "Terminal", - feed : function(str) { - this.el.feed(str,str.length); - } + xtype: WebKit.WebView, + id : "inspector", + pack : "add" } ] } @@ -3385,7 +3806,7 @@ Window=new XObject({ xtype: Gtk.Button, pack : "pack_start,false,true", listeners : { - "clicked":function (self) { + clicked : function (self) { this.get('/RightPalete').show(); } }, @@ -3408,7 +3829,7 @@ Window=new XObject({ this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK ); }, listeners : { - "enter_notify_event":function (self, event) { + enter_notify_event : function (self, event) { this.get('/RightPalete').show(); return false; } @@ -3434,7 +3855,7 @@ Window=new XObject({ xtype: Gtk.Button, pack : "pack_start,false,true", listeners : { - "clicked":function (self) { + clicked : function (self) { this.get('/RightPalete').hide(); } }, @@ -3504,7 +3925,7 @@ Window=new XObject({ headers_visible : false, enable_tree_lines : true, listeners : { - "drag_begin":function (self, ctx) { + drag_begin : function (self, ctx) { // we could fill this in now... Seed.print('SOURCE: drag-begin'); @@ -3538,7 +3959,7 @@ Window=new XObject({ return true; }, - "drag_data_get":function (self, drag_context, selection_data, info, time) { + drag_data_get : function (self, drag_context, selection_data, info, time) { //Seed.print('Palete: drag-data-get: ' + target_type); if (this.el.dragData && this.el.dragData.length ) { selection_data.set_text(this.el.dragData ,this.el.dragData.length); @@ -3549,7 +3970,7 @@ Window=new XObject({ }, - "drag_end":function (self, drag_context) { + drag_end : function (self, drag_context) { Seed.print('SOURCE: drag-end'); this.el.dragData = false; this.el.dropList = false;