Sample/builder.js
[app.Builder.js] / Sample / builder.bjs.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 builder.bjs=new XObject({
13 xtype: Gtk.Window,
14 type : Gtk.WindowType.TOPLEVEL,
15 title : "Application Builder",
16 border_width : 0,
17 init : function() {
18      this.atoms = {
19            "STRING" : Gdk.atom_intern("STRING")
20         };
21         this.targetList = new Gtk.TargetList();
22         this.targetList.add( this.atoms["STRING"], 0, 0);
23         //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
24 Gtk.rc_parse_string(
25             "style \"gtkcombobox-style\" {\n" + 
26             "    GtkComboBox::appears-as-list = 1\n" +
27             "}\n"+
28             "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
29     XObject.prototype.init.call(this);
30    // this.el.show_all();
31     
32    
33               
34 },
35 default_width : 800,
36 default_height : 500,
37 id : "Window",
38 listeners : {
39     
40 },
41 items : [
42     {
43         xtype: Gtk.VBox,
44         id : "w-vbox",
45         items : [
46             {
47                 xtype: Gtk.MenuBar,
48                 pack : "pack_start,false,false",
49                 items : [
50                     {
51                         xtype: Gtk.MenuItem,
52                         label : "File",
53                         items : [
54                             {
55                                 xtype: Gtk.Menu,
56                                 pack : "set_submenu",
57                                 items : [
58                                     {
59                                         xtype: Gtk.MenuItem,
60                                         label : "New Project",
61                                         listeners : {
62                                             
63                                         }
64                                     },
65                                     {
66                                         xtype: Gtk.MenuItem,
67                                         label : "New File",
68                                         listeners : {
69                                             
70                                         }
71                                     },
72                                     {
73                                         xtype: Gtk.SeparatorMenuItem,
74                                         pack : "add"
75                                     },
76                                     {
77                                         xtype: Gtk.MenuItem,
78                                         label : "Add Directory to Project",
79                                         pack : "add",
80                                         listeners : {
81                                             
82                                         }
83                                     },
84                                     {
85                                         xtype: Gtk.SeparatorMenuItem,
86                                         pack : "add"
87                                     },
88                                     {
89                                         xtype: Gtk.MenuItem,
90                                         label : "Quit",
91                                         pack : "add"
92                                     }
93                                 ]
94                             }
95                         ]
96                     },
97                     {
98                         xtype: Gtk.MenuItem,
99                         label : "Help"
100                     }
101                 ]
102             },
103             {
104                 xtype: Gtk.HPaned,
105                 id : "left",
106                 position : 400,
107                 items : [
108                     {
109                         xtype: Gtk.HBox,
110                         items : [
111                             {
112                                 xtype: Gtk.VPaned,
113                                 position : 300,
114                                 id : "leftvpaned",
115                                 items : [
116                                     {
117                                         xtype: Gtk.VBox,
118                                         id : "LeftTopPanel",
119                                         items : [
120                                             {
121                                                 xtype: Gtk.Expander,
122                                                 label : "Select Project",
123                                                 id : "expander",
124                                                 pack : "pack_start,false,true",
125                                                 init : function() {
126                                                     XObject.prototype.init.call(this);
127                                                    this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
128                                                 },
129                                                 listeners : {
130                                                     
131                                                 }
132                                             },
133                                             {
134                                                 xtype: Gtk.Notebook,
135                                                 id : "notebook",
136                                                 show_border : false,
137                                                 show_tabs : false,
138                                                 pack : "pack_start,true,true",
139                                                 init : function() {
140                                                     XObject.prototype.init.call(this);
141                                                         this.el.set_current_page(0);
142                                                 
143                                                 },
144                                                 items : [
145                                                     {
146                                                         xtype: Gtk.ScrolledWindow,
147                                                         pack : "add",
148                                                         shadow_type : Gtk.ShadowType.IN,
149                                                         init : function() {
150                                                             XObject.prototype.init.call(this);
151                                                             this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
152                                                         },
153                                                         id : "LeftTree",
154                                                         getPaleteProvider : function() {
155                                                             var model = this.get('model');
156                                                             var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
157                                                             return pm.getPalete(model.file.getType());
158                                                         },
159                                                         renderView : function() {
160                                                                  var model = this.get('model');
161                                                                 print("RENDER VIEW?" + model.file.getType());
162                                                                 switch( model.file.getType()) {
163                                                                         case 'Roo':
164                                                                             this.get('/RightBrowser.view').renderJS(model.toJS(false,true)[0]);
165                                                                         case 'Gtk':
166                                                                             this.get('/RightGtkView').renderJS(model.toJS(false,true)[0]);
167                                                                 }
168                                                         },
169                                                         items : [
170                                                             {
171                                                                 xtype: Gtk.TreeView,
172                                                                 pack : "add",
173                                                                 id : "view",
174                                                                 headers_visible : false,
175                                                                 enable_tree_lines : true,
176                                                                 tooltip_column : 0,
177                                                                 init : function() {
178                                                                         XObject.prototype.init.call(this);
179                                                                         var description = new Pango.FontDescription.c_new();
180                                                                         description.set_size(8000);
181                                                                         this.el.modify_font(description);
182                                                                 
183                                                                         this.selection = this.el.get_selection();
184                                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
185                                                                         var _this = this;
186                                                                         this.selection.signal['changed'].connect(function() {
187                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
188                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
189                                                                                 );
190                                                                         });
191                                                                 
192                                                                         Gtk.drag_source_set (
193                                                                                 this.el,            /* widget will be drag-able */
194                                                                                 Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
195                                                                                 null,            /* lists of target to support */
196                                                                                 0,              /* size of list */
197                                                                                 Gdk.DragAction.COPY   | Gdk.DragAction.MOVE           /* what to do with data after dropped */
198                                                                         );
199                                                                 
200                                                                         Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
201                                                                 
202                                                                         Gtk.drag_source_add_text_targets(this.el); 
203                                                                         Gtk.drag_dest_set
204                                                                         (
205                                                                             this.el,              /* widget that will accept a drop */
206                                                                             Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
207                                                                             null,            /* lists of target to support */
208                                                                             0,              /* size of list */
209                                                                             Gdk.DragAction.COPY   | Gdk.DragAction.MOVE       /* what to do with data after dropped */
210                                                                         );
211                                                                 
212                                                                         Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
213                                                                         Gtk.drag_dest_add_text_targets(this.el);
214                                                                 },
215                                                                 highlight : function(treepath_ar) {
216                                                                                     if (treepath_ar.length && treepath_ar[0].length ) {
217                                                                                 this.el.set_drag_dest_row( 
218                                                                                     new  Gtk.TreePath.from_string( treepath_ar[0] ),  treepath_ar[1]);
219                                                                             } else {
220                                                                                 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
221                                                                             }
222                                                                              
223                                                                         },
224                                                                 selectNode : function(treepath_str) {
225                                                                     this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
226                                                                 },
227                                                                 listeners : {
228                                                                     
229                                                                 },
230                                                                 items : [
231                                                                     {
232                                                                         xtype: Gtk.TreeStore,
233                                                                         pack : "set_model",
234                                                                         id : "model",
235                                                                         init : function() {
236                                                                             XObject.prototype.init.call(this);
237                                                                          this.el.set_column_types ( 3, [
238                                                                                     GObject.TYPE_STRING, // title 
239                                                                                     GObject.TYPE_STRING, // tip
240                                                                                     GObject.TYPE_STRING // source..
241                                                                                     ] );
242                                                                         },
243                                                                         activePath : false,
244                                                                         changed : function(n, refresh) {
245                                                                                  print("MODEL CHANGED CALLED" + this.activePath);
246                                                                                  if (this.activePath) {
247                                                                                         var iter = new Gtk.TreeIter();
248                                                                                         this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
249                                                                                         this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
250                                                                                         this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
251                                                                                         
252                                                                                         this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
253                                                                                     }
254                                                                                         //this.currentTree = this.toJS(false, true)[0];
255                                                                                     this.file.items = this.toJS(false, false);
256                                                                                     print("AFTER CHANGED");
257                                                                                     //console.dump(this.file.items);
258                                                                                     this.file.save();
259                                                                                     this.currentTree = this.file.items[0];
260                                                                                     //console.log(this.file.toSource());
261                                                                                     
262                                                                                     if (refresh) {
263                                                                                         print("REDNER BROWSER?!");
264                                                                                         this.get('/LeftTree').renderView();
265                                                                         
266                                                                                         var pm = this.get('/RightPalete.model');
267                                                                                         if (!this.get('/RightPalete').provider) {
268                                                                                             pm.load([]);
269                                                                                             return;
270                                                                                         }
271                                                                                         
272                                                                                         
273                                                                                         pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
274                                                                                         //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
275                                                                                     }
276                                                                                           
277                                                                         },
278                                                                         loadFile : function(f) {
279                                                                             //console.dump(f);
280                                                                                     this.el.clear();
281                                                                                     this.file = f;
282                                                                                     
283                                                                                     if (!f) {
284                                                                                         console.log('missing file');
285                                                                                         return;
286                                                                                     }
287                                                                                     
288                                                                                     // load the file if not loaded..
289                                                                                     if (f.items === false) {
290                                                                                         var _this = this;
291                                                                                         f.loadItems(function() {
292                                                                                             _this.loadFile(f);
293                                                                                         });
294                                                                                         return;
295                                                                                         
296                                                                                     }
297                                                                                     if (f.items.length && typeof(f.items[0]) == 'string') {
298                                                                                     
299                                                                                         this.get('/RightEditor').el.show();
300                                                                                         this.get('/RightEditor.view').load( f.items[0]);
301                                                                                         return;
302                                                                                     }
303                                                                                     print("LOAD");
304                                                                                     //console.dump(f.items);
305                                                                                     this.load(f.items);
306                                                                                     this.get('/LeftTree.view').el.expand_all();
307                                                                         
308                                                                                     if (!f.items.length) {
309                                                                                         // single item..
310                                                                                         
311                                                                                         this.get('/Window.leftvpaned').el.set_position(80);
312                                                                                         // select first...
313                                                                                         this.get('/LeftTree.view').el.set_cursor( 
314                                                                                             new  Gtk.TreePath.from_string('0'), null, false);
315                                                                                         
316                                                                                         
317                                                                                     } else {
318                                                                                           this.get('/Window.leftvpaned').el.set_position(200);
319                                                                                     }
320                                                                                     
321                                                                                     
322                                                                                     //print("hide right editior");
323                                                                                     this.get('/RightEditor').el.hide();
324                                                                                     //print("set current tree");
325                                                                                     this.currentTree = this.toJS(false, false)[0];
326                                                                                     //console.dump(this.currentTree);
327                                                                                     this.currentTree = this.currentTree || { items: [] };
328                                                                                     this.get('/LeftTree').renderView();
329                                                                                     //console.dump(this.map);
330                                                                                     //var RightPalete     = imports.Builder.RightPalete.RightPalete;
331                                                                                     var pm = this.get('/RightPalete.model');
332                                                                                     // set up provider..
333                                                                                     
334                                                                                     this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
335                                                                                     
336                                                                                     if (!this.get('/RightPalete').provider) {
337                                                                                         print ("********* PALETE PROVIDER MISSING?!!");
338                                                                                     }
339                                                                                     this.get('/LeftTree').renderView();
340                                                                                     
341                                                                                     pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
342                                                                                     
343                                                                                     
344                                                                                             
345                                                                                     this.get('/Window.view-notebook').el.set_current_page(
346                                                                                         this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
347                                                                                             
348                                                                         },
349                                                                         findDropNode : function(treepath_str, targets) {
350                                                                         
351                                                                         // this is used by the dragdrop code in the roo version AFAIR..
352                                                                         
353                                                                                         var path = treepath_str.replace(/^builder-/, '');
354                                                                                     // treemap is depreciated... - should really check if model has any entries..
355                                                                         
356                                                                                     if (!this.el.iter_n_children(null)) {
357                                                                                         print("NO KEYS");
358                                                                                         return [ '',  Gtk.TreeViewDropPosition.INTO_OR_AFTER];
359                                                                                     }
360                                                                                     print("FIND treepath: " + path);
361                                                                                     //console.dump(this.treemap);
362                                                                                     
363                                                                                     if (!treepath_str.match(/^builder-/)) {
364                                                                                         return []; // nothing!
365                                                                                     }
366                                                                                     if (targets === true) {
367                                                                                         return [ path ];
368                                                                                     }
369                                                                                     return this.findDropNodeByPath(path,targets) 
370                                                                         },
371                                                                         findDropNodeByPath : function(treepath_str, targets, pref) {
372                                                                             var path = treepath_str + ''; // dupe it..
373                                                                             pref = typeof(pref) == 'undefined' ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
374                                                                             var last = false;
375                                                                             //console.dump(this.treemap);
376                                                                             while (path.length) {
377                                                                                 print("LOOKING FOR PATH: " + path);
378                                                                                 var node_data = this.singleNodeToJS(path);
379                                                                                 if (node_data === false) {
380                                                                                     print("node not found");
381                                                                                     return [];
382                                                                                 }
383                                                                                 
384                                                                                 var xname = this.get('/LeftTree.model').file.guessName(node_data);
385                                                                                 var match = false;
386                                                                                 var prop = '';
387                                                                                 targets.forEach(function(tg) {
388                                                                                     if (match) {
389                                                                                         return;;
390                                                                                     }
391                                                                                     if ((tg == xname)  ) {
392                                                                                         match = tg;
393                                                                                     }
394                                                                                     if (tg.indexOf(xname +':') === 0) {
395                                                                                         match = tg;
396                                                                                         prop = tg.split(':').pop();
397                                                                                     }
398                                                                                 });
399                                                                                 
400                                                                                 if (match) {
401                                                                                     if (last) { // pref is after/before..
402                                                                                         // then it's after last
403                                                                                         if (pref > 1) {
404                                                                                             return []; // do not allow..
405                                                                                         }
406                                                                                         return [ last, pref , prop];
407                                                                                         
408                                                                                     }
409                                                                                     return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
410                                                                                 }
411                                                                                 var par = path.split(':');
412                                                                                 last = path;
413                                                                                 par.pop();
414                                                                                 path = par.join(':');
415                                                                             }
416                                                                             
417                                                                             return [];
418                                                                                     
419                                                                         },
420                                                                         dropNode : function(target_data, node) {
421                                                                                   console.dump(target_data);
422                                                                                     var tp = target_data[0].length ? new  Gtk.TreePath.from_string( target_data[0] ) : false;
423                                                                                     
424                                                                                     print("add where: " + target_data[1]  );
425                                                                                     var parent = tp;
426                                                                                     var after = false;
427                                                                                     if (target_data[1]  < 2) { // before or after..
428                                                                                         var ar = target_data[0].split(':');
429                                                                                         ar.pop();
430                                                                                         parent  = new  Gtk.TreePath.from_string( ar.join(':') );
431                                                                                         after = tp;
432                                                                                     }
433                                                                                     var n_iter = new Gtk.TreeIter();
434                                                                                     var iter_par = new Gtk.TreeIter();
435                                                                                     var iter_after = after ? new Gtk.TreeIter() : false;
436                                                                                     
437                                                                                     
438                                                                                     
439                                                                                     if (parent !== false) {
440                                                                                         this.el.get_iter(iter_par, parent);
441                                                                                     } else {
442                                                                                         iter_par = null;
443                                                                                     }
444                                                                                     
445                                                                                     
446                                                                                     if (after) {
447                                                                                         print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
448                                                                                         this.el.get_iter(iter_after, after);
449                                                                                         this.el[ target_data[1]  > 0 ? 'insert_after' : 'insert_before'](
450                                                                                                 n_iter, iter_par, iter_after);
451                                                                                         
452                                                                                     } else {
453                                                                                         this.el.append(n_iter, iter_par);
454                                                                                         
455                                                                                     }
456                                                                                     
457                                                                                     if (typeof(node) == 'string') {
458                                                                                         var ar = node.split('.');
459                                                                                         var xtype = ar.pop();
460                                                                                         
461                                                                                         node = {
462                                                                                             '|xns' : ar.join('.'),
463                                                                                             'xtype' : xtype
464                                                                                         };
465                                                                                         if (target_data.length == 3 && target_data[2].length) {
466                                                                                             node['*prop'] = target_data[2];
467                                                                                         }
468                                                                                         
469                                                                                     }
470                                                                                     // work out what kind of packing to use..
471                                                                                     if (typeof(node.pack) == 'undefined'  && parent !== false) {
472                                                                                         var pal = this.get('/LeftTree').getPaleteProvider();
473                                                                                         
474                                                                                         var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
475                                                                                         print ("PNAME : "  + pname);
476                                                                                         var cname = pal.guessName(node);
477                                                                                         print ("CNAME : "  + cname);
478                                                                                         node.pack = pal.getDefaultPack(pname, cname);
479                                                                                         
480                                                                                         
481                                                                                     }
482                                                                                     
483                                                                                     
484                                                                                     var xitems = [];
485                                                                                     if (node.items) {
486                                                                                         xitems = node.items;
487                                                                                         delete node.items;
488                                                                                     }
489                                                                                     if (xitems) {
490                                                                                         this.load(xitems, n_iter);
491                                                                                     }
492                                                                                     if (xitems || after) {
493                                                                                         this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
494                                                                                     }
495                                                                                     // wee need to get the empty proptypes from somewhere..
496                                                                                     
497                                                                                     //var olditer = this.activeIter;
498                                                                                     this.activeIter = n_iter;
499                                                                                     this.changed(node, true);
500                                                                                     
501                                                                                     
502                                                                                     
503                                                                                     this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
504                                                                                     
505                                                                                     //Builder.MidPropTree._model.load(node);
506                                                                                     //Builder.MidPropTree._win.hideWin();
507                                                                                     //Builder.LeftPanel._model.load( node);
508                                                                                     
509                                                                                     
510                                                                         },
511                                                                         moveNode : function(target_data, action) {
512                                                                              //print("MOVE NODE");
513                                                                                    // console.dump(target_data);
514                                                                                     var old_iter = new Gtk.TreeIter();
515                                                                                     var s = this.get('/LeftTree.view').selection;
516                                                                                     s.get_selected(this.el, old_iter);
517                                                                                     var node = this.nodeToJS(old_iter,false);
518                                                                                     //console.dump(node);
519                                                                                     
520                                                                                     
521                                                                                     // needs to drop first, otherwise the target_data 
522                                                                                     // treepath will be invalid.
523                                                                                     
524                                                                                     this.dropNode(target_data, node);
525                                                                                   if (action & Gdk.DragAction.MOVE) {
526                                                                                               //          print("REMOVING OLD NODE");
527                                                                                                         this.el.remove(old_iter);
528                                                                                                         
529                                                                                     }
530                                                                                     
531                                                                                     this.activeIter = false;
532                                                                                     this.changed(false,true);
533                                                                         },
534                                                                         deleteSelected : function() {
535                                                                                     
536                                                                                     var old_iter = new Gtk.TreeIter();
537                                                                                     var s = this.get('/LeftTree.view').selection;
538                                                                                     s.get_selected(this.el, old_iter);
539                                                                                     s.unselect_all();
540                                                                                     
541                                                                                     this.el.remove(old_iter);
542                                                                                     
543                                                                                     // rebuild treemap. -- depreciated.!!
544                                                                                     this.map = {};
545                                                                                     this.treemap = { };
546                                                                                     //this.toJS(null, true) // does not do anything?
547                                                                                     this.activeIter = false;
548                                                                                     this.changed(false,true);
549                                                                         },
550                                                                         currentTree : false,
551                                                                         listAllTypes : function() {
552                                                                             var s = this.get('/LeftTree.view').selection;
553                                                                             print ("LIST ALL TYPES: " + s.count_selected_rows() );
554                                                                             
555                                                                             if (s.count_selected_rows() > 0) {
556                                                                                 var iter = new Gtk.TreeIter();    
557                                                                                 s.get_selected(this.el, iter);
558                                                                         
559                                                                                 // set some properties of the tree for use by the dropped element.
560                                                                                 var value = new GObject.Value('');
561                                                                                 this.el.get_value(iter, 2, value);
562                                                                                 var data = JSON.parse(value.value);
563                                                                                 
564                                                                                 
565                                                                                 var xname = this.get('/LeftTree.model').file.guessName(data);
566                                                                                 console.log('selected:' + xname);
567                                                                                 if (xname.length) {
568                                                                                     return [ xname ];
569                                                                                 }
570                                                                                 return []; // could not find it..
571                                                                             }
572                                                                             
573                                                                             var ret = [ ];
574                                                                             
575                                                                            var _this = this;
576                                                                             function addall(li)
577                                                                             {
578                                                                                 li.forEach(function(el) {
579                                                                                     // this is specific to roo!!!?
580                                                                                     
581                                                                                     var fullpath =  _this.file.guessName(el);
582                                                                                     if (fullpath.length && ret.indexOf(fullpath) < 0) {
583                                                                                         ret.push(fullpath);
584                                                                                     }
585                                                                                     
586                                                                                     
587                                                                                     if (el.items && el.items.length) {
588                                                                                         addall(el.items);
589                                                                                     }
590                                                                                     
591                                                                                 });
592                                                                                 
593                                                                                 
594                                                                             }
595                                                                             
596                                                                             addall([this.currentTree]);
597                                                                             
598                                                                             // only if we have nothing, should we add '*top'
599                                                                             if (!ret.length) {
600                                                                                 ret = [ '*top' ];
601                                                                             }
602                                                                             //console.log('all types in tree');
603                                                                             //console.dump(ret);
604                                                                             
605                                                                             return ret;
606                                                                                                     
607                                                                         },
608                                                                         singleNodeToJS : function (treepath) 
609                                                                                 {
610                                                                                     var iter = new Gtk.TreeIter(); 
611                                                                                     if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
612                                                                                         return false;
613                                                                                     }
614                                                                                     
615                                                                                     var iv = this.getIterValue(iter, 2);
616                                                                                    
617                                                                                     return JSON.parse(iv);
618                                                                                     
619                                                                                 },
620                                                                         nodeToJS : function (iter, with_id) 
621                                                                         {
622                                                                             var par = new Gtk.TreeIter(); 
623                                                                             var iv = this.getIterValue(iter, 2);
624                                                                            // print("IV" + iv);
625                                                                             var k = JSON.parse(iv);
626                                                                             if (k.json && !this.el.iter_parent( par, iter  )) {
627                                                                                 delete k.json;
628                                                                             }
629                                                                             
630                                                                             if (with_id) {
631                                                                                 var treepath_str = this.el.get_path(iter).to_string();
632                                                                                 // not sure how we can handle mixed id stuff..
633                                                                                 if (typeof(k.id) == 'undefined')  {
634                                                                                     k.id =  'builder-'+ treepath_str ;
635                                                                                 }
636                                                                                 
637                                                                                 // needed??
638                                                                                 this.treemap[  treepath_str ] = k;
639                                                                                 k.xtreepath = treepath_str ;
640                                                                                 
641                                                                             }
642                                                                             if (this.el.iter_has_child(iter)) {
643                                                                                 citer = new Gtk.TreeIter();
644                                                                                 this.el.iter_children(citer, iter);
645                                                                                 k.items = this.toJS(citer,with_id);
646                                                                             }
647                                                                             return k;
648                                                                         },
649                                                                         toJS : function(iter, with_id)
650                                                                                 {
651                                                                                     //Seed.print("WITHID: "+ with_id);
652                                                                                     
653                                                                                     var first = false;
654                                                                                     if (!iter) {
655                                                                                         
656                                                                                         this.treemap = { }; 
657                                                                                         
658                                                                                         iter = new Gtk.TreeIter();
659                                                                                         if (!this.el.get_iter_first(iter)) {
660                                                                                             return [];
661                                                                                         }
662                                                                                         first = true;
663                                                                                     } 
664                                                                                     
665                                                                                     var ar = [];
666                                                                                        
667                                                                                     while (true) {
668                                                                                         
669                                                                                         var k = this.nodeToJS(iter, with_id); 
670                                                                                         ar.push(k);
671                                                                                         
672                                                                                         
673                                                                                         if (!this.el.iter_next(iter)) {
674                                                                                             break;
675                                                                                         }
676                                                                                     }
677                                                                                     
678                                                                                     return ar;
679                                                                                     // convert the list into a json string..
680                                                                                 
681                                                                                     
682                                                                                 },
683                                                                         getIterValue : function (iter, col) {
684                                                                             var gval = new GObject.Value('');
685                                                                             this.el.get_value(iter, col ,gval);
686                                                                             return  gval.value;
687                                                                             
688                                                                             
689                                                                         },
690                                                                         nodeTitle : function(c) {
691                                                                               var txt = [];
692                                                                             c = c || {};
693                                                                             var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
694                                                                             if (sr) txt.push('<s>');
695                                                                             if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
696                                                                             if (c.xtype)      { txt.push(c.xtype); }
697                                                                             if (c.id)      { txt.push('<b>[id=' + c.id + ']</b>'); }
698                                                                             if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
699                                                                             if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
700                                                                             
701                                                                             
702                                                                             if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
703                                                                             if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
704                                                                             if (c.label)      { txt.push('<b>' + c.label+ '</b>'); }
705                                                                             if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
706                                                                             if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
707                                                                             if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
708                                                                             if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
709                                                                             if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
710                                                                             if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
711                                                                             
712                                                                             // for flat classes...
713                                                                             if (typeof(c['*class']) != 'undefined')  { txt.push('<b>' +  c['*class']+  '</b>'); }
714                                                                             if (typeof(c['*extends']) != 'undefined')  { txt.push(': <i>' +  c['*extends']+  '</i>'); }
715                                                                             
716                                                                             
717                                                                             if (sr) txt.push('</s>');
718                                                                             return (txt.length == 0 ? "Element" : txt.join(" "));
719                                                                         },
720                                                                         nodeToJSON : function(c) {
721                                                                             var o  = {}
722                                                                             for (var i in c) {
723                                                                                 if (i == 'items') {
724                                                                                      continue;
725                                                                                 }
726                                                                                 o[i] = c[i];
727                                                                             }
728                                                                             return JSON.stringify(o);
729                                                                         },
730                                                                         load : function(tr,iter)
731                                                                                 {
732                                                                                     var citer = new Gtk.TreeIter();
733                                                                                     //this.insert(citer,iter,0);
734                                                                                     for(var i =0 ; i < tr.length; i++) {
735                                                                                         if (iter) {
736                                                                                             this.el.insert(citer,iter,-1);
737                                                                                         } else {
738                                                                                             this.el.append(citer);
739                                                                                         }
740                                                                                         
741                                                                                         this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
742                                                                                         this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
743                                                                                         this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
744                                                                                         if (tr[i].items && tr[i].items.length) {
745                                                                                             this.load(tr[i].items, citer);
746                                                                                         }
747                                                                                     }     
748                                                                                 }
749                                                                     },
750                                                                     {
751                                                                         xtype: Gtk.TreeViewColumn,
752                                                                         pack : "append_column",
753                                                                         init : function() {
754                                                                             XObject.prototype.init.call(this);
755                                                                            this.el.add_attribute(this.items[0].el , 'markup', 0 );
756                                                                         },
757                                                                         items : [
758                                                                             {
759                                                                                 xtype: Gtk.CellRendererText,
760                                                                                 pack : "pack_start"
761                                                                             }
762                                                                         ]
763                                                                     }
764                                                                 ]
765                                                             }
766                                                         ]
767                                                     },
768                                                     {
769                                                         xtype: Gtk.VBox,
770                                                         pack : "add",
771                                                         id : "LeftProjectTree",
772                                                         showNoProjectSelected : function() {
773                                                            this.get('/StandardErrorDialog').show("Select a Project first."); 
774                                                         },
775                                                         listeners : {
776                                                             
777                                                         },
778                                                         items : [
779                                                             {
780                                                                 xtype: Gtk.HBox,
781                                                                 pack : "pack_start,false,false",
782                                                                 items : [
783                                                                     {
784                                                                         xtype: Gtk.ComboBox,
785                                                                         id : "combo",
786                                                                         init : function() {
787                                                                             XObject.prototype.init.call(this);
788                                                                             this.el.add_attribute(this.get('render').el , 'markup', 1 );  
789                                                                         },
790                                                                         getValue : function() {
791                                                                             var ix = this.el.get_active();
792                                                                             if (ix < 0 ) {
793                                                                                 return false;
794                                                                             }
795                                                                             var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
796                                                                             return data[ix].fn;
797                                                                         },
798                                                                         setValue : function(fn)
799                                                                         {
800                                                                             var el = this.el;
801                                                                             el.set_active(-1);
802                                                                             var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
803                                                                             data.forEach(function(n, ix) {
804                                                                                 if (fn == n.fn) {
805                                                                                     el.set_active(ix);
806                                                                                     return false;
807                                                                                 }
808                                                                             });
809                                                                         },
810                                                                         listeners : {
811                                                                             
812                                                                         },
813                                                                         items : [
814                                                                             {
815                                                                                 xtype: Gtk.CellRendererText,
816                                                                                 pack : "pack_start,true",
817                                                                                 id : "render"
818                                                                             },
819                                                                             {
820                                                                                 xtype: Gtk.ListStore,
821                                                                                 pack : "set_model",
822                                                                                 init : function() {
823                                                                                     XObject.prototype.init.call(this);
824                                                                                   this.el.set_column_types ( 2, [
825                                                                                         GObject.TYPE_STRING,  // real key
826                                                                                         GObject.TYPE_STRING // real type
827                                                                                         
828                                                                                         
829                                                                                     ] );
830                                                                                         
831                                                                                 },
832                                                                                 loadData : function(data) {
833                                                                                      var ov = this.get('/LeftProjectTree.combo').getValue();
834                                                                                     this.el.clear();
835                                                                                     var iter = new Gtk.TreeIter();
836                                                                                     var el = this.el;
837                                                                                     data.forEach(function(p) {
838                                                                                         
839                                                                                         el.append(iter);
840                                                                                         
841                                                                                          
842                                                                                         el.set_value(iter, 0, p.fn);
843                                                                                         el.set_value(iter, 1, p.name);
844                                                                                         
845                                                                                     });
846                                                                                     
847                                                                                     this.get('/LeftProjectTree.combo').setValue(ov);
848                                                                                 },
849                                                                                 id : "combomodel"
850                                                                             }
851                                                                         ]
852                                                                     }
853                                                                 ]
854                                                             },
855                                                             {
856                                                                 xtype: Gtk.ScrolledWindow,
857                                                                 pack : "add",
858                                                                 shadow_type : Gtk.ShadowType.IN,
859                                                                 init : function() {
860                                                                     XObject.prototype.init.call(this);
861                                                                     this.el.set_policy  (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
862                                                                 },
863                                                                 items : [
864                                                                     {
865                                                                         xtype: Gtk.TreeView,
866                                                                         headers_visible : false,
867                                                                         enable_tree_lines : true,
868                                                                         tooltip_column : 1,
869                                                                         init : function() {
870                                                                             XObject.prototype.init.call(this);
871                                                                         var description = new Pango.FontDescription.c_new();
872                                                                                                     description.set_size(8000);
873                                                                                                     this.el.modify_font(description);
874                                                                                                     
875                                                                                                     this.selection = this.el.get_selection();
876                                                                                                     this.selection.set_mode( Gtk.SelectionMode.SINGLE);
877                                                                         },
878                                                                         id : "view",
879                                                                         listeners : {
880                                                                             
881                                                                         },
882                                                                         items : [
883                                                                             {
884                                                                                 xtype: Gtk.TreeStore,
885                                                                                 pack : "set_model",
886                                                                                 id : "model",
887                                                                                 init : function() {
888                                                                                     XObject.prototype.init.call(this);
889                                                                                   this.el.set_column_types ( 3, [
890                                                                                                     GObject.TYPE_STRING, // title 
891                                                                                                     GObject.TYPE_STRING, // tip
892                                                                                                     GObject.TYPE_STRING // id..
893                                                                                                     ] );
894                                                                                    
895                                                                                 },
896                                                                                 loadProject : function(pr) {
897                                                                                            this.el.clear();
898                                                                                             if (!pr) {
899                                                                                                 return;
900                                                                                             }
901                                                                                             this.get('/LeftProjectTree').project = pr;
902                                                                                             this.load(pr.toTree());
903                                                                                             this.get('/LeftProjectTree.view').el.expand_all();
904                                                                                 },
905                                                                                 load : function(tr,iter) {
906                                                                                     console.dump(tr);
907                                                                                             console.log('Project tree load: ' + tr.length);
908                                                                                             var citer = new Gtk.TreeIter();
909                                                                                             //this.insert(citer,iter,0);
910                                                                                             
911                                                                                             var _this = this;
912                                                                                             tr.forEach(function (r) {
913                                                                                                 if (!iter) {
914                                                                                                     _this.el.append(citer);   
915                                                                                                 } else {
916                                                                                                     _this.el.insert(citer,iter,-1);
917                                                                                                 }
918                                                                                                 _this.el.set_value(citer, 0,  '' + r.getTitle() ); // title 
919                                                                                                 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
920                                                                                                 _this.el.set_value(citer, 2, '' + r.id ); //id
921                                                                                                 if (r.cn && r.cn.length) {
922                                                                                                     _this.load(r.cn, citer);
923                                                                                                 }
924                                                                                                 
925                                                                                             });
926                                                                                 },
927                                                                                 getValue : function(iter, col) {
928                                                                                     var gval = new GObject.Value('');
929                                                                                     this.el.get_value(iter, col ,gval);
930                                                                                     return  '' + gval.value;
931                                                                                 }
932                                                                             },
933                                                                             {
934                                                                                 xtype: Gtk.TreeViewColumn,
935                                                                                 pack : "append_column",
936                                                                                 init : function() {
937                                                                                     XObject.prototype.init.call(this);
938                                                                                     this.el.add_attribute(this.items[0].el , 'markup', 0 );
939                                                                                 },
940                                                                                 items : [
941                                                                                     {
942                                                                                         xtype: Gtk.CellRendererText,
943                                                                                         pack : "pack_start"
944                                                                                     }
945                                                                                 ]
946                                                                             }
947                                                                         ]
948                                                                     }
949                                                                 ]
950                                                             }
951                                                         ]
952                                                     }
953                                                 ]
954                                             }
955                                         ]
956                                     },
957                                     {
958                                         xtype: Gtk.VBox,
959                                         listeners : {
960                                             
961                                         },
962                                         items : [
963                                             {
964                                                 xtype: Gtk.HBox,
965                                                 pack : "pack_start,false,true,0",
966                                                 id : "LeftProps",
967                                                 items : [
968                                                     {
969                                                         xtype: Gtk.Button,
970                                                         pack : "add",
971                                                         listeners : {
972                                                             
973                                                         },
974                                                         items : [
975                                                             {
976                                                                 xtype: Gtk.HBox,
977                                                                 pack : "add",
978                                                                 items : [
979                                                                     {
980                                                                         xtype: Gtk.Image,
981                                                                         pack : "add",
982                                                                         stock : Gtk.STOCK_ADD,
983                                                                         icon_size : Gtk.IconSize.MENU
984                                                                     },
985                                                                     {
986                                                                         xtype: Gtk.Label,
987                                                                         pack : "add",
988                                                                         label : "Property"
989                                                                     }
990                                                                 ]
991                                                             }
992                                                         ]
993                                                     },
994                                                     {
995                                                         xtype: Gtk.Button,
996                                                         pack : "add",
997                                                         listeners : {
998                                                             
999                                                         },
1000                                                         items : [
1001                                                             {
1002                                                                 xtype: Gtk.HBox,
1003                                                                 pack : "add",
1004                                                                 items : [
1005                                                                     {
1006                                                                         xtype: Gtk.Image,
1007                                                                         pack : "add",
1008                                                                         stock : Gtk.STOCK_ADD,
1009                                                                         icon_size : Gtk.IconSize.MENU
1010                                                                     },
1011                                                                     {
1012                                                                         xtype: Gtk.Label,
1013                                                                         pack : "add",
1014                                                                         label : "Handler"
1015                                                                     }
1016                                                                 ]
1017                                                             }
1018                                                         ]
1019                                                     },
1020                                                     {
1021                                                         xtype: Gtk.Button,
1022                                                         pack : "add",
1023                                                         listeners : {
1024                                                             
1025                                                         },
1026                                                         items : [
1027                                                             {
1028                                                                 xtype: Gtk.HBox,
1029                                                                 pack : "add",
1030                                                                 items : [
1031                                                                     {
1032                                                                         xtype: Gtk.Image,
1033                                                                         pack : "add",
1034                                                                         stock : Gtk.STOCK_ADD,
1035                                                                         icon_size : Gtk.IconSize.MENU
1036                                                                     },
1037                                                                     {
1038                                                                         xtype: Gtk.Label,
1039                                                                         pack : "add",
1040                                                                         label : "Other"
1041                                                                     }
1042                                                                 ]
1043                                                             },
1044                                                             {
1045                                                                 xtype: Gtk.Menu,
1046                                                                 pack : false,
1047                                                                 id : "AddPropertyPopup",
1048                                                                 items : [
1049                                                                     {
1050                                                                         xtype: Gtk.MenuItem,
1051                                                                         pack : "append",
1052                                                                         tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1053                                                                         label : "ID",
1054                                                                         listeners : {
1055                                                                             
1056                                                                         }
1057                                                                     },
1058                                                                     {
1059                                                                         xtype: Gtk.MenuItem,
1060                                                                         pack : "append",
1061                                                                         tooltip_markup : "Add what type of packing is to be used",
1062                                                                         label : "PACK",
1063                                                                         listeners : {
1064                                                                             
1065                                                                         }
1066                                                                     },
1067                                                                     {
1068                                                                         xtype: Gtk.MenuItem,
1069                                                                         pack : "append",
1070                                                                         tooltip_markup : "Override the init method",
1071                                                                         label : "INIT",
1072                                                                         listeners : {
1073                                                                             
1074                                                                         }
1075                                                                     },
1076                                                                     {
1077                                                                         xtype: Gtk.SeparatorMenuItem,
1078                                                                         pack : "add"
1079                                                                     },
1080                                                                     {
1081                                                                         xtype: Gtk.MenuItem,
1082                                                                         pack : "append",
1083                                                                         tooltip_markup : "Add a user defined string property",
1084                                                                         label : "String",
1085                                                                         listeners : {
1086                                                                             
1087                                                                         }
1088                                                                     },
1089                                                                     {
1090                                                                         xtype: Gtk.MenuItem,
1091                                                                         pack : "append",
1092                                                                         tooltip_markup : "Add a user defined number property",
1093                                                                         label : "Number",
1094                                                                         listeners : {
1095                                                                             
1096                                                                         }
1097                                                                     },
1098                                                                     {
1099                                                                         xtype: Gtk.MenuItem,
1100                                                                         pack : "append",
1101                                                                         tooltip_markup : "Add a user defined boolean property",
1102                                                                         label : "Boolean",
1103                                                                         listeners : {
1104                                                                             
1105                                                                         }
1106                                                                     },
1107                                                                     {
1108                                                                         xtype: Gtk.SeparatorMenuItem,
1109                                                                         pack : "add"
1110                                                                     },
1111                                                                     {
1112                                                                         xtype: Gtk.MenuItem,
1113                                                                         pack : "append",
1114                                                                         tooltip_markup : "Add a user function boolean property",
1115                                                                         label : "Function",
1116                                                                         listeners : {
1117                                                                             
1118                                                                         }
1119                                                                     }
1120                                                                 ]
1121                                                             }
1122                                                         ]
1123                                                     }
1124                                                 ]
1125                                             },
1126                                             {
1127                                                 xtype: Gtk.ScrolledWindow,
1128                                                 id : "LeftPanel",
1129                                                 pack : "add",
1130                                                 shadow_type : Gtk.ShadowType.IN,
1131                                                 editing : false,
1132                                                 init : function() {
1133                                                     XObject.prototype.init.call(this);
1134                                                    this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1135                                                 },
1136                                                 items : [
1137                                                     {
1138                                                         xtype: Gtk.TreeView,
1139                                                         id : "view",
1140                                                         tooltip_column : 1,
1141                                                         headers_visible : false,
1142                                                         enable_tree_lines : true,
1143                                                         init : function() {
1144                                                              XObject.prototype.init.call(this); 
1145                                                                                
1146                                                                             this.selection = this.el.get_selection();
1147                                                                             this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1148                                                                          
1149                                                                             
1150                                                                             var description = new Pango.FontDescription.c_new();
1151                                                                             description.set_size(8000);
1152                                                                             this.el.modify_font(description);
1153                                                         },
1154                                                         listeners : {
1155                                                             
1156                                                         },
1157                                                         items : [
1158                                                             {
1159                                                                 xtype: Gtk.TreeStore,
1160                                                                 pack : "set_model",
1161                                                                 id : "model",
1162                                                                 init : function() {
1163                                                                     XObject.prototype.init.call(this);
1164                                                                 this.el.set_column_types ( 5, [
1165                                                                                                 GObject.TYPE_STRING,  // 0 real key
1166                                                                                                 GObject.TYPE_STRING, // 1 real value 
1167                                                                                                  GObject.TYPE_STRING,  // 2 visable key
1168                                                                                                  GObject.TYPE_STRING, // 3 visable value
1169                                                                                                  GObject.TYPE_STRING, // 4 need to store type of!!!
1170                                                                                               
1171                                                                                             ]);
1172                                                                 },
1173                                                                 toShort : function(str) {
1174                                                                     var a = typeof(str) == 'string' ? str.split("\n") : [];
1175                                                                         return a.length > 1 ? a[0] + '....' : '' + str;
1176                                                                 },
1177                                                                 load : function(ar) {
1178                                                                      this.el.clear();
1179                                                                                             
1180                                                                             this.get('/RightEditor').el.hide();
1181                                                                             if (ar === false) {
1182                                                                                 return ;
1183                                                                             }
1184                                                                             var ret = {}; 
1185                                                                             
1186                                                                 
1187                                                                             var provider = this.get('/LeftTree').getPaleteProvider();
1188                                                                             
1189                                                                             // sort!!!?
1190                                                                             var iter = new Gtk.TreeIter();
1191                                                                             for (var i in ar) {
1192                                                                                 if (typeof(ar[i]) == 'object') {
1193                                                                                     continue;
1194                                                                                 }
1195                                                                                 
1196                                                                                 var type = provider.findType(ar, i, ar[i]);
1197                                                                                 
1198                                                                                 this.el.append(iter);
1199                                                                                 var p = this.el.get_path(iter).to_string();
1200                                                                                 ret[i] = p;
1201                                                                                 this.el.set_value(iter, 0, i);
1202                                                                                 this.el.set_value(iter, 1, '' + ar[i]);
1203                                                                                 this.el.set_value(iter, 2, i);
1204                                                                                 this.el.set_value(iter, 3, this.toShort(ar[i]));
1205                                                                                 this.el.set_value(iter, 4, type);
1206                                                                             }
1207                                                                             ar.listeners = ar.listeners || {};
1208                                                                             for (var i in ar.listeners ) {
1209                                                                                 this.el.append(iter);
1210                                                                                 var p = this.el.get_path(iter).to_string();
1211                                                                                 ret['!' + i] = p;
1212                                                                                 
1213                                                                                 this.el.set_value(iter, 0, '!'+  i  );
1214                                                                                 this.el.set_value(iter, 1, '' + ar.listeners[i]);
1215                                                                                 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
1216                                                                                 
1217                                                                                 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
1218                                                                                 this.el.set_value(iter, 4, 'function');
1219                                                                             }
1220                                                                             return ret;
1221                                                                 },
1222                                                                 add : function(info) {
1223                                                                       // info includes key, val, skel, etype..
1224                                                                                              console.dump(info);
1225                                                                             type = info.type.toLowerCase();
1226                                                                             var data = this.toJS();
1227                                                                             
1228                                                                             if (info.etype == 'events') {
1229                                                                                 data.listeners = data.listeners || { };
1230                                                                                 if (typeof(data.listeners[info.key]) != 'undefined') {
1231                                                                                     return; //already set!
1232                                                                                 }
1233                                                                             } else {
1234                                                                                 if (typeof(data[info.key]) != 'undefined') {
1235                                                                                     return;
1236                                                                                 }
1237                                                                             }
1238                                                                             
1239                                                                             if (typeof(info.val) == 'undefined') {
1240                                                                                     
1241                                                                                 info.val = '';
1242                                                                                 if (info.type == 'boolean') {
1243                                                                                     info.val = true;
1244                                                                                 }
1245                                                                                 if (type == 'number') {
1246                                                                                     info.val = 0;
1247                                                                                 }
1248                                                                                 // utf8 == string..
1249                                                                                 
1250                                                                                 
1251                                                                             }
1252                                                                             var k = info.key;
1253                                                                             if (info.etype == 'events') {
1254                                                                              
1255                                                                                 data.listeners[info.key] = info.val;
1256                                                                                 k = '!' + info.key;
1257                                                                             } else {
1258                                                                                 data[info.key] = info.val;
1259                                                                             }
1260                                                                             
1261                                                                             
1262                                                                             var map = this.load(data);
1263                                                                             
1264                                                                             // flag it as changed to the interface..
1265                                                                 
1266                                                                             this.get('/LeftTree.model').changed(data, true); 
1267                                                                             
1268                                                                             
1269                                                                             this.startEditing(map[k]);
1270                                                                              
1271                                                                             /*
1272                                                                             LeftPanel.get('view').el.row_activated(
1273                                                                                 new Gtk.TreePath.from_string(map[k]), 
1274                                                                                 LeftPanel.editableColumn.el
1275                                                                             );
1276                                                                             */
1277                                                                 },
1278                                                                 startEditing : function(path,col) {
1279                                                                 /**
1280                                                                 * start editing path (or selected if not set..)
1281                                                                 * @param {String|false} path  (optional) treepath to edit - selected tree gets
1282                                                                 *     edited by default.
1283                                                                 * @param {Number} 0 or 1 (optional)- column to edit. 
1284                                                                 */
1285                                                                      var tp;
1286                                                                             if (typeof(path) == 'string') {
1287                                                                                 tp = new Gtk.TreePath.from_string(path);
1288                                                                             } else {
1289                                                                                 var iter = new Gtk.TreeIter();
1290                                                                                 var s = this.get('/LeftPanel.view').selection;
1291                                                                                 s.get_selected(this.el, iter);
1292                                                                                 tp = this.el.get_path(iter);
1293                                                                                 path = tp.to_string();
1294                                                                             }
1295                                                                             
1296                                                                            
1297                                                                             // which colum is to be edited..
1298                                                                             var colObj = false;
1299                                                                             if (typeof(col) == 'undefined') {
1300                                                                                 var k = this.getValue(path, 0);
1301                                                                                 colObj = (!k.length || k == '|') ? 
1302                                                                                     this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
1303                                                                             } else {
1304                                                                                 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
1305                                                                             }
1306                                                                             
1307                                                                             // make sure the pulldown is set correctly..
1308                                                                             // not really needed for second col...
1309                                                                 
1310                                                                             var provider = this.get('/LeftTree').getPaleteProvider();
1311                                                                            
1312                                                                             var type = this.get('/LeftPanel.model').getType(path);
1313                                                                             var opts = provider.findOptions(type);
1314                                                                             var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
1315                                                                             
1316                                                                             if (opts === false) {
1317                                                                                 this.get('/LeftPanel').editableColumn.setOptions([]);
1318                                                                                 renderer.has_entry = true; /// probably does not have any effect.
1319                                                                             } else {
1320                                                                                 this.get('/LeftPanel').editableColumn.setOptions(opts);
1321                                                                                 renderer.has_entry = false;
1322                                                                             }
1323                                                                             
1324                                                                             var _this=this;
1325                                                                             // iter now has row...
1326                                                                             GLib.timeout_add(0, 100, function() {
1327                                                                                 
1328                                                                                 colObj.items[0].el.editable = true; // esp. need for col 0..
1329                                                                                 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
1330                                                                                     tp,
1331                                                                                     colObj.el,
1332                                                                                     colObj.items[0].el,
1333                                                                                     true
1334                                                                                 );
1335                                                                             });
1336                                                                             
1337                                                                 },
1338                                                                 deleteSelected : function() {
1339                                                                      var data = this.toJS();
1340                                                                     var iter = new Gtk.TreeIter();
1341                                                                     var s = this.get('/LeftPanel.view').selection;
1342                                                                     s.get_selected(this.el, iter);
1343                                                                          
1344                                                                        
1345                                                                     var gval = new GObject.Value('');
1346                                                                    this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
1347                                                                     
1348                                                                     var val = gval.value;
1349                                                                     if (val[0] == '!') {
1350                                                                         // listener..
1351                                                                         if (!data.listeners || typeof(data.listeners[  val.substring(1)]) == 'undefined') {
1352                                                                             return;
1353                                                                         }
1354                                                                         delete data.listeners[  val.substring(1)];
1355                                                                         if (!XObject.keys(data.listeners).length) {
1356                                                                             delete data.listeners;
1357                                                                         }
1358                                                                         
1359                                                                     } else {
1360                                                                         if (typeof(data[val]) == 'undefined') {
1361                                                                             return;
1362                                                                         }
1363                                                                         delete data[val];
1364                                                                     }
1365                                                                     
1366                                                                     
1367                                                                     this.load(data);
1368                                                                     this.get('/LeftTree.model').changed(data, true);
1369                                                                     
1370                                                                 },
1371                                                                 activePath : false,
1372                                                                 changed : function(str, doRefresh) {
1373                                                                     if (!this.activePath) {
1374                                                                         return;
1375                                                                     }
1376                                                                     var iter = new Gtk.TreeIter();
1377                                                                     this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
1378                                                                     
1379                                                                     this.el.set_value(iter, 1, '' +str);
1380                                                                     this.el.set_value(iter, 3, '' + this.toShort(str));
1381                                                                     // update the tree...
1382                                                                     var LeftTree        = imports.Builder.LeftTree.LeftTree;
1383                                                                     this.get('/LeftTree.model').changed(this.toJS(), doRefresh); 
1384                                                                 },
1385                                                                 toJS : function() {
1386                                                                      var iter = new Gtk.TreeIter();
1387                                                                     this.get('/LeftPanel.model').el.get_iter_first(iter);
1388                                                                     var ar = {};
1389                                                                        
1390                                                                     while (true) {
1391                                                                         
1392                                                                         var k = this.getValue(this.el.get_path(iter).to_string(), 0);
1393                                                                        // Seed.print(k);
1394                                                                         if (k[0] == '!') {
1395                                                                             ar.listeners = ar.listeners || {};
1396                                                                             ar.listeners[  k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
1397                                                                             
1398                                                                         } else {
1399                                                                             ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
1400                                                                         }
1401                                                                         
1402                                                                         if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
1403                                                                             break;
1404                                                                         }
1405                                                                     }
1406                                                                     
1407                                                                     
1408                                                                     //print(JSON.stringify(ar));
1409                                                                     return ar;
1410                                                                     // convert the l
1411                                                                 },
1412                                                                 getType : function(treepath) {
1413                                                                      return this.getValue(treepath, 4);
1414                                                                 },
1415                                                                 getValue : function(treepath_str, col) {
1416                                                                       var iter = new Gtk.TreeIter();
1417                                                                     this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
1418                                                                     
1419                                                                     var gval = new GObject.Value('');
1420                                                                     this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1421                                                                     var val = '' + gval.value;
1422                                                                     if (col != 1) {
1423                                                                         return val;
1424                                                                     }
1425                                                                     var type = this.getType(this.el.get_path(iter).to_string());
1426                                                                     //print("TYPE: " +type + " -  val:" + val);
1427                                                                     switch(type.toLowerCase()) {
1428                                                                         case 'number':
1429                                                                         case 'uint':
1430                                                                         case 'int':
1431                                                                             return parseFloat(val); // Nan ?? invalid!!?
1432                                                                         case 'boolean':
1433                                                                             return val == 'true' ? true : false;
1434                                                                         default: 
1435                                                                             return val;
1436                                                                     }
1437                                                                                             
1438                                                                 },
1439                                                                 editSelected : function(e) {
1440                                                                     print("EDIT SELECTED?");
1441                                                                             var iter = new Gtk.TreeIter();
1442                                                                             var s = this.get('/LeftPanel.view').selection;
1443                                                                             s.get_selected(this.get('/LeftPanel.model').el, iter);
1444                                                                             var m = this.get('/LeftPanel.model')
1445                                                                            
1446                                                                             var gval = new GObject.Value('');
1447                                                                             this.el.get_value(iter, 0 ,gval);
1448                                                                             var val = '' + gval.value;
1449                                                                             
1450                                                                             gval = new GObject.Value('');
1451                                                                             this.el.get_value(iter, 1 ,gval);
1452                                                                             var rval = gval.value;
1453                                                                             var activePath = this.el.get_path(iter).to_string(); 
1454                                                                             this.activePath = activePath ;
1455                                                                             // was activeIter...
1456                                                                             //  not listener...
1457                                                                             
1458                                                                             var showEditor = false;
1459                                                                             
1460                                                                             if (val[0] == '!') {
1461                                                                                 showEditor = true;
1462                                                                             }
1463                                                                             if (val[0] == '|') {
1464                                                                                 if (rval.match(/function/g) || rval.match(/\n/g)) {
1465                                                                                     showEditor = true;
1466                                                                                 }
1467                                                                             }
1468                                                                             
1469                                                                             if (showEditor) {
1470                                                                                 var _this = this;
1471                                                                                 this.activePath = false;
1472                                                                                 GLib.timeout_add(0, 1, function() {
1473                                                                                     //   Gdk.threads_enter();
1474                                                                                     _this.get('/RightEditor').el.show();
1475                                                                                    _this.get('/RightEditor.view').load( rval );
1476                                                                                     
1477                                                                                     e.editing_done();
1478                                                                                     e.remove_widget();
1479                                                                                     _this.activePath = activePath ;
1480                                                                                     
1481                                                                              //       Gdk.threads_leave();
1482                                                                                     return false;
1483                                                                                 });
1484                                                                                 return;
1485                                                                             }
1486                                                                              
1487                                                                             this.get('/RightEditor').el.hide();
1488                                                                 
1489                                                                             //var type = this.getValue(this.el.get_path(iter).to_string(),4);
1490                                                                             
1491                                                                             
1492                                                                 }
1493                                                             },
1494                                                             {
1495                                                                 xtype: Gtk.TreeViewColumn,
1496                                                                 pack : "append_column",
1497                                                                 init : function() {
1498                                                                     XObject.prototype.init.call(this);
1499                                                                 
1500                                                                     this.el.add_attribute(this.items[0].el , 'markup', 2 );
1501                                                                     this.get('/LeftPanel').propertyColumn = this;
1502                                                                 },
1503                                                                 title : "key",
1504                                                                 items : [
1505                                                                     {
1506                                                                         xtype: Gtk.CellRendererText,
1507                                                                         pack : "pack_start",
1508                                                                         listeners : {
1509                                                                             
1510                                                                         }
1511                                                                     }
1512                                                                 ]
1513                                                             },
1514                                                             {
1515                                                                 xtype: Gtk.TreeViewColumn,
1516                                                                 pack : "append_column",
1517                                                                 init : function() {
1518                                                                     XObject.prototype.init.call(this);
1519                                                                         this.el.add_attribute(this.items[0].el , 'text', 3 );
1520                                                                         this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
1521                                                                         this.el.add_attribute(this.items[0].el , 'editable', 3 );
1522                                                                           // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
1523                                                                 
1524                                                                         this.get('/LeftPanel').editableColumn= this;
1525                                                                 },
1526                                                                 setOptions : function(ar) {
1527                                                                        var m = this.items[0].el.model;
1528                                                                             m.clear();
1529                                                                             var iter = new Gtk.TreeIter();
1530                                                                             ar.forEach(function(i) {
1531                                                                                    // sort!!!?
1532                                                                                 m.append(iter);
1533                                                                                 m.set_value(iter, 0, i);
1534                                                                             });
1535                                                                             
1536                                                                 },
1537                                                                 items : [
1538                                                                     {
1539                                                                         xtype: Gtk.CellRendererCombo,
1540                                                                         pack : "pack_start",
1541                                                                         editable : true,
1542                                                                         has_entry : true,
1543                                                                         text_column : 0,
1544                                                                         init : function() {
1545                                                                             XObject.prototype.init.call(this);
1546                                                                            this.el.model = new Gtk.ListStore();
1547                                                                             this.el.model.set_column_types ( 1, [
1548                                                                                 GObject.TYPE_STRING  // 0 real key
1549                                                                               ]);
1550                                                                         },
1551                                                                         listeners : {
1552                                                                             
1553                                                                         }
1554                                                                     }
1555                                                                 ]
1556                                                             }
1557                                                         ]
1558                                                     },
1559                                                     {
1560                                                         xtype: Gtk.Menu,
1561                                                         pack : false,
1562                                                         id : "LeftPanelPopup",
1563                                                         items : [
1564                                                             {
1565                                                                 xtype: Gtk.MenuItem,
1566                                                                 pack : "append",
1567                                                                 label : "Delete",
1568                                                                 listeners : {
1569                                                                     
1570                                                                 }
1571                                                             },
1572                                                             {
1573                                                                 xtype: Gtk.MenuItem,
1574                                                                 pack : "append",
1575                                                                 label : "Edit",
1576                                                                 listeners : {
1577                                                                     
1578                                                                 }
1579                                                             }
1580                                                         ]
1581                                                     }
1582                                                 ]
1583                                             }
1584                                         ]
1585                                     }
1586                                 ]
1587                             },
1588                             {
1589                                 xtype: Gtk.ScrolledWindow,
1590                                 pack : "pack_end,false,true,0",
1591                                 id : "MidPropTree",
1592                                 shadow_type : Gtk.ShadowType.IN,
1593                                 init : function() {
1594                                     XObject.prototype.init.call(this);
1595                                        XObject.prototype.init.call(this); 
1596                                     this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
1597                                     this.el.set_size_request ( 150, -1 );
1598                                     this.shown = true;
1599                                 },
1600                                 activeElement : false,
1601                                 hideWin : function() {
1602                                      
1603                                     if (!this.shown) {
1604                                         return;
1605                                     }
1606                                     
1607                                     
1608                                     if (this.get('/Window.left').el.position < 160) {
1609                                         return;
1610                                     }
1611                                     this.get('/Window.left').el.position = this.get('/Window.left').el.position  - 150;
1612                                         
1613                                     this.el.hide();
1614                                     this.shown = false;
1615                                 },
1616                                 items : [
1617                                     {
1618                                         xtype: Gtk.TreeView,
1619                                         enable_tree_lines : true,
1620                                         headers_visible : false,
1621                                         tooltip_column : 2,
1622                                         init : function() {
1623                                                 XObject.prototype.init.call(this); 
1624                                                             
1625                                                var description = new Pango.FontDescription.c_new();
1626                                              description.set_size(8000);
1627                                             this.el.modify_font(description);     
1628                                                             
1629                                             //this.selection = this.el.get_selection();
1630                                             // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1631                                          
1632                                         
1633                                             
1634                                           
1635                                             
1636                                         },
1637                                         listeners : {
1638                                             
1639                                         },
1640                                         items : [
1641                                             {
1642                                                 xtype: Gtk.ListStore,
1643                                                 pack : "set_model",
1644                                                 init : function() {
1645                                                     XObject.prototype.init.call(this);
1646                                                    this.el.set_column_types ( 6, [
1647                                                         GObject.TYPE_STRING,  // real key
1648                                                          GObject.TYPE_STRING, // real type
1649                                                          GObject.TYPE_STRING, // docs ?
1650                                                          GObject.TYPE_STRING, // visable desc
1651                                                          GObject.TYPE_STRING, // function desc
1652                                                          GObject.TYPE_STRING // element type (event|prop)
1653                                                         
1654                                                     ] );
1655                                                 },
1656                                                 getValue : function(treepath, col)
1657                                                 {
1658                                                     var tp = new Gtk.TreePath.from_string (treepath);
1659                                                     var iter = new Gtk.TreeIter();
1660                                                     this.el.get_iter (iter, tp);
1661                                                     var value = new GObject.Value('');
1662                                                     this.el.get_value(iter, col, value);
1663                                                     return value.value;
1664                                                     
1665                                                 },
1666                                                 showData : function(type) {
1667                                                     this.el.clear();
1668                                                             if (!this.get('/MidPropTree').activeElement || !type) {
1669                                                                 return; // no active element
1670                                                             }
1671                                                 
1672                                                             var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
1673                                                             var palete = this.get('/LeftTree').getPaleteProvider();
1674                                                             
1675                                                              
1676                                                             
1677                                                             Seed.print('Showing right?');
1678                                                             if (!this.get('/MidPropTree').shown) {
1679                                                 
1680                                                                 this.get('/Window.left').el.position = this.get('/Window.left').el.position  + 150;
1681                                                                 this.get('/MidPropTree').el.show();
1682                                                                 this.get('/MidPropTree').shown = true;
1683                                                             }
1684                                                             
1685                                                             var elementList = palete.getPropertiesFor(fullpath, type);
1686                                                             print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
1687                                                            // console.dump(elementList);
1688                                                            
1689                                                             
1690                                                             var iter = new Gtk.TreeIter();
1691                                                             for(var i =0 ; i < elementList.length; i++) {
1692                                                                 var p=elementList[i];
1693                                                                 this.el.append(iter);
1694                                                               //  console.log( '<b>' + p.name +'</b> ['+p.type+']');
1695                                                                     //GObject.TYPE_STRING,  // real key
1696                                                                     // GObject.TYPE_STRING, // real type
1697                                                                     // GObject.TYPE_STRING, // docs ?
1698                                                                     // GObject.TYPE_STRING // func def?
1699                                                                     
1700                                                                 
1701                                                                 this.el.set_value(iter, 0, p.name);
1702                                                                 this.el.set_value(iter, 1, p.type);
1703                                                                 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
1704                                                                 this.el.set_value(iter, 3, p.sig ? p.sig  : '');
1705                                                                 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
1706                                                                 this.el.set_value(iter, 5, type);
1707                                                                 
1708                                                             }
1709                                                                              
1710                                                 },
1711                                                 id : "model"
1712                                             },
1713                                             {
1714                                                 xtype: Gtk.TreeViewColumn,
1715                                                 init : function() {
1716                                                     this.el = new Gtk.TreeViewColumn();
1717                                                     this.parent.el.append_column(this.el);
1718                                                     
1719                                                     XObject.prototype.init.call(this);
1720                                                     this.el.add_attribute(this.items[0].el , 'markup', 4  );
1721                                                 },
1722                                                 pack : false,
1723                                                 items : [
1724                                                     {
1725                                                         xtype: Gtk.CellRendererText,
1726                                                         pack : "pack_start,true"
1727                                                     }
1728                                                 ]
1729                                             }
1730                                         ]
1731                                     }
1732                                 ]
1733                             }
1734                         ]
1735                     },
1736                     {
1737                         xtype: Gtk.HBox,
1738                         pack : "add",
1739                         items : [
1740                             {
1741                                 xtype: Gtk.VPaned,
1742                                 pack : "add",
1743                                 position : 300,
1744                                 items : [
1745                                     {
1746                                         xtype: Gtk.VBox,
1747                                         pack : "add",
1748                                         items : [
1749                                             {
1750                                                 xtype: Gtk.Notebook,
1751                                                 pack : "pack_start,true,true",
1752                                                 id : "view-notebook",
1753                                                 tab_border : 0,
1754                                                 init : function() {
1755                                                     XObject.prototype.init.call(this);
1756                                                     this.el.set_current_page(0);
1757                                                     print("SET LABEL?")
1758                                                     this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
1759                                                     this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
1760                                                 },
1761                                                 show_tabs : false,
1762                                                 items : [
1763                                                     {
1764                                                         xtype: Gtk.VBox,
1765                                                         pack : "add",
1766                                                         id : "RightBrowser",
1767                                                         listeners : {
1768                                                             
1769                                                         },
1770                                                         items : [
1771                                                             {
1772                                                                 xtype: Gtk.HBox,
1773                                                                 pack : "pack_start,false,true,0",
1774                                                                 items : [
1775                                                                     {
1776                                                                         xtype: Gtk.Button,
1777                                                                         pack : "pack_start,false,false,0",
1778                                                                         label : "Dump HTML to console",
1779                                                                         listeners : {
1780                                                                             
1781                                                                         }
1782                                                                     }
1783                                                                 ]
1784                                                             },
1785                                                             {
1786                                                                 xtype: Gtk.ScrolledWindow,
1787                                                                 pack : "add",
1788                                                                 shadow_type : Gtk.ShadowType.IN,
1789                                                                 init : function() {
1790                                                                     XObject.prototype.init.call(this);
1791                                                                   this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1792                                                                 },
1793                                                                 items : [
1794                                                                     {
1795                                                                         xtype: WebKit.WebView,
1796                                                                         pack : "add",
1797                                                                         id : "view",
1798                                                                         init : function() {
1799                                                                             XObject.prototype.init.call(this);
1800                                                                             // this may not work!?
1801                                                                             //this.el.open('file:///' + __script_path__ + '/../builder.html');
1802                                                                                                     
1803                                                                             Gtk.drag_dest_set
1804                                                                             (
1805                                                                                     this.el,              /* widget that will accept a drop */
1806                                                                                     Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
1807                                                                                     null,            /* lists of target to support */
1808                                                                                     0,              /* size of list */
1809                                                                                     Gdk.DragAction.COPY         /* what to do with data after dropped */
1810                                                                             );
1811                                                                                                     
1812                                                                            // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
1813                                                                             Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
1814                                                                         },
1815                                                                         renderJS : function() {
1816                                                                             this.renderedData = data;
1817                                                                             var str = JSON.stringify(data) ;
1818                                                                             
1819                                                                             if (!this.ready) {
1820                                                                                 console.log('not loaded yet');
1821                                                                             }
1822                                                                             Seed.print("RENDER:" + str);
1823                                                                             imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
1824                                                                             this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
1825                                                                         },
1826                                                                         listeners : {
1827                                                                             
1828                                                                         }
1829                                                                     }
1830                                                                 ]
1831                                                             }
1832                                                         ]
1833                                                     },
1834                                                     {
1835                                                         xtype: Gtk.VBox,
1836                                                         pack : "add",
1837                                                         id : "RightGtkView",
1838                                                         buildJS : function(data,withDebug) {
1839                                                             var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 
1840                                                                 'GtkSource', 'WebKit', 'Vte' ];
1841                                                             var src = "";
1842                                                             i.forEach(function(e) {
1843                                                                 src += e+" = imports.gi." + e +";\n";
1844                                                             });
1845                                                             src += "console = imports.console;\n"; // path?!!?
1846                                                             src += "XObject = imports.XObject.XObject;\n"; // path?!!?
1847                                                             if (withDebug) {
1848                                                                 src += "XObject.debug=true;\n"; 
1849                                                             }
1850                                                             this.withDebug = withDebug;
1851                                                             
1852                                                             src += '_top=new XObject('+ this.mungeToString(data) + ')\n;';
1853                                                             src += '_top.init();\n';
1854                                                         
1855                                                             imports.File.File.write('/tmp/BuilderGtkView.js', src);
1856                                                             print("Test code  in /tmp/BuilderGtkView.js");
1857                                                             this.lastSrc = src;
1858                                                             return src;
1859                                                         },
1860                                                         renderJS : function(data, withDebug)
1861                                                         {
1862                                                             // can we mess with data?!?!?
1863                                                             
1864                                                             /**
1865                                                              * first effort..
1866                                                              * sandbox it? - nope then will have dificulting passing. stuff aruond..
1867                                                              * 
1868                                                              */
1869                                                             if (!data) {
1870                                                                  return; 
1871                                                             }
1872                                                             this.withDebug = false;
1873                                                             var src = this.buildJS(data,withDebug);
1874                                                             var x = new imports.sandbox.Context();
1875                                                             x.add_globals();
1876                                                             //x.get_global_object().a = "hello world";
1877                                                             
1878                                                             try {
1879                                                                 Seed.check_syntax('var e = ' + src);
1880                                                                 x.eval(src);
1881                                                             } catch( e) {
1882                                                                // if (!withDebug) {
1883                                                                //    return this.renderJS(data,true);
1884                                                                 //}
1885                                                                 print(e.message || e.toString());
1886                                                                 console.dump(e);
1887                                                                 return;
1888                                                             }
1889                                                             
1890                                                             var r = new Gdk.Rectangle();
1891                                                             var _top = x.get_global_object()._top;
1892                                                             
1893                                                             _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
1894                                                             _top.el.show_all();
1895                                                             if (_top.el.popup) {
1896                                                                 _top.el.popup(null, null, null, null, 3, null);
1897                                                             }
1898                                                             
1899                                                             
1900                                                             
1901                                                             var pb = _top.el.get_snapshot(r);
1902                                                             if (!pb) {
1903                                                                 return;
1904                                                             }
1905                                                             _top.el.hide();
1906                                                             _top.el.destroy();
1907                                                             x._top = false;
1908                                                         
1909                                                             var gc = new Gdk.GC.c_new(this.get('/Window').el.window);
1910                                                                 
1911                                                                 // 10 points all round..
1912                                                             var full = new Gdk.Pixmap.c_new (this.get('/Window').el.window, r.width+20, r.height+20, pb.get_depth());
1913                                                             // draw a white background..
1914                                                            // gc.set_rgb_fg_color({ red: 0, white: 0, black : 0 });
1915                                                             Gdk.draw_rectangle(full, gc, true, 0, 0, r.width+20, r.height+20);
1916                                                             // paint image..
1917                                                             Gdk.draw_drawable (full, gc, pb, 0, 0, 10, 10, r.width, r.height);
1918                                                             // boxes..
1919                                                             //gc.set_rgb_fg_color({ red: 255, white: 255, black : 255 });
1920                                                             Gdk.draw_rectangle(full, gc, true, 0, 0, 10, 10);
1921                                                             this.get('view').el.set_from_pixmap(full, null);
1922                                                             //this.get('view-vbox').el.set_size_request( r.width+20, r.height+20);
1923                                                             //var img = new Gtk.Image.from_file("/home/alan/solarpanels.jpeg");
1924                                                             
1925                                                             
1926                                                             
1927                                                         },
1928                                                         showInWindow : function() {
1929                                                              var src= this.buildJS(
1930                                                                         this.get('/LeftTree.model').toJS()[0], 
1931                                                                         true);
1932                                                               // show term?? 
1933                                                         
1934                                                         
1935                                                             //var x = new imports.sandbox.Context();
1936                                                             //x.add_globals();
1937                                                             //print(src);
1938                                                             try {
1939                                                                 Seed.check_syntax('var e = ' + src);
1940                                                                 //x.eval(src);
1941                                                             } catch( e) {
1942                                                                 this.get('/Terminal').feed(e.message || e.toString() + "\n");
1943                                                                 this.get('/Terminal').feed(console._dump(e)+"\n");
1944                                                                 if (e.line) {
1945                                                                     var lines = src.split("\n");
1946                                                                     var start = Math.max(0, e.line - 10);
1947                                                                     var end = Math.min(lines.length, e.line + 10);
1948                                                                     for (var i =start ; i < end; i++) {
1949                                                                         if (i == e.line) {
1950                                                                             this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
1951                                                                             continue;
1952                                                                         }
1953                                                                         this.get('/Terminal').feed(lines[i] + "\n");
1954                                                                     }
1955                                                                     
1956                                                                 }
1957                                                                 
1958                                                                 return;
1959                                                             }
1960                                                              this.get('/BottomPane').el.set_current_page(1);
1961                                                             this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false); 
1962                                                             var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
1963                                                             this.get('/Terminal').el.feed_child(cmd, cmd.length);
1964                                                              /*
1965                                                             var _top = x.get_global_object()._top;
1966                                                             
1967                                                             _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
1968                                                             _top.el.show_all();
1969                                                             if (_top.el.popup) {
1970                                                                 _top.el.popup(null, null, null, null, 3, null);
1971                                                             }
1972                                                         */
1973                                                         },
1974                                                         mungeToString : function(obj, isListener, pad)
1975                                                                 {
1976                                                                     pad = pad || '';
1977                                                                     var keys = [];
1978                                                                     var isArray = false;
1979                                                                     isListener = isListener || false;
1980                                                                     
1981                                                                     // am I munging a object or array...
1982                                                                     if (obj.constructor.toString() === Array.toString()) {
1983                                                                         for (var i= 0; i < obj.length; i++) {
1984                                                                             keys.push(i);
1985                                                                         }
1986                                                                         isArray = true;
1987                                                                     } else {
1988                                                                         for (var i in obj) {
1989                                                                             keys.push(i);
1990                                                                         }
1991                                                                     }
1992                                                                     
1993                                                                     
1994                                                                     var els = []; 
1995                                                                     var skip = [];
1996                                                                     if (!isArray && 
1997                                                                             typeof(obj['|xns']) != 'undefined' &&
1998                                                                             typeof(obj['xtype']) != 'undefined'
1999                                                                         ) {
2000                                                                             els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
2001                                                                             skip.push('|xns','xtype');
2002                                                                         }
2003                                                                     
2004                                                                     var _this = this;
2005                                                                     
2006                                                                     
2007                                                                     
2008                                                                     keys.forEach(function(i) {
2009                                                                         var el = obj[i];
2010                                                                         if (!isArray && skip.indexOf(i) > -1) {
2011                                                                             return;
2012                                                                         }
2013                                                                         if (isListener) {
2014                                                                                 if (!_this.withDebug) {
2015                                                                                 // do not write listeners unless we are debug mode.
2016                                                                                     return;
2017                                                                                  }
2018                                                                             //if (obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
2019                                                                             //    return;
2020                                                                            // }
2021                                                                             var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");
2022                                                                             var lines = str.split("\n");
2023                                                                             if (lines.length > 1) {
2024                                                                                 str = lines.join("\n" + pad);
2025                                                                             }
2026                                                                             els.push(JSON.stringify(i) + ":" + str);
2027                                                                             return;
2028                                                                         }
2029                                                                         if (i[0] == '|') {
2030                                                                             // does not hapepnd with arrays..
2031                                                                             if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
2032                                                                                 return;
2033                                                                             }
2034                                                                             // this needs to go...
2035                                                                            // if (typeof(el) == 'string'  && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
2036                                                                             //    return;
2037                                                                             //}
2038                                                                             
2039                                                                             var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
2040                                                                             var lines = str.split("\n");
2041                                                                             if (lines.length > 1) {
2042                                                                                 str = lines.join("\n" + pad);
2043                                                                             }
2044                                                                             
2045                                                                             els.push(JSON.stringify(i.substring(1)) + ":" + str);
2046                                                                             return;
2047                                                                         }
2048                                                                         var left = isArray ? '' : (JSON.stringify(i) + " : " )
2049                                                                         if (typeof(el) == 'object') {
2050                                                                             els.push(left + _this.mungeToString(el, i == 'listeners', pad + '    '));
2051                                                                             return;
2052                                                                         }
2053                                                                         els.push(JSON.stringify(i) + ":" + JSON.stringify(obj[i]));
2054                                                                     });
2055                                                                     var spad = pad.substring(0, pad.length-4);
2056                                                                     return (isArray ? '[' : '{') + "\n" +
2057                                                                         pad  + els.join(",\n" + pad ) + 
2058                                                                         "\n" + spad + (isArray ? ']' : '}');
2059                                                                        
2060                                                                     
2061                                                                     
2062                                                                 },
2063                                                         items : [
2064                                                             {
2065                                                                 xtype: Gtk.HBox,
2066                                                                 pack : "pack_start,false,true,0",
2067                                                                 items : [
2068                                                                     {
2069                                                                         xtype: Gtk.Button,
2070                                                                         pack : "pack_start,false,false,0",
2071                                                                         label : "Run The Application",
2072                                                                         listeners : {
2073                                                                             
2074                                                                         }
2075                                                                     }
2076                                                                 ]
2077                                                             },
2078                                                             {
2079                                                                 xtype: Gtk.ScrolledWindow,
2080                                                                 pack : "add",
2081                                                                 id : "view-sw",
2082                                                                 shadow_type : Gtk.ShadowType.IN,
2083                                                                 init : function() {
2084                                                                     XObject.prototype.init.call(this);
2085                                                                  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2086                                                                 },
2087                                                                 items : [
2088                                                                     {
2089                                                                         xtype: Gtk.Viewport,
2090                                                                         pack : "add",
2091                                                                         init : function() {
2092                                                                                 XObject.prototype.init.call(this);
2093                                                                                 this.el.set_hadjustment(this.parent.el.get_hadjustment());
2094                                                                                 this.el.set_vadjustment(this.parent.el.get_vadjustment());
2095                                                                         },
2096                                                                         items : [
2097                                                                             {
2098                                                                                 xtype: Gtk.Image,
2099                                                                                 pack : "add",
2100                                                                                 init : function() {
2101                                                                                         this.el =     new Gtk.Image.from_stock (Gtk.STOCK_HOME,  Gtk.IconSize.MENU);
2102                                                                                         XObject.prototype.init.call(this);
2103                                                                                 
2104                                                                                             Gtk.drag_dest_set
2105                                                                                             (
2106                                                                                                     this.el,              /* widget that will accept a drop */
2107                                                                                                     Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
2108                                                                                                     null,            /* lists of target to support */
2109                                                                                                     0,              /* size of list */
2110                                                                                                     Gdk.DragAction.COPY         /* what to do with data after dropped */
2111                                                                                             );
2112                                                                                             
2113                                                                                            // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2114                                                                                             Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2115                                                                                 },
2116                                                                                 ready : false,
2117                                                                                 getActiveNode : function(x,y)
2118                                                                                 {
2119                                                                                    // workout what node is here..
2120                                                                                     return '0'; // top..
2121                                                                                 },
2122                                                                                 id : "view",
2123                                                                                 listeners : {
2124                                                                                     
2125                                                                                 }
2126                                                                             }
2127                                                                         ]
2128                                                                     }
2129                                                                 ]
2130                                                             }
2131                                                         ]
2132                                                     }
2133                                                 ]
2134                                             }
2135                                         ]
2136                                     },
2137                                     {
2138                                         xtype: Gtk.Notebook,
2139                                         pack : "add",
2140                                         init : function() {
2141                                             XObject.prototype.init.call(this);
2142                                                 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
2143                                                 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
2144                                         },
2145                                         id : "BottomPane",
2146                                         items : [
2147                                             {
2148                                                 xtype: Gtk.ScrolledWindow,
2149                                                 pack : "add",
2150                                                 id : "RightEditor",
2151                                                 items : [
2152                                                     {
2153                                                         xtype: GtkSource.View,
2154                                                         pack : "add",
2155                                                         id : "view",
2156                                                         init : function() {
2157                                                             XObject.prototype.init.call(this);
2158                                                              var description = Pango.Font.description_from_string("monospace")
2159                                                             description.set_size(8000);
2160                                                             this.el.modify_font(description);
2161                                                         
2162                                                         },
2163                                                         load : function(str) {
2164                                                            this.get('/BottomPane').el.set_current_page(0);
2165                                                             this.el.get_buffer().set_text(str, str.length);
2166                                                             var lm = GtkSource.LanguageManager.get_default();
2167                                                             
2168                                                             this.el.get_buffer().set_language(lm.get_language('js'));
2169                                                             var buf = this.el.get_buffer();
2170                                                             var cursor = buf.get_mark("insert");
2171                                                             var iter= new Gtk.TextIter;
2172                                                             buf.get_iter_at_mark(iter, cursor);
2173                                                             iter.set_line(1);
2174                                                             iter.set_line_offset(4);
2175                                                             buf.move_mark(cursor, iter);
2176                                                             
2177                                                             
2178                                                             cursor = buf.get_mark("selection_bound");
2179                                                             iter= new Gtk.TextIter;
2180                                                             buf.get_iter_at_mark(iter, cursor);
2181                                                             iter.set_line(1);
2182                                                             iter.set_line_offset(4);
2183                                                             buf.move_mark(cursor, iter);
2184                                                              
2185                                                             this.el.grab_focus();
2186                                                         },
2187                                                         items : [
2188                                                             {
2189                                                                 xtype: GtkSource.Buffer,
2190                                                                 pack : "set_buffer",
2191                                                                 listeners : {
2192                                                                     
2193                                                                 }
2194                                                             }
2195                                                         ]
2196                                                     }
2197                                                 ]
2198                                             },
2199                                             {
2200                                                 xtype: Gtk.ScrolledWindow,
2201                                                 pack : "add",
2202                                                 items : [
2203                                                     {
2204                                                         xtype: Vte.Terminal,
2205                                                         pack : "add",
2206                                                         id : "Terminal",
2207                                                         feed : function(str) {
2208                                                             this.el.feed(str,str.length);
2209                                                         }
2210                                                     }
2211                                                 ]
2212                                             }
2213                                         ]
2214                                     }
2215                                 ]
2216                             },
2217                             {
2218                                 xtype: Gtk.VBox,
2219                                 pack : "pack_start,false,false",
2220                                 id : "RightPalete",
2221                                 hide : function() {
2222                                     
2223                                       this.get('buttonbar').el.show();
2224                                        this.get('viewbox').el.hide();
2225                                     print("TRIED TO HIDE");
2226                                 },
2227                                 show : function() {
2228                                     this.get('buttonbar').el.hide();
2229                                     this.get('viewbox').el.show();
2230                                    // this.get('model').expanded();
2231                                             
2232                                 },
2233                                 provider : false,
2234                                 items : [
2235                                     {
2236                                         xtype: Gtk.VBox,
2237                                         pack : "add",
2238                                         id : "buttonbar",
2239                                         items : [
2240                                             {
2241                                                 xtype: Gtk.Button,
2242                                                 pack : "pack_start,false,true",
2243                                                 listeners : {
2244                                                     
2245                                                 },
2246                                                 items : [
2247                                                     {
2248                                                         xtype: Gtk.Image,
2249                                                         pack : "add",
2250                                                         stock : Gtk.STOCK_GOTO_FIRST,
2251                                                         icon_size : Gtk.IconSize.MENU
2252                                                     }
2253                                                 ]
2254                                             },
2255                                             {
2256                                                 xtype: Gtk.Label,
2257                                                 pack : "add",
2258                                                 label : "Palete",
2259                                                 angle : 270,
2260                                                 init : function() {
2261                                                     XObject.prototype.init.call(this);
2262                                                     this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
2263                                                 },
2264                                                 listeners : {
2265                                                     
2266                                                 }
2267                                             }
2268                                         ]
2269                                     },
2270                                     {
2271                                         xtype: Gtk.VBox,
2272                                         pack : "add",
2273                                         id : "viewbox",
2274                                         items : [
2275                                             {
2276                                                 xtype: Gtk.HBox,
2277                                                 pack : "pack_start,false,true",
2278                                                 items : [
2279                                                     {
2280                                                         xtype: Gtk.Label,
2281                                                         pack : "add",
2282                                                         label : "Palete"
2283                                                     },
2284                                                     {
2285                                                         xtype: Gtk.Button,
2286                                                         pack : "pack_start,false,true",
2287                                                         listeners : {
2288                                                             
2289                                                         },
2290                                                         items : [
2291                                                             {
2292                                                                 xtype: Gtk.Image,
2293                                                                 pack : "add",
2294                                                                 stock : Gtk.STOCK_GOTO_LAST,
2295                                                                 icon_size : Gtk.IconSize.MENU
2296                                                             }
2297                                                         ]
2298                                                     }
2299                                                 ]
2300                                             },
2301                                             {
2302                                                 xtype: Gtk.ScrolledWindow,
2303                                                 pack : "add",
2304                                                 init : function() {
2305                                                     XObject.prototype.init.call(this);
2306                                                         this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2307                                                     this.el.set_size_request(-1,200);
2308                                                 },
2309                                                 shadow_type : Gtk.ShadowType.IN,
2310                                                 items : [
2311                                                     {
2312                                                         xtype: Gtk.TreeView,
2313                                                         pack : "add",
2314                                                         init : function() {
2315                                                             XObject.prototype.init.call(this);
2316                                                           this.el.set_size_request(150,-1);
2317                                                                                   //  set_reorderable: [1]
2318                                                                                           
2319                                                                     var description = new Pango.FontDescription.c_new();
2320                                                             description.set_size(8000);
2321                                                             this.el.modify_font(description);
2322                                                             
2323                                                             this.selection = this.el.get_selection();
2324                                                             this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2325                                                            // this.selection.signal['changed'].connect(function() {
2326                                                             //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
2327                                                             //});
2328                                                             // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
2329                                                              
2330                                                             Gtk.drag_source_set (
2331                                                                     this.el,            /* widget will be drag-able */
2332                                                                     Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
2333                                                                     null,            /* lists of target to support */
2334                                                                     0,              /* size of list */
2335                                                                     Gdk.DragAction.COPY         /* what to do with data after dropped */
2336                                                             );
2337                                                             //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
2338                                                            
2339                                                             Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
2340                                                             Gtk.drag_source_add_text_targets(this.el); 
2341                                                             /*
2342                                                             print("RP: TARGET:" + LeftTree.atoms["STRING"]);
2343                                                             targets = new Gtk.TargetList();
2344                                                             targets.add( LeftTree.atoms["STRING"], 0, 0);
2345                                                             targets.add_text_targets( 1 );
2346                                                             Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
2347                                                             
2348                                                             //if you want to allow text to be output elsewhere..
2349                                                             //Gtk.drag_source_add_text_targets(this.el);
2350                                                             */
2351                                                             return true; 
2352                                                         },
2353                                                         listeners : {
2354                                                             
2355                                                         },
2356                                                         items : [
2357                                                             {
2358                                                                 xtype: Gtk.ListStore,
2359                                                                 pack : "set_model",
2360                                                                 init : function() {
2361                                                                     XObject.prototype.init.call(this);
2362                                                                 this.el.set_column_types ( 2, [
2363                                                                                             GObject.TYPE_STRING, // title 
2364                                                                                             GObject.TYPE_STRING // tip
2365                                                                                             
2366                                                                                             ] );
2367                                                                 },
2368                                                                 id : "model",
2369                                                                 load : function(tr,iter)
2370                                                                 {
2371                                                                     if (!iter) {
2372                                                                         this.el.clear();
2373                                                                     }
2374                                                                     //console.log('Project tree load: ' + tr.length);
2375                                                                     var citer = new Gtk.TreeIter();
2376                                                                     //this.insert(citer,iter,0);
2377                                                                     for(var i =0 ; i < tr.length; i++) {
2378                                                                         if (!iter) {
2379                                                                             
2380                                                                             this.el.append(citer);   
2381                                                                         } else {
2382                                                                             this.el.insert(citer,iter,-1);
2383                                                                         }
2384                                                                         
2385                                                                         var r = tr[i];
2386                                                                         //Seed.print(r);
2387                                                                         this.el.set_value(citer, 0,  '' +  r ); // title 
2388                                                                         
2389                                                                         //this.el.set_value(citer, 1,  new GObject.Value( r)); //id
2390                                                                         //if (r.cn && r.cn.length) {
2391                                                                         //    this.load(r.cn, citer);
2392                                                                         //}
2393                                                                     }
2394                                                                     
2395                                                                     
2396                                                                 },
2397                                                                 getValue : function (iter, col) {
2398                                                                     var gval = new GObject.Value('');
2399                                                                      this.el.get_value(iter, col ,gval);
2400                                                                     return  gval.value;
2401                                                                     
2402                                                                     
2403                                                                 }
2404                                                             },
2405                                                             {
2406                                                                 xtype: Gtk.TreeViewColumn,
2407                                                                 pack : "append_column",
2408                                                                 init : function() {
2409                                                                     XObject.prototype.init.call(this);
2410                                                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
2411                                                                 },
2412                                                                 items : [
2413                                                                     {
2414                                                                         xtype: Gtk.CellRendererText,
2415                                                                         pack : "pack_start"
2416                                                                     }
2417                                                                 ]
2418                                                             }
2419                                                         ]
2420                                                     }
2421                                                 ]
2422                                             }
2423                                         ]
2424                                     }
2425                                 ]
2426                             }
2427                         ]
2428                     }
2429                 ]
2430             }
2431         ]
2432     }
2433 ]
2434 })
2435 ;builder.bjs.init();