Sample/Window.js
[app.Builder.js] / Sample / Window.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 Window=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         "delete_event":function (self, event) {
40             return false;
41         },
42         "destroy":function (self) {
43            Gtk.main_quit();
44         },
45         "show":function (self) {
46           print("WINDOW SHOWING - trying to hide");
47         imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
48                 this.get('/MidPropTree').hideWin();
49             this.get('/RightPalete').hide();
50         
51         }
52     },
53     items : [
54         {
55             xtype: Gtk.VBox,
56             id : "w-vbox",
57             items : [
58                 {
59                     xtype: Gtk.MenuBar,
60                     pack : "pack_start,false,false",
61                     items : [
62                         {
63                             xtype: Gtk.MenuItem,
64                             label : "File",
65                             items : [
66                                 {
67                                     xtype: Gtk.Menu,
68                                     pack : "set_submenu",
69                                     items : [
70                                         {
71                                             xtype: Gtk.MenuItem,
72                                             label : "New Project",
73                                             listeners : {
74                                                 "activate":function (self) {
75                                                         this.get('/EditProject').show({
76                                                             success : function(pr) {
77                                                                      this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
78                                                             }
79                                                         });
80                                                 }
81                                             }
82                                         },
83                                         {
84                                             xtype: Gtk.MenuItem,
85                                             label : "New File",
86                                             listeners : {
87                                                 "activate":function (self) {
88                                                         var fn = this.get('/LeftProjectTree.combo').getValue();
89                                                         if (!fn) {
90                                                             this.get('/LeftProjectTree').showNoProjectSelected();
91                                                             return true;
92                                                         }
93                                                         var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
94                                                         this.get('/DialogNewComponent').show({
95                                                             project : pm.getByFn(fn)
96                                                         });
97                                                 }
98                                             }
99                                         },
100                                         {
101                                             xtype: Gtk.SeparatorMenuItem,
102                                             pack : "add"
103                                         },
104                                         {
105                                             xtype: Gtk.MenuItem,
106                                             label : "Add Directory to Project",
107                                             pack : "add",
108                                             listeners : {
109                                                 "activate":function (self) {
110                                                         var fn = this.get('/LeftProjectTree').get('combo').getValue();
111                                                         if (!fn) {
112                                                             this.get('/LeftProjectTree').showNoProjectSelected();
113                                                             return true;
114                                                         }
115                                                         
116                                                         
117                                                         var dc = new Gtk.FileChooserDialog({
118                                                             action : Gtk.FileChooserAction.SELECT_FOLDER,
119                                                             modal: true,
120                                                             'select-multiple' : false,
121                                                             "show-hidden" : true,
122                                                         });
123                                                         dc.add_button("Add To Project", Gtk.ResponseType.ACCEPT );
124                                                         dc.add_button("Cancel",Gtk.ResponseType.CANCEL);
125                                                         
126                                                         if (dc.run() != Gtk.ResponseType.ACCEPT) {
127                                                             
128                                                             dc.destroy();
129                                                             return;
130                                                         }
131                                                             
132                                                         //Seed.print(dc.get_filename());
133                                                         var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
134                                                         pm.getByFn(fn).add(dc.get_filename(), 'dir');
135                                                         dc.destroy();
136                                                 }
137                                             }
138                                         },
139                                         {
140                                             xtype: Gtk.SeparatorMenuItem,
141                                             pack : "add"
142                                         },
143                                         {
144                                             xtype: Gtk.MenuItem,
145                                             label : "Quit",
146                                             pack : "add",
147                                             listeners : {
148                                                 "activate":function (self) {
149                                                         Gtk.main_quit();
150                                                 }
151                                             }
152                                         }
153                                     ]
154                                 }
155                             ]
156                         },
157                         {
158                             xtype: Gtk.MenuItem,
159                             label : "Help"
160                         }
161                     ]
162                 },
163                 {
164                     xtype: Gtk.HPaned,
165                     id : "left",
166                     position : 400,
167                     items : [
168                         {
169                             xtype: Gtk.HBox,
170                             items : [
171                                 {
172                                     xtype: Gtk.VPaned,
173                                     position : 300,
174                                     id : "leftvpaned",
175                                     items : [
176                                         {
177                                             xtype: Gtk.VBox,
178                                             id : "LeftTopPanel",
179                                             items : [
180                                                 {
181                                                     xtype: Gtk.Expander,
182                                                     label : "Select Project",
183                                                     id : "expander",
184                                                     pack : "pack_start,false,true",
185                                                     init : function() {
186                                                         XObject.prototype.init.call(this);
187                                                        this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
188                                                     },
189                                                     listeners : {
190                                                         "activate":function (self) {
191                                                                 var nb = this.get('/LeftTopPanel.notebook');
192                                                                 if (this.el.expanded) {
193                                                                     // now expanded..
194                                                                     
195                                                                     var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
196                                                                     
197                                                                    
198                                                                     var model = this.get('/LeftProjectTree.combomodel');
199                                                                   //  print ("loading Projects?")
200                                                                 //console.dump(pm.projects);
201                                                                     model.loadData(pm.projects);
202                                                                      
203                                                                     
204                                                                     nb.el.set_current_page(1);
205                                                                     //pm.on('changed', function() {
206                                                                         //console.log("CAUGHT project manager change");
207                                                                     //    _combo.model.loadData(pm.projects);
208                                                                     //}
209                                                                     return;
210                                                                 }
211                                                                 nb.el.set_current_page(0);
212                                                         },
213                                                         "enter_notify_event":function (self, event) {
214                                                              this.el.expanded = !this.el.expanded;
215                                                         //if (this.el.expanded ) {
216                                                             this.listeners.activate.call(this);
217                                                         //   }
218                                                         
219                                                         return true;
220                                                         }
221                                                     }
222                                                 },
223                                                 {
224                                                     xtype: Gtk.Notebook,
225                                                     id : "notebook",
226                                                     show_border : false,
227                                                     show_tabs : false,
228                                                     pack : "pack_start,true,true",
229                                                     init : function() {
230                                                         XObject.prototype.init.call(this);
231                                                         this.el.set_current_page(0);
232                                                     
233                                                     },
234                                                     items : [
235                                                         {
236                                                             xtype: Gtk.ScrolledWindow,
237                                                             pack : "add",
238                                                             shadow_type : Gtk.ShadowType.IN,
239                                                             init : function() {
240                                                                 XObject.prototype.init.call(this);
241                                                                 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
242                                                             },
243                                                             id : "LeftTree",
244                                                             getPaleteProvider : function() {
245                                                                 var model = this.get('model');
246                                                                 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
247                                                                 return pm.getPalete(model.file.getType());
248                                                             },
249                                                             renderView : function() {
250                                                                  var model = this.get('model');
251                                                                 print("RENDER VIEW?" + model.file.getType());
252                                                                 switch( model.file.getType()) {
253                                                                         case 'Roo':
254                                                                             this.get('/RightBrowser.view').renderJS(model.toJS(false,true)[0]);
255                                                                         case 'Gtk':
256                                                                             this.get('/RightGtkView').renderJS(model.toJS(false,true)[0]);
257                                                                 }
258                                                             },
259                                                             items : [
260                                                                 {
261                                                                     xtype: Gtk.TreeView,
262                                                                     pack : "add",
263                                                                     id : "view",
264                                                                     headers_visible : false,
265                                                                     enable_tree_lines : true,
266                                                                     tooltip_column : 0,
267                                                                     init : function() {
268                                                                                 XObject.prototype.init.call(this);
269                                                                         var description = new Pango.FontDescription.c_new();
270                                                                         description.set_size(8000);
271                                                                         this.el.modify_font(description);
272                                                                     
273                                                                         this.selection = this.el.get_selection();
274                                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
275                                                                         var _this = this;
276                                                                         this.selection.signal['changed'].connect(function() {
277                                                                                 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
278                                                                                     _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
279                                                                                 );
280                                                                         });
281                                                                     
282                                                                         Gtk.drag_source_set (
283                                                                                 this.el,            /* widget will be drag-able */
284                                                                                 Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
285                                                                                 null,            /* lists of target to support */
286                                                                                 0,              /* size of list */
287                                                                                 Gdk.DragAction.COPY   | Gdk.DragAction.MOVE           /* what to do with data after dropped */
288                                                                         );
289                                                                     
290                                                                         Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
291                                                                     
292                                                                         Gtk.drag_source_add_text_targets(this.el); 
293                                                                         Gtk.drag_dest_set
294                                                                         (
295                                                                             this.el,              /* widget that will accept a drop */
296                                                                             Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
297                                                                             null,            /* lists of target to support */
298                                                                             0,              /* size of list */
299                                                                             Gdk.DragAction.COPY   | Gdk.DragAction.MOVE       /* what to do with data after dropped */
300                                                                         );
301                                                                     
302                                                                         Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
303                                                                         Gtk.drag_dest_add_text_targets(this.el);
304                                                                     },
305                                                                     highlight : function(treepath_ar) {
306                                                                                         if (treepath_ar.length && treepath_ar[0].length ) {
307                                                                                     this.el.set_drag_dest_row( 
308                                                                                         new  Gtk.TreePath.from_string( treepath_ar[0] ),  treepath_ar[1]);
309                                                                                 } else {
310                                                                                     this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
311                                                                                 }
312                                                                                  
313                                                                             },
314                                                                     selectNode : function(treepath_str) {
315                                                                         //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));
316                                                                      var tp = new Gtk.TreePath.from_string(treepath_str);
317                                                                               this.el.set_cursor(tp, null, false);  
318                                                                           this.el.scroll_to_cell(tp, null, false, 0,0);
319                                                                     },
320                                                                     listeners : {
321                                                                         "button_press_event":function (self, ev) {
322                                                                                 console.log("button press?");
323                                                                                         if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button.button != 3) {
324                                                                                             print("click" + ev.type);
325                                                                                             return false;
326                                                                                         }
327                                                                                       
328                                                                                     
329                                                                                         var res = {}; 
330                                                                                         this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
331                                                                                         
332                                                                                         if (!this.get('/LeftTreeMenu').el)  this.get('/LeftTreeMenu').init();
333                                                                                         
334                                                                                         this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
335                                                                                         this.get('/LeftTreeMenu').el.show_all();
336                                                                                         this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
337                                                                                         print("click:" + res.path.to_string());
338                                                                                         return false;
339                                                                         },
340                                                                         "drag_begin":function (self, drag_context) {
341                                                                                 print('SOURCE: drag-begin');
342                                                                                  this.targetData = false;
343                                                                                 // find what is selected in our tree...
344                                                                                 var iter = new Gtk.TreeIter();
345                                                                                 var s = this.selection;
346                                                                                 s.get_selected(this.get('/LeftTree.model').el, iter);
347                                                                         
348                                                                                 // set some properties of the tree for use by the dropped element.
349                                                                                 var value = new GObject.Value('');
350                                                                                 this.get('/LeftTree.model').el.get_value(iter, 2, value);
351                                                                                 var data = JSON.parse(value.value);
352                                                                                 var xname = this.get('/LeftTree.model').file.guessName(data);
353                                                                                 
354                                                                                 this.el.dragData = xname;
355                                                                                 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
356                                                                                 
357                                                                         
358                                                                                 // make the drag icon a picture of the node that was selected
359                                                                                 var path = this.get('/LeftTree.model').el.get_path(iter);
360                                                                                 this.el.treepath = path.to_string();
361                                                                                 
362                                                                                 var pix = this.el.create_row_drag_icon ( path);
363                                                                                 
364                                                                                 Gtk.drag_set_icon_pixmap (ctx,
365                                                                                     pix.get_colormap(),
366                                                                                     pix,
367                                                                                     null,
368                                                                                     -10,
369                                                                                     -10);
370                                                                                 
371                                                                                 return true;
372                                                                         },
373                                                                         "drag_end":function (self, drag_context) {
374                                                                                 Seed.print('LEFT-TREE: drag-end');
375                                                                                 this.el.dragData = false;
376                                                                                 this.el.dropList = false;
377                                                                                 this.targetData = false;
378                                                                                 this.get('/LeftTree.view').highlight(false);
379                                                                                 return true;
380                                                                         },
381                                                                         "drag_motion":function (self, ctx, x, y, time) {
382                                                                             console.log("LEFT-TREE: drag-motion");
383                                                                                         var src = Gtk.drag_get_source_widget(ctx);
384                                                                         
385                                                                                         // a drag from  elsewhere...- prevent drop..
386                                                                                         if (!src.dragData) {
387                                                                                             print("no drag data!");
388                                                                                             Gdk.drag_status(ctx, 0, time);
389                                                                                             this.targetData = false;
390                                                                                             return true;
391                                                                                         }
392                                                                                         var action = Gdk.DragAction.COPY;
393                                                                                         if (src == this.el) {
394                                                                                             // unless we are copying!!! ctl button..
395                                                                                             action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
396                                                                                         }
397                                                                                         var data = {};
398                                                                         
399                                                                                         if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
400                                                                                                 // no children.. -- asume it's ok..
401                                                                                                 this.targetData =  [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
402                                                                                                 Gdk.drag_status(ctx, action ,time);
403                                                                                                 return true;
404                                                                                         }
405                                                                         
406                                                                                         print("GETTING POS");
407                                                                                         var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
408                                                                                         print("ISOVER? " + isOver);
409                                                                                         if (!isOver) {
410                                                                                             Gdk.drag_status(ctx, 0 ,time);
411                                                                                             return false; // not over apoint!?!
412                                                                                         }
413                                                                                         // drag node is parent of child..
414                                                                                         console.log("SRC TREEPATH: " + src.treepath);
415                                                                                         console.log("TARGET TREEPATH: " + data.path.to_string());
416                                                                                         
417                                                                                         // nned to check a  few here..
418                                                                                         //Gtk.TreeViewDropPosition.INTO_OR_AFTER
419                                                                                         //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
420                                                                                         //Gtk.TreeViewDropPosition.AFTER
421                                                                                         //Gtk.TreeViewDropPosition.BEFORE
422                                                                                         
423                                                                                         if (typeof(src.treepath) != 'undefined'  && 
424                                                                                             src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
425                                                                                             print("subpath drag");
426                                                                                              Gdk.drag_status(ctx, 0 ,time);
427                                                                                             return false;
428                                                                                         }
429                                                                                         
430                                                                                         // check that 
431                                                                                         //print("DUMPING DATA");
432                                                                                         //console.dump(data);
433                                                                                         // path, pos
434                                                                                         
435                                                                                         print(data.path.to_string() +' => '+  data.pos);
436                                                                                         var tg = this.get('/LeftTree.model').findDropNodeByPath(
437                                                                                             data.path.to_string(), src.dropList, data.pos);
438                                                                                             
439                                                                                         this.get('/LeftTree.view').highlight(tg);
440                                                                                         if (!tg.length) {
441                                                                                             print("Can not find drop node path");
442                                                                                             this.targetData = false;
443                                                                                             Gdk.drag_status(ctx, 0, time);
444                                                                                             return true;
445                                                                                         }
446                                                                                         //console.dump(tg);
447                                                                                         this.targetData = tg;    
448                                                                                         
449                                                                                         
450                                                                                         Gdk.drag_status(ctx, action ,time);
451                                                                                          
452                                                                                         return true;
453                                                                         },
454                                                                         "drag_drop":function (w, ctx, x, y, time) {
455                                                                               Seed.print("TARGET: drag-drop");
456                                                                                                
457                                                                                                 Gtk.drag_get_data
458                                                                                                 (
459                                                                                                         w,         /* will receive 'drag-data-received' signal */
460                                                                                                         ctx,        /* represents the current state of the DnD */
461                                                                                                         this.get('/Window').atoms["STRING"],    /* the target type we want */
462                                                                                                         time            /* time stamp */
463                                                                                                 );
464                                                                                                 
465                                                                                                  
466                                                                                                 /* No target offered by source => error */
467                                                                                                
468                                                                         
469                                                                                                 return  true;
470                                                                         },
471                                                                         "drag_data_received":function (self, ctx, x, y, sel_data, info, time) {
472                                                                                  print("Tree: drag-data-received");
473                                                                         
474                                                                                       var   delete_selection_data = false;
475                                                                                        var  dnd_success = false;
476                                                                                         /* Deal with what we are given from source */
477                                                                                         if( sel_data && sel_data.length ) {
478                                                                                             
479                                                                                             if (ctx.action == Gdk.DragAction.ASK)  {
480                                                                                                 /* Ask the user to move or copy, then set the ctx action. */
481                                                                                             }
482                                                                         
483                                                                                             if (ctx.action == Gdk.DragAction.MOVE) {
484                                                                                                 //delete_selection_data = true;
485                                                                                             }
486                                                                                             
487                                                                                             var source = Gtk.drag_get_source_widget(ctx);
488                                                                         
489                                                                                             if (this.targetData) {
490                                                                                                 if (source != this.el) {
491                                                                                                     this.get('/LeftTree.model').dropNode(this.targetData,  source.dragData);
492                                                                                                 } else {
493                                                                                                     // drag around.. - reorder..
494                                                                                                      this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
495                                                                                                     
496                                                                                                     
497                                                                                                 }
498                                                                                                 //Seed.print(this.targetData);
499                                                                                               
500                                                                                             }
501                                                                                             
502                                                                                             
503                                                                                             
504                                                                                             // we can send stuff to souce here...
505                                                                         
506                                                                                             dnd_success = true;
507                                                                         
508                                                                                         }
509                                                                         
510                                                                                         if (dnd_success == false)
511                                                                                         {
512                                                                                                 Seed.print ("DnD data transfer failed!\n");
513                                                                                         }
514                                                                         
515                                                                                         Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
516                                                                                         return true;
517                                                                         },
518                                                                         "cursor_changed":function (self) {
519                                                                          var iter = new Gtk.TreeIter();
520                                                                                         
521                                                                                         if (this.selection.count_selected_rows() < 1) {
522                                                                                             this.get('/LeftPanel.model').load( false);
523                                                                                             this.get('/MidPropTree').activeElement =  false;
524                                                                                             this.get('/MidPropTree').hideWin();
525                                                                         
526                                                                                             var pm = this.get('/RightPalete.model');
527                                                                                             if (!this.get('/LeftTree').getPaleteProvider()) {
528                                                                                                 // it may not be loaded yet..
529                                                                                                 return  true;
530                                                                                             }
531                                                                                             pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
532                                                                                                 this.get('/LeftTree.model').listAllTypes()));
533                                                                                            
534                                                                                             return true;
535                                                                                         }
536                                                                                         
537                                                                                         //console.log('changed');
538                                                                                         var s = this.selection;
539                                                                                         s.get_selected(this.get('/LeftTree.model').el, iter);
540                                                                                         
541                                                                                         
542                                                                                         // var val = "";
543                                                                                         value = new GObject.Value('');
544                                                                                         this.get('/LeftTree.model').el.get_value(iter, 2, value);
545                                                                                         this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
546                                                                                         
547                                                                                         var data = JSON.parse(value.value);
548                                                                                         this.get('/MidPropTree').activeElement =  data;
549                                                                                         this.get('/MidPropTree').hideWin();
550                                                                                         this.get('/LeftPanel.model').load( data);
551                                                                                         
552                                                                                         console.log(value.value);
553                                                                                        // _g.button.set_label(''+value.get_string());
554                                                                         
555                                                                                         var pm =this.get('/RightPalete.model');
556                                                                                         pm.load( this.get('/RightPalete').provider.gatherList(
557                                                                                              this.get('/LeftTree.model').listAllTypes()));
558                                                                                        
559                                                                                         
560                                                                                        
561                                                                                        
562                                                                                         //Seed.print( value.get_string());
563                                                                                         return true;
564                                                                                         
565                                                                         }
566                                                                     },
567                                                                     items : [
568                                                                         {
569                                                                             xtype: Gtk.TreeStore,
570                                                                             pack : "set_model",
571                                                                             id : "model",
572                                                                             init : function() {
573                                                                                 XObject.prototype.init.call(this);
574                                                                              this.el.set_column_types ( 3, [
575                                                                                         GObject.TYPE_STRING, // title 
576                                                                                         GObject.TYPE_STRING, // tip
577                                                                                         GObject.TYPE_STRING // source..
578                                                                                         ] );
579                                                                             },
580                                                                             activePath : false,
581                                                                             changed : function(n, refresh) {
582                                                                                      print("MODEL CHANGED CALLED" + this.activePath);
583                                                                                      if (this.activePath) {
584                                                                                             var iter = new Gtk.TreeIter();
585                                                                                             this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
586                                                                                             this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
587                                                                                             this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
588                                                                                             
589                                                                                             this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
590                                                                                         }
591                                                                                             //this.currentTree = this.toJS(false, true)[0];
592                                                                                         this.file.items = this.toJS(false, false);
593                                                                                         print("AFTER CHANGED");
594                                                                                         //console.dump(this.file.items);
595                                                                                         this.file.save();
596                                                                                         this.currentTree = this.file.items[0];
597                                                                                         //console.log(this.file.toSource());
598                                                                                         
599                                                                                         if (refresh) {
600                                                                                             print("REDNER BROWSER?!");
601                                                                                             this.get('/LeftTree').renderView();
602                                                                             
603                                                                                             var pm = this.get('/RightPalete.model');
604                                                                                             if (!this.get('/RightPalete').provider) {
605                                                                                                 pm.load([]);
606                                                                                                 return;
607                                                                                             }
608                                                                                             
609                                                                                             
610                                                                                             pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
611                                                                                             //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
612                                                                                         }
613                                                                                           
614                                                                             },
615                                                                             loadFile : function(f) {
616                                                                                 //console.dump(f);
617                                                                                         this.el.clear();
618                                                                                         this.file = f;
619                                                                                         
620                                                                                         if (!f) {
621                                                                                             console.log('missing file');
622                                                                                             return;
623                                                                                         }
624                                                                                         
625                                                                                         // load the file if not loaded..
626                                                                                         if (f.items === false) {
627                                                                                             var _this = this;
628                                                                                             f.loadItems(function() {
629                                                                                                 _this.loadFile(f);
630                                                                                             });
631                                                                                             return;
632                                                                                             
633                                                                                         }
634                                                                                         if (f.items.length && typeof(f.items[0]) == 'string') {
635                                                                                         
636                                                                                             this.get('/RightEditor').el.show();
637                                                                                             this.get('/RightEditor.view').load( f.items[0]);
638                                                                                             return;
639                                                                                         }
640                                                                                         print("LOAD");
641                                                                                         //console.dump(f.items);
642                                                                                         this.load(f.items);
643                                                                                         this.get('/LeftTree.view').el.expand_all();
644                                                                             
645                                                                                         if (!f.items.length) {
646                                                                                             // single item..
647                                                                                             
648                                                                                             this.get('/Window.leftvpaned').el.set_position(80);
649                                                                                             // select first...
650                                                                                             this.get('/LeftTree.view').el.set_cursor( 
651                                                                                                 new  Gtk.TreePath.from_string('0'), null, false);
652                                                                                             
653                                                                                             
654                                                                                         } else {
655                                                                                               this.get('/Window.leftvpaned').el.set_position(200);
656                                                                                         }
657                                                                                         
658                                                                                         
659                                                                                         //print("hide right editior");
660                                                                                         this.get('/RightEditor').el.hide();
661                                                                                         //print("set current tree");
662                                                                                         this.currentTree = this.toJS(false, false)[0];
663                                                                                         //console.dump(this.currentTree);
664                                                                                         this.currentTree = this.currentTree || { items: [] };
665                                                                                         this.get('/LeftTree').renderView();
666                                                                                         //console.dump(this.map);
667                                                                                         //var RightPalete     = imports.Builder.RightPalete.RightPalete;
668                                                                                         var pm = this.get('/RightPalete.model');
669                                                                                         // set up provider..
670                                                                                         
671                                                                                         this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
672                                                                                         
673                                                                                         if (!this.get('/RightPalete').provider) {
674                                                                                             print ("********* PALETE PROVIDER MISSING?!!");
675                                                                                         }
676                                                                                         this.get('/LeftTree').renderView();
677                                                                                         
678                                                                                         pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
679                                                                                         
680                                                                                         
681                                                                                                 
682                                                                                         this.get('/Window.view-notebook').el.set_current_page(
683                                                                                             this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
684                                                                                                 
685                                                                             },
686                                                                             findDropNode : function(treepath_str, targets) {
687                                                                             
688                                                                             // this is used by the dragdrop code in the roo version AFAIR..
689                                                                             
690                                                                                                 var path = treepath_str.replace(/^builder-/, '');
691                                                                                         // treemap is depreciated... - should really check if model has any entries..
692                                                                             
693                                                                                         if (!this.el.iter_n_children(null)) {
694                                                                                             print("NO KEYS");
695                                                                                             return [ '',  Gtk.TreeViewDropPosition.INTO_OR_AFTER];
696                                                                                         }
697                                                                                         print("FIND treepath: " + path);
698                                                                                         //console.dump(this.treemap);
699                                                                                         
700                                                                                         if (!treepath_str.match(/^builder-/)) {
701                                                                                             return []; // nothing!
702                                                                                         }
703                                                                                         if (targets === true) {
704                                                                                             return [ path ];
705                                                                                         }
706                                                                                         return this.findDropNodeByPath(path,targets) 
707                                                                             },
708                                                                             findDropNodeByPath : function(treepath_str, targets, pref) {
709                                                                                 var path = treepath_str + ''; // dupe it..
710                                                                                 pref = typeof(pref) == 'undefined' ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
711                                                                                 var last = false;
712                                                                                 //console.dump(this.treemap);
713                                                                                 while (path.length) {
714                                                                                     print("LOOKING FOR PATH: " + path);
715                                                                                     var node_data = this.singleNodeToJS(path);
716                                                                                     if (node_data === false) {
717                                                                                         print("node not found");
718                                                                                         return [];
719                                                                                     }
720                                                                                     
721                                                                                     var xname = this.get('/LeftTree.model').file.guessName(node_data);
722                                                                                     var match = false;
723                                                                                     var prop = '';
724                                                                                     targets.forEach(function(tg) {
725                                                                                         if (match) {
726                                                                                             return;;
727                                                                                         }
728                                                                                         if ((tg == xname)  ) {
729                                                                                             match = tg;
730                                                                                         }
731                                                                                         if (tg.indexOf(xname +':') === 0) {
732                                                                                             match = tg;
733                                                                                             prop = tg.split(':').pop();
734                                                                                         }
735                                                                                     });
736                                                                                     
737                                                                                     if (match) {
738                                                                                         if (last) { // pref is after/before..
739                                                                                             // then it's after last
740                                                                                             if (pref > 1) {
741                                                                                                 return []; // do not allow..
742                                                                                             }
743                                                                                             return [ last, pref , prop];
744                                                                                             
745                                                                                         }
746                                                                                         return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
747                                                                                     }
748                                                                                     var par = path.split(':');
749                                                                                     last = path;
750                                                                                     par.pop();
751                                                                                     path = par.join(':');
752                                                                                 }
753                                                                                 
754                                                                                 return [];
755                                                                                         
756                                                                             },
757                                                                             dropNode : function(target_data, node) {
758                                                                               print("drop Node");
759                                                                                   console.dump(node);
760                                                                                   console.dump(target_data);
761                                                                                         var tp = target_data[0].length ? new  Gtk.TreePath.from_string( target_data[0] ) : false;
762                                                                                         
763                                                                                         print("add " + tp + "@" + target_data[1]  );
764                                                                                         var parent = tp;
765                                                                                         var after = false;
766                                                                                         if (tp && target_data[1]  < 2) { // before or after..
767                                                                                             var ar = target_data[0].split(':');
768                                                                                             ar.pop();
769                                                                                             parent  = new  Gtk.TreePath.from_string( ar.join(':') );
770                                                                                             after = tp;
771                                                                                         }
772                                                                                         var n_iter = new Gtk.TreeIter();
773                                                                                         var iter_par = new Gtk.TreeIter();
774                                                                                         var iter_after = after ? new Gtk.TreeIter() : false;
775                                                                                         
776                                                                                         
777                                                                                         
778                                                                                         if (parent !== false) {
779                                                                                             this.el.get_iter(iter_par, parent);
780                                                                                         } else {
781                                                                                             iter_par = null;
782                                                                                         }
783                                                                                         
784                                                                                         
785                                                                                         if (tp && after) {
786                                                                                             print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');
787                                                                                             this.el.get_iter(iter_after, after);
788                                                                                             this.el[ target_data[1]  > 0 ? 'insert_after' : 'insert_before'](
789                                                                                                     n_iter, iter_par, iter_after);
790                                                                                             
791                                                                                         } else {
792                                                                                             this.el.append(n_iter, iter_par);
793                                                                                             
794                                                                                         }
795                                                                                         
796                                                                                         if (typeof(node) == 'string') {
797                                                                                             var ar = node.split('.');
798                                                                                             var xtype = ar.pop();
799                                                                                             
800                                                                                             node = {
801                                                                                                 '|xns' : ar.join('.'),
802                                                                                                 'xtype' : xtype
803                                                                                             };
804                                                                                             if (target_data.length == 3 && target_data[2].length) {
805                                                                                                 node['*prop'] = target_data[2];
806                                                                                             }
807                                                                                             
808                                                                                         }
809                                                                                         // work out what kind of packing to use..
810                                                                                         if (typeof(node.pack) == 'undefined'  && parent !== false) {
811                                                                                             var pal = this.get('/LeftTree').getPaleteProvider();
812                                                                                             
813                                                                                             var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
814                                                                                             print ("PNAME : "  + pname);
815                                                                                             var cname = pal.guessName(node);
816                                                                                             print ("CNAME : "  + cname);
817                                                                                             node.pack = pal.getDefaultPack(pname, cname);
818                                                                                             
819                                                                                             
820                                                                                         }
821                                                                                         
822                                                                                         
823                                                                                         var xitems = [];
824                                                                                         if (node.items) {
825                                                                                             xitems = node.items;
826                                                                                             delete node.items;
827                                                                                         }
828                                                                             // load children - if it has any..
829                                                                             
830                                                                                         if (xitems) {
831                                                                                             this.load(xitems, n_iter);
832                                                                                         }
833                                                                                         if (tp && (xitems || after)) {
834                                                                                             this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
835                                                                                         }
836                                                                                         // wee need to get the empty proptypes from somewhere..
837                                                                                         
838                                                                                         //var olditer = this.activeIter;
839                                                                                         this.activePath = this.el.get_path(n_iter).to_string();
840                                                                             
841                                                                                   // changed actually set's the node data..
842                                                                                         this.changed(node, true);
843                                                                                         
844                                                                                         
845                                                                                         
846                                                                                         this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
847                                                                                         
848                                                                                         //Builder.MidPropTree._model.load(node);
849                                                                                         //Builder.MidPropTree._win.hideWin();
850                                                                                         //Builder.LeftPanel._model.load( node);
851                                                                                         
852                                                                                         
853                                                                             },
854                                                                             moveNode : function(target_data, action) {
855                                                                                  //print("MOVE NODE");
856                                                                                        // console.dump(target_data);
857                                                                                         var old_iter = new Gtk.TreeIter();
858                                                                                         var s = this.get('/LeftTree.view').selection;
859                                                                                         s.get_selected(this.el, old_iter);
860                                                                                         var node = this.nodeToJS(old_iter,false);
861                                                                                         //console.dump(node);
862                                                                                         
863                                                                                         
864                                                                                         // needs to drop first, otherwise the target_data 
865                                                                                         // treepath will be invalid.
866                                                                                         
867                                                                                         this.dropNode(target_data, node);
868                                                                                   if (action & Gdk.DragAction.MOVE) {
869                                                                                                   //          print("REMOVING OLD NODE");
870                                                                                                             this.el.remove(old_iter);
871                                                                                                             
872                                                                                         }
873                                                                                         
874                                                                                         this.activeIter = false;
875                                                                                         this.changed(false,true);
876                                                                             },
877                                                                             deleteSelected : function() {
878                                                                                         
879                                                                                         var old_iter = new Gtk.TreeIter();
880                                                                                         var s = this.get('/LeftTree.view').selection;
881                                                                                         s.get_selected(this.el, old_iter);
882                                                                                         s.unselect_all();
883                                                                                         
884                                                                                         this.el.remove(old_iter);
885                                                                                         
886                                                                                         // rebuild treemap. -- depreciated.!!
887                                                                                         this.map = {};
888                                                                                         this.treemap = { };
889                                                                                         //this.toJS(null, true) // does not do anything?
890                                                                                         this.activeIter = false;
891                                                                                         this.changed(false,true);
892                                                                             },
893                                                                             currentTree : false,
894                                                                             listAllTypes : function() {
895                                                                                 var s = this.get('/LeftTree.view').selection;
896                                                                                 print ("LIST ALL TYPES: " + s.count_selected_rows() );
897                                                                                 
898                                                                                 if (s.count_selected_rows() > 0) {
899                                                                                     var iter = new Gtk.TreeIter();    
900                                                                                     s.get_selected(this.el, iter);
901                                                                             
902                                                                                     // set some properties of the tree for use by the dropped element.
903                                                                                     var value = new GObject.Value('');
904                                                                                     this.el.get_value(iter, 2, value);
905                                                                                     var data = JSON.parse(value.value);
906                                                                                     
907                                                                                     
908                                                                                     var xname = this.get('/LeftTree.model').file.guessName(data);
909                                                                                     console.log('selected:' + xname);
910                                                                                     if (xname.length) {
911                                                                                         return [ xname ];
912                                                                                     }
913                                                                                     return []; // could not find it..
914                                                                                 }
915                                                                                 
916                                                                                 var ret = [ ];
917                                                                                 
918                                                                                var _this = this;
919                                                                                 function addall(li)
920                                                                                 {
921                                                                                     li.forEach(function(el) {
922                                                                                         // this is specific to roo!!!?
923                                                                                         
924                                                                                         var fullpath =  _this.file.guessName(el);
925                                                                                         if (fullpath.length && ret.indexOf(fullpath) < 0) {
926                                                                                             ret.push(fullpath);
927                                                                                         }
928                                                                                         
929                                                                                         
930                                                                                         if (el.items && el.items.length) {
931                                                                                             addall(el.items);
932                                                                                         }
933                                                                                         
934                                                                                     });
935                                                                                     
936                                                                                     
937                                                                                 }
938                                                                                 
939                                                                                 addall([this.currentTree]);
940                                                                                 
941                                                                                 // only if we have nothing, should we add '*top'
942                                                                                 if (!ret.length) {
943                                                                                     ret = [ '*top' ];
944                                                                                 }
945                                                                                 //console.log('all types in tree');
946                                                                                 //console.dump(ret);
947                                                                                 
948                                                                                 return ret;
949                                                                                                         
950                                                                             },
951                                                                             singleNodeToJS : function (treepath) 
952                                                                                     {
953                                                                                         var iter = new Gtk.TreeIter(); 
954                                                                                         if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
955                                                                                             return false;
956                                                                                         }
957                                                                                         
958                                                                                         var iv = this.getIterValue(iter, 2);
959                                                                                        
960                                                                                         return JSON.parse(iv);
961                                                                                         
962                                                                                     },
963                                                                             nodeToJS : function (iter, with_id) 
964                                                                             {
965                                                                                 var par = new Gtk.TreeIter(); 
966                                                                                 var iv = this.getIterValue(iter, 2);
967                                                                                // print("IV" + iv);
968                                                                                 var k = JSON.parse(iv);
969                                                                                 if (k.json && !this.el.iter_parent( par, iter  )) {
970                                                                                     delete k.json;
971                                                                                 }
972                                                                                 
973                                                                                 if (with_id) {
974                                                                                     var treepath_str = this.el.get_path(iter).to_string();
975                                                                                     // not sure how we can handle mixed id stuff..
976                                                                                     if (typeof(k.id) == 'undefined')  {
977                                                                                         k.id =  'builder-'+ treepath_str ;
978                                                                                     }
979                                                                                     
980                                                                                     // needed??
981                                                                                     this.treemap[  treepath_str ] = k;
982                                                                                     k.xtreepath = treepath_str ;
983                                                                                     
984                                                                                 }
985                                                                                 if (this.el.iter_has_child(iter)) {
986                                                                                     citer = new Gtk.TreeIter();
987                                                                                     this.el.iter_children(citer, iter);
988                                                                                     k.items = this.toJS(citer,with_id);
989                                                                                 }
990                                                                                 return k;
991                                                                             },
992                                                                             toJS : function(iter, with_id)
993                                                                                     {
994                                                                                         //Seed.print("WITHID: "+ with_id);
995                                                                                         
996                                                                                         var first = false;
997                                                                                         if (!iter) {
998                                                                                             
999                                                                                             this.treemap = { }; 
1000                                                                                             
1001                                                                                             iter = new Gtk.TreeIter();
1002                                                                                             if (!this.el.get_iter_first(iter)) {
1003                                                                                                 return [];
1004                                                                                             }
1005                                                                                             first = true;
1006                                                                                         } 
1007                                                                                         
1008                                                                                         var ar = [];
1009                                                                                            
1010                                                                                         while (true) {
1011                                                                                             
1012                                                                                             var k = this.nodeToJS(iter, with_id); 
1013                                                                                             ar.push(k);
1014                                                                                             
1015                                                                                             
1016                                                                                             if (!this.el.iter_next(iter)) {
1017                                                                                                 break;
1018                                                                                             }
1019                                                                                         }
1020                                                                                         
1021                                                                                         return ar;
1022                                                                                         // convert the list into a json string..
1023                                                                                     
1024                                                                                         
1025                                                                                     },
1026                                                                             getIterValue : function (iter, col) {
1027                                                                                 var gval = new GObject.Value('');
1028                                                                                 this.el.get_value(iter, col ,gval);
1029                                                                                 return  gval.value;
1030                                                                                 
1031                                                                                 
1032                                                                             },
1033                                                                             nodeTitle : function(c) {
1034                                                                                   var txt = [];
1035                                                                                 c = c || {};
1036                                                                                 var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
1037                                                                                 if (sr) txt.push('<s>');
1038                                                                                 if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
1039                                                                                 if (c.xtype)      { txt.push(c.xtype); }
1040                                                                                 if (c.id)      { txt.push('<b>[id=' + c.id + ']</b>'); }
1041                                                                                 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1042                                                                                 if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
1043                                                                                 
1044                                                                                 
1045                                                                                 if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
1046                                                                                 if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
1047                                                                                 if (c.label)      { txt.push('<b>' + c.label+ '</b>'); }
1048                                                                                 if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
1049                                                                                 if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
1050                                                                                 if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
1051                                                                                 if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
1052                                                                                 if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
1053                                                                                 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1054                                                                                 
1055                                                                                 // for flat classes...
1056                                                                                 if (typeof(c['*class']) != 'undefined')  { txt.push('<b>' +  c['*class']+  '</b>'); }
1057                                                                                 if (typeof(c['*extends']) != 'undefined')  { txt.push(': <i>' +  c['*extends']+  '</i>'); }
1058                                                                                 
1059                                                                                 
1060                                                                                 if (sr) txt.push('</s>');
1061                                                                                 return (txt.length == 0 ? "Element" : txt.join(" "));
1062                                                                             },
1063                                                                             nodeToJSON : function(c) {
1064                                                                                 var o  = {}
1065                                                                                 for (var i in c) {
1066                                                                                     if (i == 'items') {
1067                                                                                          continue;
1068                                                                                     }
1069                                                                                     o[i] = c[i];
1070                                                                                 }
1071                                                                                 return JSON.stringify(o);
1072                                                                             },
1073                                                                             load : function(tr,iter)
1074                                                                                     {
1075                                                                                         var citer = new Gtk.TreeIter();
1076                                                                                         //this.insert(citer,iter,0);
1077                                                                                         for(var i =0 ; i < tr.length; i++) {
1078                                                                                             if (iter) {
1079                                                                                                 this.el.insert(citer,iter,-1);
1080                                                                                             } else {
1081                                                                                                 this.el.append(citer);
1082                                                                                             }
1083                                                                                             
1084                                                                                             this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1085                                                                                             this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1086                                                                                             this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1087                                                                                             if (tr[i].items && tr[i].items.length) {
1088                                                                                                 this.load(tr[i].items, citer);
1089                                                                                             }
1090                                                                                         }     
1091                                                                                     }
1092                                                                         },
1093                                                                         {
1094                                                                             xtype: Gtk.TreeViewColumn,
1095                                                                             pack : "append_column",
1096                                                                             init : function() {
1097                                                                                 XObject.prototype.init.call(this);
1098                                                                                this.el.add_attribute(this.items[0].el , 'markup', 0 );
1099                                                                             },
1100                                                                             items : [
1101                                                                                 {
1102                                                                                     xtype: Gtk.CellRendererText,
1103                                                                                     pack : "pack_start"
1104                                                                                 }
1105                                                                             ]
1106                                                                         }
1107                                                                     ]
1108                                                                 },
1109                                                                 {
1110                                                                     xtype: Gtk.Menu,
1111                                                                     pack : false,
1112                                                                     id : "LeftTreeMenu",
1113                                                                     items : [
1114                                                                         {
1115                                                                             xtype: Gtk.MenuItem,
1116                                                                             pack : "add",
1117                                                                             label : "Delete Element",
1118                                                                             listeners : {
1119                                                                                 "activate":function (self) {
1120                                                                                 
1121                                                                                      this.get('/LeftTree.model').deleteSelected();
1122                                                                                 }
1123                                                                             }
1124                                                                         }
1125                                                                     ]
1126                                                                 }
1127                                                             ]
1128                                                         },
1129                                                         {
1130                                                             xtype: Gtk.VBox,
1131                                                             pack : "add",
1132                                                             id : "LeftProjectTree",
1133                                                             showNoProjectSelected : function() {
1134                                                                this.get('/StandardErrorDialog').show("Select a Project first."); 
1135                                                             },
1136                                                             getActiveProject : function() {
1137                                                                  return this.project;
1138                                                             },
1139                                                             listeners : {
1140                                                                 "leave_notify_event":function (self, event) {
1141                                                                     return false;
1142                                                                 }
1143                                                             },
1144                                                             items : [
1145                                                                 {
1146                                                                     xtype: Gtk.HBox,
1147                                                                     pack : "pack_start,false,false",
1148                                                                     items : [
1149                                                                         {
1150                                                                             xtype: Gtk.ComboBox,
1151                                                                             id : "combo",
1152                                                                             init : function() {
1153                                                                                 XObject.prototype.init.call(this);
1154                                                                                 this.el.add_attribute(this.get('render').el , 'markup', 1 );  
1155                                                                             },
1156                                                                             getValue : function() {
1157                                                                                 var ix = this.el.get_active();
1158                                                                                 if (ix < 0 ) {
1159                                                                                     return false;
1160                                                                                 }
1161                                                                                 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1162                                                                                 return data[ix].fn;
1163                                                                             },
1164                                                                             setValue : function(fn)
1165                                                                             {
1166                                                                                 var el = this.el;
1167                                                                                 el.set_active(-1);
1168                                                                                 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1169                                                                                 data.forEach(function(n, ix) {
1170                                                                                     if (fn == n.fn) {
1171                                                                                         el.set_active(ix);
1172                                                                                         return false;
1173                                                                                     }
1174                                                                                 });
1175                                                                             },
1176                                                                             listeners : {
1177                                                                                 "changed":function (self) {
1178                                                                                         var fn = this.getValue();
1179                                                                                         var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
1180                                                                                         this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1181                                                                                 }
1182                                                                             },
1183                                                                             items : [
1184                                                                                 {
1185                                                                                     xtype: Gtk.CellRendererText,
1186                                                                                     pack : "pack_start,true",
1187                                                                                     id : "render"
1188                                                                                 },
1189                                                                                 {
1190                                                                                     xtype: Gtk.ListStore,
1191                                                                                     pack : "set_model",
1192                                                                                     init : function() {
1193                                                                                         XObject.prototype.init.call(this);
1194                                                                                       this.el.set_column_types ( 2, [
1195                                                                                             GObject.TYPE_STRING,  // real key
1196                                                                                             GObject.TYPE_STRING // real type
1197                                                                                             
1198                                                                                             
1199                                                                                         ] );
1200                                                                                             
1201                                                                                     },
1202                                                                                     loadData : function(data) {
1203                                                                                          var ov = this.get('/LeftProjectTree.combo').getValue();
1204                                                                                         this.el.clear();
1205                                                                                         var iter = new Gtk.TreeIter();
1206                                                                                         var el = this.el;
1207                                                                                         data.forEach(function(p) {
1208                                                                                             
1209                                                                                             el.append(iter);
1210                                                                                             
1211                                                                                              
1212                                                                                             el.set_value(iter, 0, p.fn);
1213                                                                                             el.set_value(iter, 1, p.name);
1214                                                                                             
1215                                                                                         });
1216                                                                                         
1217                                                                                         this.get('/LeftProjectTree.combo').setValue(ov);
1218                                                                                     },
1219                                                                                     id : "combomodel"
1220                                                                                 }
1221                                                                             ]
1222                                                                         }
1223                                                                     ]
1224                                                                 },
1225                                                                 {
1226                                                                     xtype: Gtk.ScrolledWindow,
1227                                                                     pack : "add",
1228                                                                     shadow_type : Gtk.ShadowType.IN,
1229                                                                     init : function() {
1230                                                                         XObject.prototype.init.call(this);
1231                                                                         this.el.set_policy  (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1232                                                                     },
1233                                                                     items : [
1234                                                                         {
1235                                                                             xtype: Gtk.TreeView,
1236                                                                             headers_visible : false,
1237                                                                             enable_tree_lines : true,
1238                                                                             tooltip_column : 1,
1239                                                                             init : function() {
1240                                                                                 XObject.prototype.init.call(this);
1241                                                                             var description = new Pango.FontDescription.c_new();
1242                                                                                                         description.set_size(8000);
1243                                                                                                         this.el.modify_font(description);
1244                                                                                                         
1245                                                                                                         this.selection = this.el.get_selection();
1246                                                                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1247                                                                             },
1248                                                                             id : "view",
1249                                                                             listeners : {
1250                                                                                 "cursor_changed":function (self) {
1251                                                                                         var iter = new Gtk.TreeIter();
1252                                                                                                                 
1253                                                                                         if (this.selection.count_selected_rows() < 1) {
1254                                                                                             //XN.get('Builder.LeftTree.model').
1255                                                                                             this.get('/LeftTree.model').load( false);
1256                                                                                             
1257                                                                                             return;
1258                                                                                         }
1259                                                                                         var model = this.get('/LeftProjectTree.model');
1260                                                                                         //console.log('changed');
1261                                                                                         var s = this.selection;
1262                                                                                         s.get_selected(model, iter);
1263                                                                                         value = new GObject.Value('');
1264                                                                                         model.el.get_value(iter, 2, value);
1265                                                                                         
1266                                                                                         console.log(value.value);// id..
1267                                                                                         
1268                                                                                         var file = this.get('/LeftProjectTree').project.getById(value.value);
1269                                                                                         
1270                                                                                         
1271                                                                                         console.log(file);
1272                                                                                         
1273                                                                                 
1274                                                                                 
1275                                                                                         var nb = this.get('/LeftTopPanel.expander');
1276                                                                                         nb.el.expanded = false;
1277                                                                                         nb.listeners.activate.call(nb);
1278                                                                                         //_expander.el.set_expanded(false);
1279                                                                                 
1280                                                                                         var ltm = this.get('/LeftTree.model');
1281                                                                                         ltm.loadFile(file);
1282                                                                                         
1283                                                                                         return true;
1284                                                                                 }
1285                                                                             },
1286                                                                             items : [
1287                                                                                 {
1288                                                                                     xtype: Gtk.TreeStore,
1289                                                                                     pack : "set_model",
1290                                                                                     id : "model",
1291                                                                                     init : function() {
1292                                                                                         XObject.prototype.init.call(this);
1293                                                                                       this.el.set_column_types ( 3, [
1294                                                                                                         GObject.TYPE_STRING, // title 
1295                                                                                                         GObject.TYPE_STRING, // tip
1296                                                                                                         GObject.TYPE_STRING // id..
1297                                                                                                         ] );
1298                                                                                        
1299                                                                                     },
1300                                                                                     loadProject : function(pr) {
1301                                                                                                this.el.clear();
1302                                                                                                 if (!pr) {
1303                                                                                                     return;
1304                                                                                                 }
1305                                                                                                 this.get('/LeftProjectTree').project = pr;
1306                                                                                                 this.load(pr.toTree());
1307                                                                                                 this.get('/LeftProjectTree.view').el.expand_all();
1308                                                                                     },
1309                                                                                     load : function(tr,iter) {
1310                                                                                         console.dump(tr);
1311                                                                                                 console.log('Project tree load: ' + tr.length);
1312                                                                                                 var citer = new Gtk.TreeIter();
1313                                                                                                 //this.insert(citer,iter,0);
1314                                                                                                 
1315                                                                                                 var _this = this;
1316                                                                                                 tr.forEach(function (r) {
1317                                                                                                     if (!iter) {
1318                                                                                                         _this.el.append(citer);   
1319                                                                                                     } else {
1320                                                                                                         _this.el.insert(citer,iter,-1);
1321                                                                                                     }
1322                                                                                                     _this.el.set_value(citer, 0,  '' + r.getTitle() ); // title 
1323                                                                                                     _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1324                                                                                                     _this.el.set_value(citer, 2, '' + r.id ); //id
1325                                                                                                     if (r.cn && r.cn.length) {
1326                                                                                                         _this.load(r.cn, citer);
1327                                                                                                     }
1328                                                                                                     
1329                                                                                                 });
1330                                                                                     },
1331                                                                                     getValue : function(iter, col) {
1332                                                                                         var gval = new GObject.Value('');
1333                                                                                         this.el.get_value(iter, col ,gval);
1334                                                                                         return  '' + gval.value;
1335                                                                                     }
1336                                                                                 },
1337                                                                                 {
1338                                                                                     xtype: Gtk.TreeViewColumn,
1339                                                                                     pack : "append_column",
1340                                                                                     init : function() {
1341                                                                                         XObject.prototype.init.call(this);
1342                                                                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
1343                                                                                     },
1344                                                                                     items : [
1345                                                                                         {
1346                                                                                             xtype: Gtk.CellRendererText,
1347                                                                                             pack : "pack_start"
1348                                                                                         }
1349                                                                                     ]
1350                                                                                 }
1351                                                                             ]
1352                                                                         }
1353                                                                     ]
1354                                                                 }
1355                                                             ]
1356                                                         }
1357                                                     ]
1358                                                 }
1359                                             ]
1360                                         },
1361                                         {
1362                                             xtype: Gtk.VBox,
1363                                             listeners : {
1364                                                 
1365                                             },
1366                                             items : [
1367                                                 {
1368                                                     xtype: Gtk.HBox,
1369                                                     pack : "pack_start,false,true,0",
1370                                                     id : "LeftProps",
1371                                                     items : [
1372                                                         {
1373                                                             xtype: Gtk.Button,
1374                                                             pack : "add",
1375                                                             listeners : {
1376                                                                 "button_press_event":function (self, event) {
1377                                                                     this.get('/MidPropTree.model').showData('props');
1378                                                                     return false;
1379                                                                 }
1380                                                             },
1381                                                             items : [
1382                                                                 {
1383                                                                     xtype: Gtk.HBox,
1384                                                                     pack : "add",
1385                                                                     items : [
1386                                                                         {
1387                                                                             xtype: Gtk.Image,
1388                                                                             pack : "add",
1389                                                                             stock : Gtk.STOCK_ADD,
1390                                                                             icon_size : Gtk.IconSize.MENU
1391                                                                         },
1392                                                                         {
1393                                                                             xtype: Gtk.Label,
1394                                                                             pack : "add",
1395                                                                             label : "Property"
1396                                                                         }
1397                                                                     ]
1398                                                                 }
1399                                                             ]
1400                                                         },
1401                                                         {
1402                                                             xtype: Gtk.Button,
1403                                                             pack : "add",
1404                                                             listeners : {
1405                                                                 "button_press_event":function (self, event) {
1406                                                                     this.get('/MidPropTree.model').showData('events');
1407                                                                     return false;
1408                                                                 }
1409                                                             },
1410                                                             items : [
1411                                                                 {
1412                                                                     xtype: Gtk.HBox,
1413                                                                     pack : "add",
1414                                                                     items : [
1415                                                                         {
1416                                                                             xtype: Gtk.Image,
1417                                                                             pack : "add",
1418                                                                             stock : Gtk.STOCK_ADD,
1419                                                                             icon_size : Gtk.IconSize.MENU
1420                                                                         },
1421                                                                         {
1422                                                                             xtype: Gtk.Label,
1423                                                                             pack : "add",
1424                                                                             label : "Handler"
1425                                                                         }
1426                                                                     ]
1427                                                                 }
1428                                                             ]
1429                                                         },
1430                                                         {
1431                                                             xtype: Gtk.Button,
1432                                                             pack : "add",
1433                                                             listeners : {
1434                                                                 "button_press_event":function (self, ev) {
1435                                                                         var p = this.get('/AddPropertyPopup');
1436                                                                         if (!p.el) {
1437                                                                                 p.init();
1438                                                                         }
1439                                                                         p.el.set_screen(Gdk.Screen.get_default());
1440                                                                         p.el.show_all();
1441                                                                          p.el.popup(null, null, null, null, 3, ev.button.time);
1442                                                                     return true;
1443                                                                 }
1444                                                             },
1445                                                             items : [
1446                                                                 {
1447                                                                     xtype: Gtk.HBox,
1448                                                                     pack : "add",
1449                                                                     items : [
1450                                                                         {
1451                                                                             xtype: Gtk.Image,
1452                                                                             pack : "add",
1453                                                                             stock : Gtk.STOCK_ADD,
1454                                                                             icon_size : Gtk.IconSize.MENU
1455                                                                         },
1456                                                                         {
1457                                                                             xtype: Gtk.Label,
1458                                                                             pack : "add",
1459                                                                             label : "Other"
1460                                                                         }
1461                                                                     ]
1462                                                                 },
1463                                                                 {
1464                                                                     xtype: Gtk.Menu,
1465                                                                     pack : false,
1466                                                                     id : "AddPropertyPopup",
1467                                                                     items : [
1468                                                                         {
1469                                                                             xtype: Gtk.MenuItem,
1470                                                                             pack : "append",
1471                                                                             tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1472                                                                             label : "ID",
1473                                                                             listeners : {
1474                                                                                 "activate":function (self) {
1475                                                                                 
1476                                                                                     this.get('/LeftPanel.model').add( {
1477                                                                                         key : 'id', 
1478                                                                                         type : 'string',
1479                                                                                         val : '',
1480                                                                                         //skel  : skel,
1481                                                                                         etype : 'props'
1482                                                                                     });
1483                                                                                 }
1484                                                                             }
1485                                                                         },
1486                                                                         {
1487                                                                             xtype: Gtk.MenuItem,
1488                                                                             pack : "append",
1489                                                                             tooltip_markup : "Add what type of packing is to be used",
1490                                                                             label : "PACK",
1491                                                                             listeners : {
1492                                                                                 "activate":function (self) {
1493                                                                                 
1494                                                                                     this.get('/LeftPanel.model').add( {
1495                                                                                          key : 'pack', 
1496                                                                                          type : 'string',
1497                                                                                          val : 'add',
1498                                                                                           etype : 'props'
1499                                                                                     });
1500                                                                                 }
1501                                                                             }
1502                                                                         },
1503                                                                         {
1504                                                                             xtype: Gtk.MenuItem,
1505                                                                             pack : "append",
1506                                                                             tooltip_markup : "Override the init method",
1507                                                                             label : "INIT",
1508                                                                             listeners : {
1509                                                                                 "activate":function (self) {
1510                                                                                 
1511                                                                                     this.get('/LeftPanel.model').add( {
1512                                                                                        key : '|init', 
1513                                                                                         type : 'function',
1514                                                                                         val  : "function() {\n    XObject.prototype.init.call(this);\n}\n",
1515                                                                                         etype : 'props'
1516                                                                                     });
1517                                                                                 }
1518                                                                             }
1519                                                                         },
1520                                                                         {
1521                                                                             xtype: Gtk.SeparatorMenuItem,
1522                                                                             pack : "add"
1523                                                                         },
1524                                                                         {
1525                                                                             xtype: Gtk.MenuItem,
1526                                                                             pack : "append",
1527                                                                             tooltip_markup : "Add a user defined string property",
1528                                                                             label : "String",
1529                                                                             listeners : {
1530                                                                                 "activate":function (self) {
1531                                                                                 
1532                                                                                     this.get('/LeftPanel.model').add( {
1533                                                                                                   key : '', 
1534                                                                                                 type : 'string',
1535                                                                                                 val  : "",
1536                                                                                                 etype : 'props'
1537                                                                                     });
1538                                                                                 }
1539                                                                             }
1540                                                                         },
1541                                                                         {
1542                                                                             xtype: Gtk.MenuItem,
1543                                                                             pack : "append",
1544                                                                             tooltip_markup : "Add a user defined number property",
1545                                                                             label : "Number",
1546                                                                             listeners : {
1547                                                                                 "activate":function (self) {
1548                                                                                 
1549                                                                                     this.get('/LeftPanel.model').add( {
1550                                                                                                   key : '', 
1551                                                                                                 type : 'number',
1552                                                                                                 val  : 0,
1553                                                                                                 etype : 'props'
1554                                                                                     });
1555                                                                                 }
1556                                                                             }
1557                                                                         },
1558                                                                         {
1559                                                                             xtype: Gtk.MenuItem,
1560                                                                             pack : "append",
1561                                                                             tooltip_markup : "Add a user defined boolean property",
1562                                                                             label : "Boolean",
1563                                                                             listeners : {
1564                                                                                 "activate":function (self) {
1565                                                                                 
1566                                                                                     this.get('/LeftPanel.model').add( {
1567                                                                                                   key : '', 
1568                                                                                                 type : 'boolean',
1569                                                                                                 val  : false,
1570                                                                                                 etype : 'props'
1571                                                                                     });
1572                                                                                 }
1573                                                                             }
1574                                                                         },
1575                                                                         {
1576                                                                             xtype: Gtk.SeparatorMenuItem,
1577                                                                             pack : "add"
1578                                                                         },
1579                                                                         {
1580                                                                             xtype: Gtk.MenuItem,
1581                                                                             pack : "append",
1582                                                                             tooltip_markup : "Add a user function boolean property",
1583                                                                             label : "Function",
1584                                                                             listeners : {
1585                                                                                 "activate":function (self) {
1586                                                                                 
1587                                                                                     this.get('/LeftPanel.model').add( {
1588                                                                                             key : '|', 
1589                                                                                                         type : 'function',
1590                                                                                                         val  : "function() {\n    \n}\n",
1591                                                                                                         etype : 'props'
1592                                                                                     });
1593                                                                                 }
1594                                                                             }
1595                                                                         }
1596                                                                     ]
1597                                                                 }
1598                                                             ]
1599                                                         }
1600                                                     ]
1601                                                 },
1602                                                 {
1603                                                     xtype: Gtk.ScrolledWindow,
1604                                                     id : "LeftPanel",
1605                                                     pack : "add",
1606                                                     shadow_type : Gtk.ShadowType.IN,
1607                                                     editing : false,
1608                                                     init : function() {
1609                                                         XObject.prototype.init.call(this);
1610                                                        this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1611                                                     },
1612                                                     items : [
1613                                                         {
1614                                                             xtype: Gtk.TreeView,
1615                                                             id : "view",
1616                                                             tooltip_column : 1,
1617                                                             headers_visible : false,
1618                                                             enable_tree_lines : true,
1619                                                             init : function() {
1620                                                                  XObject.prototype.init.call(this); 
1621                                                                                    
1622                                                                                 this.selection = this.el.get_selection();
1623                                                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1624                                                                              
1625                                                                                 
1626                                                                                 var description = new Pango.FontDescription.c_new();
1627                                                                                 description.set_size(8000);
1628                                                                                 this.el.modify_font(description);
1629                                                             },
1630                                                             listeners : {
1631                                                                 "button_press_event":function (self, ev) {
1632                                                                     
1633                                                                                 
1634                                                                                 var res = { }; 
1635                                                                                 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1636                                                                                     return false; //not on a element.
1637                                                                                 }
1638                                                                                 
1639                                                                                 
1640                                                                                 if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button.button != 3) {
1641                                                                                     
1642                                                                                     if (res.column.title != 'value') {
1643                                                                                         return false; // ignore..
1644                                                                                     }
1645                                                                                     if (  this.get('/LeftPanel').editing) {
1646                                                                                         return false;
1647                                                                                     }
1648                                                                                     var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1649                                                                                     this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1650                                                                                     var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1651                                                                                     
1652                                                                                      
1653                                                                 
1654                                                                                     var provider = this.get('/LeftTree').getPaleteProvider();
1655                                                                                     
1656                                                                                     var opts = provider.findOptions(type);
1657                                                                                     
1658                                                                                     if (opts === false) {
1659                                                                                          this.get('/LeftPanel').editableColumn.setOptions([]);
1660                                                                                         renderer.has_entry = true;
1661                                                                                     } else {
1662                                                                                         LeftPanel.editableColumn.setOptions(opts);
1663                                                                                         renderer.has_entry = false;
1664                                                                                     }
1665                                                                                     
1666                                                                                     
1667                                                                                    //Seed.print("click" + ev.type);
1668                                                                                     //console.dump(res);
1669                                                                                     return false;
1670                                                                                 }
1671                                                                               
1672                                                                             
1673                                                                                
1674                                                                                 if (res.column.title == 'value') {
1675                                                                                     return false;
1676                                                                                 }
1677                                                                                 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1678                                                                                 var p = this.get('/LeftPanelPopup');
1679                                                                                 if (!p.el) {
1680                                                                                         p.init();
1681                                                                                 }
1682                                                                 
1683                                                                                 p.el.set_screen(Gdk.Screen.get_default());
1684                                                                                 p.el.show_all();
1685                                                                                 p.el.popup(null, null, null, null, 3, ev.button.time);
1686                                                                                 //Seed.print("click:" + res.column.title);
1687                                                                                 
1688                                                                                 
1689                                                                                 return false;
1690                                                                 }
1691                                                             },
1692                                                             items : [
1693                                                                 {
1694                                                                     xtype: Gtk.TreeStore,
1695                                                                     pack : "set_model",
1696                                                                     id : "model",
1697                                                                     init : function() {
1698                                                                         XObject.prototype.init.call(this);
1699                                                                     this.el.set_column_types ( 5, [
1700                                                                                                     GObject.TYPE_STRING,  // 0 real key
1701                                                                                                     GObject.TYPE_STRING, // 1 real value 
1702                                                                                                      GObject.TYPE_STRING,  // 2 visable key
1703                                                                                                      GObject.TYPE_STRING, // 3 visable value
1704                                                                                                      GObject.TYPE_STRING, // 4 need to store type of!!!
1705                                                                                                   
1706                                                                                                 ]);
1707                                                                     },
1708                                                                     toShort : function(str) {
1709                                                                         var a = typeof(str) == 'string' ? str.split("\n") : [];
1710                                                                             return a.length > 1 ? a[0] + '....' : '' + str;
1711                                                                     },
1712                                                                     load : function(ar) {
1713                                                                          this.el.clear();
1714                                                                                                 
1715                                                                                 this.get('/RightEditor').el.hide();
1716                                                                                 if (ar === false) {
1717                                                                                     return ;
1718                                                                                 }
1719                                                                                 var ret = {}; 
1720                                                                                 
1721                                                                     
1722                                                                                 var provider = this.get('/LeftTree').getPaleteProvider();
1723                                                                                 
1724                                                                                 // sort!!!?
1725                                                                                 var iter = new Gtk.TreeIter();
1726                                                                                 for (var i in ar) {
1727                                                                                     if (typeof(ar[i]) == 'object') {
1728                                                                                         continue;
1729                                                                                     }
1730                                                                                     
1731                                                                                     var type = provider.findType(ar, i, ar[i]);
1732                                                                                     
1733                                                                                     this.el.append(iter);
1734                                                                                     var p = this.el.get_path(iter).to_string();
1735                                                                                     ret[i] = p;
1736                                                                                     this.el.set_value(iter, 0, i);
1737                                                                                     this.el.set_value(iter, 1, '' + ar[i]);
1738                                                                                     this.el.set_value(iter, 2, i);
1739                                                                                     this.el.set_value(iter, 3, this.toShort(ar[i]));
1740                                                                                     this.el.set_value(iter, 4, type);
1741                                                                                 }
1742                                                                                 ar.listeners = ar.listeners || {};
1743                                                                                 for (var i in ar.listeners ) {
1744                                                                                     this.el.append(iter);
1745                                                                                     var p = this.el.get_path(iter).to_string();
1746                                                                                     ret['!' + i] = p;
1747                                                                                     
1748                                                                                     this.el.set_value(iter, 0, '!'+  i  );
1749                                                                                     this.el.set_value(iter, 1, '' + ar.listeners[i]);
1750                                                                                     this.el.set_value(iter, 2, '<b>'+ i + '</b>');
1751                                                                                     
1752                                                                                     this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
1753                                                                                     this.el.set_value(iter, 4, 'function');
1754                                                                                 }
1755                                                                                 return ret;
1756                                                                     },
1757                                                                     add : function(info) {
1758                                                                           // info includes key, val, skel, etype..
1759                                                                                                  console.dump(info);
1760                                                                                 type = info.type.toLowerCase();
1761                                                                                 var data = this.toJS();
1762                                                                                 
1763                                                                                 if (info.etype == 'events') {
1764                                                                                     data.listeners = data.listeners || { };
1765                                                                                     if (typeof(data.listeners[info.key]) != 'undefined') {
1766                                                                                         return; //already set!
1767                                                                                     }
1768                                                                                 } else {
1769                                                                                     if (typeof(data[info.key]) != 'undefined') {
1770                                                                                         return;
1771                                                                                     }
1772                                                                                 }
1773                                                                                 
1774                                                                                 if (typeof(info.val) == 'undefined') {
1775                                                                                         
1776                                                                                     info.val = '';
1777                                                                                     if (info.type == 'boolean') {
1778                                                                                         info.val = true;
1779                                                                                     }
1780                                                                                     if (type == 'number') {
1781                                                                                         info.val = 0;
1782                                                                                     }
1783                                                                                     // utf8 == string..
1784                                                                                     
1785                                                                                     
1786                                                                                 }
1787                                                                                 var k = info.key;
1788                                                                                 if (info.etype == 'events') {
1789                                                                                  
1790                                                                                     data.listeners[info.key] = info.val;
1791                                                                                     k = '!' + info.key;
1792                                                                                 } else {
1793                                                                                     data[info.key] = info.val;
1794                                                                                 }
1795                                                                                 
1796                                                                                 
1797                                                                                 var map = this.load(data);
1798                                                                                 
1799                                                                                 // flag it as changed to the interface..
1800                                                                     
1801                                                                                 this.get('/LeftTree.model').changed(data, true); 
1802                                                                                 
1803                                                                                 
1804                                                                                 this.startEditing(map[k]);
1805                                                                                  
1806                                                                                 /*
1807                                                                                 LeftPanel.get('view').el.row_activated(
1808                                                                                     new Gtk.TreePath.from_string(map[k]), 
1809                                                                                     LeftPanel.editableColumn.el
1810                                                                                 );
1811                                                                                 */
1812                                                                     },
1813                                                                     startEditing : function(path,col) {
1814                                                                     /**
1815                                                                     * start editing path (or selected if not set..)
1816                                                                     * @param {String|false} path  (optional) treepath to edit - selected tree gets
1817                                                                     *     edited by default.
1818                                                                     * @param {Number} 0 or 1 (optional)- column to edit. 
1819                                                                     */
1820                                                                          var tp;
1821                                                                                 if (typeof(path) == 'string') {
1822                                                                                     tp = new Gtk.TreePath.from_string(path);
1823                                                                                 } else {
1824                                                                                     var iter = new Gtk.TreeIter();
1825                                                                                     var s = this.get('/LeftPanel.view').selection;
1826                                                                                     s.get_selected(this.el, iter);
1827                                                                                     tp = this.el.get_path(iter);
1828                                                                                     path = tp.to_string();
1829                                                                                 }
1830                                                                                 
1831                                                                                
1832                                                                                 // which colum is to be edited..
1833                                                                                 var colObj = false;
1834                                                                                 if (typeof(col) == 'undefined') {
1835                                                                                     var k = this.getValue(path, 0);
1836                                                                                     colObj = (!k.length || k == '|') ? 
1837                                                                                         this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
1838                                                                                 } else {
1839                                                                                     colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
1840                                                                                 }
1841                                                                                 
1842                                                                                 // make sure the pulldown is set correctly..
1843                                                                                 // not really needed for second col...
1844                                                                     
1845                                                                                 var provider = this.get('/LeftTree').getPaleteProvider();
1846                                                                                
1847                                                                                 var type = this.get('/LeftPanel.model').getType(path);
1848                                                                                 var opts = provider.findOptions(type);
1849                                                                                 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
1850                                                                                 
1851                                                                                 if (opts === false) {
1852                                                                                     this.get('/LeftPanel').editableColumn.setOptions([]);
1853                                                                                     renderer.has_entry = true; /// probably does not have any effect.
1854                                                                                 } else {
1855                                                                                     this.get('/LeftPanel').editableColumn.setOptions(opts);
1856                                                                                     renderer.has_entry = false;
1857                                                                                 }
1858                                                                                 
1859                                                                                 var _this=this;
1860                                                                                 // iter now has row...
1861                                                                                 GLib.timeout_add(0, 100, function() {
1862                                                                                     
1863                                                                                     colObj.items[0].el.editable = true; // esp. need for col 0..
1864                                                                                     _this.get('/LeftPanel.view').el.set_cursor_on_cell(
1865                                                                                         tp,
1866                                                                                         colObj.el,
1867                                                                                         colObj.items[0].el,
1868                                                                                         true
1869                                                                                     );
1870                                                                                 });
1871                                                                                 
1872                                                                     },
1873                                                                     deleteSelected : function() {
1874                                                                          var data = this.toJS();
1875                                                                         var iter = new Gtk.TreeIter();
1876                                                                         var s = this.get('/LeftPanel.view').selection;
1877                                                                         s.get_selected(this.el, iter);
1878                                                                              
1879                                                                            
1880                                                                         var gval = new GObject.Value('');
1881                                                                        this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
1882                                                                         
1883                                                                         var val = gval.value;
1884                                                                         if (val[0] == '!') {
1885                                                                             // listener..
1886                                                                             if (!data.listeners || typeof(data.listeners[  val.substring(1)]) == 'undefined') {
1887                                                                                 return;
1888                                                                             }
1889                                                                             delete data.listeners[  val.substring(1)];
1890                                                                             if (!XObject.keys(data.listeners).length) {
1891                                                                                 delete data.listeners;
1892                                                                             }
1893                                                                             
1894                                                                         } else {
1895                                                                             if (typeof(data[val]) == 'undefined') {
1896                                                                                 return;
1897                                                                             }
1898                                                                             delete data[val];
1899                                                                         }
1900                                                                         
1901                                                                         
1902                                                                         this.load(data);
1903                                                                         this.get('/LeftTree.model').changed(data, true);
1904                                                                         
1905                                                                     },
1906                                                                     activePath : false,
1907                                                                     changed : function(str, doRefresh) {
1908                                                                         if (!this.activePath) {
1909                                                                             return;
1910                                                                         }
1911                                                                         var iter = new Gtk.TreeIter();
1912                                                                         this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
1913                                                                         
1914                                                                         this.el.set_value(iter, 1, '' +str);
1915                                                                         this.el.set_value(iter, 3, '' + this.toShort(str));
1916                                                                         // update the tree...  
1917                                                                     
1918                                                                         this.get('/LeftTree.model').changed(this.toJS(), doRefresh); 
1919                                                                     },
1920                                                                     toJS : function() {
1921                                                                          var iter = new Gtk.TreeIter();
1922                                                                         this.get('/LeftPanel.model').el.get_iter_first(iter);
1923                                                                         var ar = {};
1924                                                                            
1925                                                                         while (true) {
1926                                                                             
1927                                                                             var k = this.getValue(this.el.get_path(iter).to_string(), 0);
1928                                                                            // Seed.print(k);
1929                                                                             if (k[0] == '!') {
1930                                                                                 ar.listeners = ar.listeners || {};
1931                                                                                 ar.listeners[  k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
1932                                                                                 
1933                                                                             } else {
1934                                                                                 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
1935                                                                             }
1936                                                                             
1937                                                                             if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
1938                                                                                 break;
1939                                                                             }
1940                                                                         }
1941                                                                         
1942                                                                         
1943                                                                         //print(JSON.stringify(ar));
1944                                                                         return ar;
1945                                                                         // convert the l
1946                                                                     },
1947                                                                     getType : function(treepath) {
1948                                                                          return this.getValue(treepath, 4);
1949                                                                     },
1950                                                                     getValue : function(treepath_str, col) {
1951                                                                           var iter = new Gtk.TreeIter();
1952                                                                         this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
1953                                                                         
1954                                                                         var gval = new GObject.Value('');
1955                                                                         this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1956                                                                         var val = '' + gval.value;
1957                                                                         if (col != 1) {
1958                                                                             return val;
1959                                                                         }
1960                                                                         var type = this.getType(this.el.get_path(iter).to_string());
1961                                                                         //print("TYPE: " +type + " -  val:" + val);
1962                                                                         switch(type.toLowerCase()) {
1963                                                                             case 'number':
1964                                                                             case 'uint':
1965                                                                             case 'int':
1966                                                                                 return parseFloat(val); // Nan ?? invalid!!?
1967                                                                             case 'boolean':
1968                                                                                 return val == 'true' ? true : false;
1969                                                                             default: 
1970                                                                                 return val;
1971                                                                         }
1972                                                                                                 
1973                                                                     },
1974                                                                     editSelected : function(e) {
1975                                                                         print("EDIT SELECTED?");
1976                                                                                 var iter = new Gtk.TreeIter();
1977                                                                                 var s = this.get('/LeftPanel.view').selection;
1978                                                                                 s.get_selected(this.get('/LeftPanel.model').el, iter);
1979                                                                                 var m = this.get('/LeftPanel.model')
1980                                                                                
1981                                                                                 var gval = new GObject.Value('');
1982                                                                                 this.el.get_value(iter, 0 ,gval);
1983                                                                                 var val = '' + gval.value;
1984                                                                                 
1985                                                                                 gval = new GObject.Value('');
1986                                                                                 this.el.get_value(iter, 1 ,gval);
1987                                                                                 var rval = gval.value;
1988                                                                                 var activePath = this.el.get_path(iter).to_string(); 
1989                                                                                 this.activePath = activePath ;
1990                                                                                 // was activeIter...
1991                                                                                 //  not listener...
1992                                                                                 
1993                                                                                 var showEditor = false;
1994                                                                                 
1995                                                                                 if (val[0] == '!') {
1996                                                                                     showEditor = true;
1997                                                                                 }
1998                                                                                 if (val[0] == '|') {
1999                                                                                     if (rval.match(/function/g) || rval.match(/\n/g)) {
2000                                                                                         showEditor = true;
2001                                                                                     }
2002                                                                                 }
2003                                                                                 
2004                                                                                 if (showEditor) {
2005                                                                                     var _this = this;
2006                                                                                     this.activePath = false;
2007                                                                                     GLib.timeout_add(0, 1, function() {
2008                                                                                         //   Gdk.threads_enter();
2009                                                                                         _this.get('/RightEditor').el.show();
2010                                                                                    _this.get('/RightEditor.view').load( rval );
2011                                                                                         
2012                                                                                         e.editing_done();
2013                                                                                         e.remove_widget();
2014                                                                                         _this.activePath = activePath ;
2015                                                                                         
2016                                                                                  //       Gdk.threads_leave();
2017                                                                                         return false;
2018                                                                                     });
2019                                                                                     return;
2020                                                                                 }
2021                                                                                  
2022                                                                                 this.get('/RightEditor').el.hide();
2023                                                                     
2024                                                                                 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2025                                                                                 
2026                                                                                 
2027                                                                     }
2028                                                                 },
2029                                                                 {
2030                                                                     xtype: Gtk.TreeViewColumn,
2031                                                                     pack : "append_column",
2032                                                                     init : function() {
2033                                                                         XObject.prototype.init.call(this);
2034                                                                     
2035                                                                         this.el.add_attribute(this.items[0].el , 'markup', 2 );
2036                                                                         this.get('/LeftPanel').propertyColumn = this;
2037                                                                     },
2038                                                                     title : "key",
2039                                                                     items : [
2040                                                                         {
2041                                                                             xtype: Gtk.CellRendererText,
2042                                                                             pack : "pack_start",
2043                                                                             listeners : {
2044                                                                                 "editing_started":function (self, editable, path) {
2045                                                                                 
2046                                                                                         this.get('/LeftPanel.model').activePath  = path;
2047                                                                                 
2048                                                                                 },
2049                                                                                 "edited":function (self, object, p0) {
2050                                                                                         var model = this.get('/LeftPanel.model');
2051                                                                                         var path = model.activePath;
2052                                                                                         var iter = new Gtk.TreeIter();
2053                                                                                         model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2054                                                                                         model.el.set_value(iter, 0, p0);
2055                                                                                         model.el.set_value(iter, 2, p0);
2056                                                                                         
2057                                                                                         model.activePath = false;
2058                                                                                 
2059                                                                                         this.get('/LeftTree.model').changed(model.toJS(), true); 
2060                                                                                         this.el.editable = false;
2061                                                                                 }
2062                                                                             }
2063                                                                         }
2064                                                                     ]
2065                                                                 },
2066                                                                 {
2067                                                                     xtype: Gtk.TreeViewColumn,
2068                                                                     pack : "append_column",
2069                                                                     init : function() {
2070                                                                         XObject.prototype.init.call(this);
2071                                                                         this.el.add_attribute(this.items[0].el , 'text', 3 );
2072                                                                         this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2073                                                                         this.el.add_attribute(this.items[0].el , 'editable', 3 );
2074                                                                               // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2075                                                                     
2076                                                                         this.get('/LeftPanel').editableColumn= this;
2077                                                                     },
2078                                                                     setOptions : function(ar) {
2079                                                                            var m = this.items[0].el.model;
2080                                                                                 m.clear();
2081                                                                                 var iter = new Gtk.TreeIter();
2082                                                                                 ar.forEach(function(i) {
2083                                                                                        // sort!!!?
2084                                                                                     m.append(iter);
2085                                                                                     m.set_value(iter, 0, i);
2086                                                                                 });
2087                                                                                 
2088                                                                     },
2089                                                                     items : [
2090                                                                         {
2091                                                                             xtype: Gtk.CellRendererCombo,
2092                                                                             pack : "pack_start",
2093                                                                             editable : true,
2094                                                                             has_entry : true,
2095                                                                             text_column : 0,
2096                                                                             init : function() {
2097                                                                                 XObject.prototype.init.call(this);
2098                                                                                this.el.model = new Gtk.ListStore();
2099                                                                                 this.el.model.set_column_types ( 1, [
2100                                                                                     GObject.TYPE_STRING  // 0 real key
2101                                                                                   ]);
2102                                                                             },
2103                                                                             listeners : {
2104                                                                                 "edited":function (self, object, p0) {
2105                                                                                         this.get('/LeftPanel').editing = false;
2106                                                                                         print("EDITED? p:" + p0 + " t:" + p0);
2107                                                                                         this.get('/LeftPanel.model').changed(p0, true);
2108                                                                                         this.get('/LeftPanel.model').activePath = false;
2109                                                                                 },
2110                                                                                 "editing_started":function (self, editable, path) {
2111                                                                                    this.get('/LeftPanel').editing  = true;
2112                                                                                         //  console.log('editing started');
2113                                                                                        // r.has_entry = false;
2114                                                                                    this.get('/LeftPanel.model').editSelected(editable);
2115                                                                                 }
2116                                                                             }
2117                                                                         }
2118                                                                     ]
2119                                                                 }
2120                                                             ]
2121                                                         },
2122                                                         {
2123                                                             xtype: Gtk.Menu,
2124                                                             pack : false,
2125                                                             id : "LeftPanelPopup",
2126                                                             items : [
2127                                                                 {
2128                                                                     xtype: Gtk.MenuItem,
2129                                                                     pack : "append",
2130                                                                     label : "Delete",
2131                                                                     listeners : {
2132                                                                         "activate":function (self) {
2133                                                                                 this.get('/LeftPanel.model').deleteSelected();
2134                                                                         }
2135                                                                     }
2136                                                                 },
2137                                                                 {
2138                                                                     xtype: Gtk.MenuItem,
2139                                                                     pack : "append",
2140                                                                     label : "Edit",
2141                                                                     listeners : {
2142                                                                         "activate":function (self) {
2143                                                                                 this.get('/LeftPanel.model').startEditing(false, 0);
2144                                                                         }
2145                                                                     }
2146                                                                 }
2147                                                             ]
2148                                                         }
2149                                                     ]
2150                                                 }
2151                                             ]
2152                                         }
2153                                     ]
2154                                 },
2155                                 {
2156                                     xtype: Gtk.ScrolledWindow,
2157                                     pack : "pack_end,false,true,0",
2158                                     id : "MidPropTree",
2159                                     shadow_type : Gtk.ShadowType.IN,
2160                                     init : function() {
2161                                         XObject.prototype.init.call(this);
2162                                            XObject.prototype.init.call(this); 
2163                                         this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2164                                         this.el.set_size_request ( 150, -1 );
2165                                         this.shown = true;
2166                                     },
2167                                     activeElement : false,
2168                                     hideWin : function() {
2169                                          
2170                                         if (!this.shown) {
2171                                             return;
2172                                         }
2173                                         
2174                                         
2175                                         if (this.get('/Window.left').el.position < 160) {
2176                                             return;
2177                                         }
2178                                         this.get('/Window.left').el.position = this.get('/Window.left').el.position  - 150;
2179                                             
2180                                         this.el.hide();
2181                                         this.shown = false;
2182                                     },
2183                                     items : [
2184                                         {
2185                                             xtype: Gtk.TreeView,
2186                                             enable_tree_lines : true,
2187                                             headers_visible : false,
2188                                             tooltip_column : 2,
2189                                             init : function() {
2190                                                 XObject.prototype.init.call(this); 
2191                                                                 
2192                                                    var description = new Pango.FontDescription.c_new();
2193                                                  description.set_size(8000);
2194                                                 this.el.modify_font(description);     
2195                                                                 
2196                                                 //this.selection = this.el.get_selection();
2197                                                 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2198                                              
2199                                             
2200                                                 
2201                                               
2202                                                 
2203                                             },
2204                                             pack : "add",
2205                                             listeners : {
2206                                                 "cursor_changed":function (self) {
2207                                                        var iter = new Gtk.TreeIter();
2208                                                                         
2209                                                                         //console.log('changed');
2210                                                         var m = this.get('model');
2211                                                         if (!this.selection){
2212                                                                 this.selection = this.el.get_selection();
2213                                                         }
2214                                                 
2215                                                         var s = this.selection;
2216                                                         if (!s.get_selected(m.el, iter)) {
2217                                                                 return; 
2218                                                         }
2219                                                         var tp = m.el.get_path(iter).to_string();
2220                                                         
2221                                                         
2222                                                         // var val = "";
2223                                                         
2224                                                         var key = m.getValue(tp, 0);
2225                                                         
2226                                                         var type = m.getValue(tp, 1);
2227                                                         var skel = m.getValue(tp, 3);
2228                                                         var etype = m.getValue(tp, 5);
2229                                                         
2230                                                         
2231                                                         this.get('/MidPropTree').hideWin();
2232                                                 
2233                                                         if (type == 'function') {
2234                                                             
2235                                                             if (etype != 'events') {
2236                                                                 key = '|' + key;
2237                                                             }
2238                                                             
2239                                                             this.get('/LeftPanel.model').add({
2240                                                                 key :  key, 
2241                                                                 type : type,
2242                                                                 val  : skel,
2243                                                                 etype : etype
2244                                                             })  
2245                                                             return;
2246                                                         }
2247                                                         
2248                                                         if (type.indexOf('.') > -1 || 
2249                                                                 type == 'boolean') {
2250                                                              key = '|' + key;
2251                                                         }
2252                                                         
2253                                                         this.get('/LeftPanel.model').add( {
2254                                                             key : key, 
2255                                                             type : type,
2256                                                             //skel  : skel,
2257                                                             etype : etype
2258                                                            }) //, 
2259                                                 }
2260                                             },
2261                                             items : [
2262                                                 {
2263                                                     xtype: Gtk.ListStore,
2264                                                     pack : "set_model",
2265                                                     init : function() {
2266                                                         XObject.prototype.init.call(this);
2267                                                        this.el.set_column_types ( 6, [
2268                                                             GObject.TYPE_STRING,  // real key
2269                                                              GObject.TYPE_STRING, // real type
2270                                                              GObject.TYPE_STRING, // docs ?
2271                                                              GObject.TYPE_STRING, // visable desc
2272                                                              GObject.TYPE_STRING, // function desc
2273                                                              GObject.TYPE_STRING // element type (event|prop)
2274                                                             
2275                                                         ] );
2276                                                     },
2277                                                     getValue : function(treepath, col)
2278                                                     {
2279                                                         var tp = new Gtk.TreePath.from_string (treepath);
2280                                                         var iter = new Gtk.TreeIter();
2281                                                         this.el.get_iter (iter, tp);
2282                                                         var value = new GObject.Value('');
2283                                                         this.el.get_value(iter, col, value);
2284                                                         return value.value;
2285                                                         
2286                                                     },
2287                                                     showData : function(type) {
2288                                                         this.el.clear();
2289                                                                 if (!this.get('/MidPropTree').activeElement || !type) {
2290                                                                     return; // no active element
2291                                                                 }
2292                                                     
2293                                                                 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2294                                                                 var palete = this.get('/LeftTree').getPaleteProvider();
2295                                                                 
2296                                                                  
2297                                                                 
2298                                                                 Seed.print('Showing right?');
2299                                                                 if (!this.get('/MidPropTree').shown) {
2300                                                     
2301                                                                     this.get('/Window.left').el.position = this.get('/Window.left').el.position  + 150;
2302                                                                     this.get('/MidPropTree').el.show();
2303                                                                     this.get('/MidPropTree').shown = true;
2304                                                                 }
2305                                                                 
2306                                                                 var elementList = palete.getPropertiesFor(fullpath, type);
2307                                                                 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2308                                                                // console.dump(elementList);
2309                                                                
2310                                                                 
2311                                                                 var iter = new Gtk.TreeIter();
2312                                                                 for(var i =0 ; i < elementList.length; i++) {
2313                                                                     var p=elementList[i];
2314                                                                     this.el.append(iter);
2315                                                                   //  console.log( '<b>' + p.name +'</b> ['+p.type+']');
2316                                                                         //GObject.TYPE_STRING,  // real key
2317                                                                         // GObject.TYPE_STRING, // real type
2318                                                                         // GObject.TYPE_STRING, // docs ?
2319                                                                         // GObject.TYPE_STRING // func def?
2320                                                                         
2321                                                                     
2322                                                                     this.el.set_value(iter, 0, p.name);
2323                                                                     this.el.set_value(iter, 1, p.type);
2324                                                                     this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2325                                                                     this.el.set_value(iter, 3, p.sig ? p.sig  : '');
2326                                                                     this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2327                                                                     this.el.set_value(iter, 5, type);
2328                                                                     
2329                                                                 }
2330                                                                                  
2331                                                     },
2332                                                     id : "model"
2333                                                 },
2334                                                 {
2335                                                     xtype: Gtk.TreeViewColumn,
2336                                                     init : function() {
2337                                                         this.el = new Gtk.TreeViewColumn();
2338                                                         this.parent.el.append_column(this.el);
2339                                                         
2340                                                         XObject.prototype.init.call(this);
2341                                                         this.el.add_attribute(this.items[0].el , 'markup', 4  );
2342                                                     },
2343                                                     pack : false,
2344                                                     items : [
2345                                                         {
2346                                                             xtype: Gtk.CellRendererText,
2347                                                             pack : "pack_start,true"
2348                                                         }
2349                                                     ]
2350                                                 }
2351                                             ]
2352                                         }
2353                                     ]
2354                                 }
2355                             ]
2356                         },
2357                         {
2358                             xtype: Gtk.HBox,
2359                             pack : "add",
2360                             items : [
2361                                 {
2362                                     xtype: Gtk.VPaned,
2363                                     pack : "add",
2364                                     position : 300,
2365                                     items : [
2366                                         {
2367                                             xtype: Gtk.VBox,
2368                                             pack : "add",
2369                                             items : [
2370                                                 {
2371                                                     xtype: Gtk.Notebook,
2372                                                     pack : "pack_start,true,true",
2373                                                     id : "view-notebook",
2374                                                     tab_border : 0,
2375                                                     init : function() {
2376                                                         XObject.prototype.init.call(this);
2377                                                         this.el.set_current_page(0);
2378                                                         print("SET LABEL?")
2379                                                         this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2380                                                         this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2381                                                     },
2382                                                     show_tabs : false,
2383                                                     items : [
2384                                                         {
2385                                                             xtype: Gtk.VBox,
2386                                                             pack : "add",
2387                                                             id : "RightBrowser",
2388                                                             items : [
2389                                                                 {
2390                                                                     xtype: Gtk.HBox,
2391                                                                     pack : "pack_start,false,true,0",
2392                                                                     items : [
2393                                                                         {
2394                                                                             xtype: Gtk.Button,
2395                                                                             pack : "pack_start,false,false,0",
2396                                                                             label : "Dump HTML to console",
2397                                                                             listeners : {
2398                                                                                 "activate":function (self) {
2399                                                                                         this.get('/RightBrowser.view').el.execute_script(
2400                                                                                             "console.log(document.body.innerHTML);");
2401                                                                                         this.get('/RightBrowser.view').el.execute_script(
2402                                                                                             "console.log(Builder.dump(Builder));");   
2403                                                                                 }
2404                                                                             }
2405                                                                         }
2406                                                                     ]
2407                                                                 },
2408                                                                 {
2409                                                                     xtype: Gtk.ScrolledWindow,
2410                                                                     pack : "add",
2411                                                                     shadow_type : Gtk.ShadowType.IN,
2412                                                                     init : function() {
2413                                                                         XObject.prototype.init.call(this);
2414                                                                       this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2415                                                                     },
2416                                                                     items : [
2417                                                                         {
2418                                                                             xtype: WebKit.WebView,
2419                                                                             pack : "add",
2420                                                                             id : "view",
2421                                                                             init : function() {
2422                                                                                 XObject.prototype.init.call(this);
2423                                                                                 // this may not work!?
2424                                                                                 this.el.open('file:///' + __script_path__ + '/../builder.html');
2425                                                                                                         
2426                                                                                 Gtk.drag_dest_set
2427                                                                                 (
2428                                                                                         this.el,              /* widget that will accept a drop */
2429                                                                                         Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
2430                                                                                         null,            /* lists of target to support */
2431                                                                                         0,              /* size of list */
2432                                                                                         Gdk.DragAction.COPY         /* what to do with data after dropped */
2433                                                                                 );
2434                                                                                                         
2435                                                                                // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2436                                                                                 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2437                                                                             },
2438                                                                             renderJS : function(data) {
2439                                                                                 this.renderedData = data;
2440                                                                                 var str = JSON.stringify(data) ;
2441                                                                                 
2442                                                                                 if (!this.ready) {
2443                                                                                     console.log('not loaded yet');
2444                                                                                 }
2445                                                                                 Seed.print("RENDER:" + str);
2446                                                                                 imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2447                                                                                 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2448                                                                             },
2449                                                                             listeners : {
2450                                                                                 "load_finished":function (self, object) {
2451                                                                                          if (this.ready) { // dont do it twice!
2452                                                                                             return; 
2453                                                                                         }
2454                                                                                         this.ready = true;
2455                                                                                 
2456                                                                                         this.renderJS(this.get('/LeftTree.model').toJS()[0]);
2457                                                                                 },
2458                                                                                 "script_alert":function (self, object, p0) {
2459                                                                                         print(p0);
2460                                                                                         return false;
2461                                                                                         return true; // do not display anything...
2462                                                                                 },
2463                                                                                 "console_message":function (self, object, p0, p1) {
2464                                                                                      console.log(object);
2465                                                                                         if (!object.match(/^\{/)) {
2466                                                                                             return false; // do not handle!!! -> later maybe in console..
2467                                                                                         }
2468                                                                                         console.log(object);
2469                                                                                         var val =  JSON.parse(object);
2470                                                                                 
2471                                                                                         if (typeof(val['hover-node']) != 'undefined') {
2472                                                                                             this.activeNode = val['hover-node'];
2473                                                                                             console.log('active node: ' + this.activeNode);
2474                                                                                             return true;
2475                                                                                         }
2476                                                                                 
2477                                                                                          var ret = false;
2478                                                                                          if (typeof(val['id']) != 'undefined') {
2479                                                                                            // this.activeNode = val['id'];
2480                                                                                             var tg = this.get('/LeftTree.model').findDropNode(val['id'], true); 
2481                                                                                             if (!tg) {
2482                                                                                                 return false;
2483                                                                                             }
2484                                                                                             this.get('/LeftTree.view').selectNode(tg[0]);
2485                                                                                             ret  = true;
2486                                                                                             
2487                                                                                         } 
2488                                                                                         if (ret && typeof(val['set']) != 'undefined') {
2489                                                                                            this.get('/LeftPanel.model').add({
2490                                                                                                 key : val['set'],
2491                                                                                                 val : val['value']
2492                                                                                             });
2493                                                                                             //console.log('active node: ' + this.activeNode);
2494                                                                                             
2495                                                                                         }
2496                                                                                         //Seed.print('a:'+a);
2497                                                                                         //Seed.print('b:'+b);
2498                                                                                         //Seed.print('c:'+c);
2499                                                                                         return ret;
2500                                                                                 },
2501                                                                                 "drag_motion":function (w, ctx,  x,   y,   time, ud) {
2502                                                                                    // console.log('DRAG MOTION'); 
2503                                                                                         // status:
2504                                                                                         // if lastCurrentNode == this.currentNode.. -- don't change anything..
2505                                                                                         this.targetData = [];
2506                                                                                         this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2507                                                                                         
2508                                                                                         // A) find out from drag all the places that node could be dropped.
2509                                                                                         var src = Gtk.drag_get_source_widget(ctx);
2510                                                                                         if (!src.dropList) {
2511                                                                                             Gdk.drag_status(ctx, 0, time);
2512                                                                                             return true;
2513                                                                                         }
2514                                                                                         // b) get what we are over.. (from activeNode)
2515                                                                                         // tree is empty.. - list should be correct..
2516                                                                                         if (!this.get('/LeftTree.model').currentTree) {
2517                                                                                             Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2518                                                                                             return true;
2519                                                                                             
2520                                                                                         }
2521                                                                                         // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2522                                                                                         
2523                                                                                         var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2524                                                                                         console.dump(tg);
2525                                                                                         if (!tg.length) {
2526                                                                                             Gdk.drag_status(ctx, 0,time);
2527                                                                                             this.get('/LeftTree.view').highlight(false);
2528                                                                                             return true;
2529                                                                                         }
2530                                                                                          
2531                                                                                         // if we have a target..
2532                                                                                         // -> highlight it! (in browser)
2533                                                                                         // -> highlight it! (in tree)
2534                                                                                         
2535                                                                                         Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2536                                                                                         this.get('/LeftTree.view').highlight(tg);
2537                                                                                         this.targetData = tg;
2538                                                                                         // for tree we should handle this...
2539                                                                                         return true;
2540                                                                                 },
2541                                                                                 "drag_drop":function (w, ctx, x, y,time, ud) {
2542                                                                                         print("TARGET: drag-drop");
2543                                                                                         var is_valid_drop_site = true;
2544                                                                                         
2545                                                                                          
2546                                                                                         Gtk.drag_get_data
2547                                                                                         (
2548                                                                                                 w,         /* will receive 'drag-data-received' signal */
2549                                                                                                 ctx,        /* represents the current state of the DnD */
2550                                                                                                 this.get('/Window').atoms["STRING"],    /* the target type we want */
2551                                                                                                 time            /* time stamp */
2552                                                                                         );
2553                                                                                                         
2554                                                                                                         
2555                                                                                                         /* No target offered by source => error */
2556                                                                                                        
2557                                                                                 
2558                                                                                         return  is_valid_drop_site;
2559                                                                                 },
2560                                                                                 "drag_data_received":function (w, ctx,  x,  y, sel_data,  target_type,  time, ud) 
2561                                                                                     {
2562                                                                                         print("Browser: drag-data-received");
2563                                                                                         var delete_selection_data = false;
2564                                                                                         vardnd_success = false;
2565                                                                                         /* Deal with what we are given from source */
2566                                                                                         if( sel_data && sel_data.length ) {
2567                                                                                             
2568                                                                                             if (ctx.action == Gdk.DragAction.ASK)  {
2569                                                                                                 /* Ask the user to move or copy, then set the ctx action. */
2570                                                                                             }
2571                                                                                 
2572                                                                                             if (ctx.action == Gdk.DragAction.MOVE) {
2573                                                                                                 delete_selection_data = true;
2574                                                                                             }
2575                                                                                             var source = Gtk.drag_get_source_widget(ctx);
2576                                                                                 
2577                                                                                             print("Browser: source.DRAGDATA? " + source.dragData);
2578                                                                                             if (this.targetData) {
2579                                                                                                 print(this.targetData);
2580                                                                                                 this.get('/LeftTree.model').dropNode(this.targetData,  source.dragData);
2581                                                                                             }
2582                                                                                             
2583                                                                                             
2584                                                                                             
2585                                                                                             dnd_success = true;
2586                                                                                 
2587                                                                                         }
2588                                                                                 
2589                                                                                         if (dnd_success == false)
2590                                                                                         {
2591                                                                                                 Seed.print ("DnD data transfer failed!\n");
2592                                                                                         }
2593                                                                                         
2594                                                                                         Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2595                                                                                         return true;
2596                                                                                     }
2597                                                                             }
2598                                                                         }
2599                                                                     ]
2600                                                                 }
2601                                                             ]
2602                                                         },
2603                                                         {
2604                                                             xtype: Gtk.VBox,
2605                                                             pack : "add",
2606                                                             id : "RightGtkView",
2607                                                             renderJS : function(data, withDebug)
2608                                                             {
2609                                                                  if (!data) {
2610                                                                              return; 
2611                                                                 }
2612                                                                 this.withDebug = false;
2613                                                                 
2614                                                                 if (this.renderedEl) {
2615                                                                     this.get('view').el.remove(this.renderedEl);
2616                                                                     this.renderedEl.destroy();
2617                                                                     this.renderedEl = false;
2618                                                                 }
2619                                                                 
2620                                                                 var tree =  this.get('/LeftTree.model').toJS(false,true)[0];
2621                                                                 // in theory tree is actually window..  
2622                                                                try {
2623                                                                 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
2624                                                               } catch (e) {
2625                                                                  print(e.message);
2626                                                                 return;
2627                                                               }
2628                                                                 this.get('view').el.set_size_request(
2629                                                                     tree.default_width * 1 || 400, tree.default_height * 1 || 400
2630                                                                 ) ;
2631                                                                 
2632                                                                 this.renderedEl.set_size_request(
2633                                                                     tree.default_width || 600,
2634                                                                     tree.default_height || 400
2635                                                                 );
2636                                                                 this.get('view').el.show_all();
2637                                                                 
2638                                                                 
2639                                                                 
2640                                                             },
2641                                                             showInWindow : function() {
2642                                                               print("GET PROEJCT");
2643                                                                 var pr = this.get('/LeftProjectTree').getActiveProject();
2644                                                               
2645                                                                 console.log(pr.paths);
2646                                                                 return;
2647                                                             /*
2648                                                                  var src= this.buildJS(
2649                                                                         this.get('/LeftTree.model').toJS()[0], 
2650                                                                         true);
2651                                                                   // show term?? 
2652                                                             
2653                                                             
2654                                                                 //var x = new imports.sandbox.Context();
2655                                                                 //x.add_globals();
2656                                                                 //print(src);
2657                                                                 try {
2658                                                                     Seed.check_syntax('var e = ' + src);
2659                                                                     //x.eval(src);
2660                                                                 } catch( e) {
2661                                                                     this.get('/Terminal').feed(e.message || e.toString() + "\n");
2662                                                                     this.get('/Terminal').feed(console._dump(e)+"\n");
2663                                                                     if (e.line) {
2664                                                                         var lines = src.split("\n");
2665                                                                         var start = Math.max(0, e.line - 10);
2666                                                                         var end = Math.min(lines.length, e.line + 10);
2667                                                                         for (var i =start ; i < end; i++) {
2668                                                                             if (i == e.line) {
2669                                                                                 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
2670                                                                                 continue;
2671                                                                             }
2672                                                                             this.get('/Terminal').feed(lines[i] + "\n");
2673                                                                         }
2674                                                                         
2675                                                                     }
2676                                                                     
2677                                                                     return;
2678                                                                 }
2679                                                                  this.get('/BottomPane').el.set_current_page(1);
2680                                                                 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false); 
2681                                                                 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
2682                                                                 this.get('/Terminal').el.feed_child(cmd, cmd.length);
2683                                                                  /*
2684                                                                 var _top = x.get_global_object()._top;
2685                                                                 
2686                                                                 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
2687                                                                 _top.el.show_all();
2688                                                                 if (_top.el.popup) {
2689                                                                     _top.el.popup(null, null, null, null, 3, null);
2690                                                                 }
2691                                                             */
2692                                                             },
2693                                                             viewAdd : function(item, par)
2694                                                                     {
2695                                                                 // does something similar to xobject..
2696                                                                 item.pack = (typeof(item.pack) == 'undefined') ?  'add' : item.pack;
2697                                                                 
2698                                                                 if (item.pack===false || item.pack === 'false') {  // no ;
2699                                                                     return;
2700                                                                 }
2701                                                                 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
2702                                                                 var ns = imports.gi[item['|xns']];
2703                                                                 var ctr = ns[item['xtype']];
2704                                                                 var ctr_args = { };
2705                                                                 for(var k in item) {
2706                                                                     var kv = item[k];
2707                                                                     if (typeof(kv) == 'object' || typeof(kv) == 'function') {
2708                                                                         continue;
2709                                                                     }
2710                                                                     if ( 
2711                                                                         k == 'pack' ||
2712                                                                         k == 'items' ||
2713                                                                         k == 'id' ||
2714                                                                         k == 'xtype' ||
2715                                                                         k == 'xdebug' ||
2716                                                                         k == 'xns' ||
2717                                                                         k == '|xns'
2718                                                                     ) {
2719                                                                         continue;
2720                                                                     }
2721                                                             
2722                                                                 if (k[0] == '|' && typeof(kv) == 'string') {
2723                                                             
2724                                                                         if (kv.match(new RegExp('function'))) {
2725                                                                                 continue;
2726                                                                             }
2727                                                                          print("WASL " + k + '=' + kv);
2728                                                                         try {
2729                                                                                 eval( 'kv = ' + kv);
2730                                                                         } catch(e) {    continue; }
2731                                                                             
2732                                                                         k = k.substring(1);
2733                                                                           print(k + '=' + kv);
2734                                                                 }
2735                                                                     if (k[0] == '|') { // should be boolean or number..
2736                                                                         k = k.substring(1);
2737                                                                     }
2738                                                                 if (k == 'show_tabs') { // force tab showing for notebooks.
2739                                                                        kv = true;
2740                                                                     }
2741                                                                     ctr_args[k] = kv;
2742                                                                     
2743                                                                 } 
2744                                                                 
2745                                                                 
2746                                                                 var el = new ctr(ctr_args);
2747                                                                 
2748                                                                 //print("PACK");
2749                                                                 //console.dump(item.pack);
2750                                                                 
2751                                                                 
2752                                                                 
2753                                                                 
2754                                                                 var args = [];
2755                                                                 var pack_m  = false;
2756                                                                 if (typeof(item.pack) == 'string') {
2757                                                                      
2758                                                                     item.pack.split(',').forEach(function(e, i) {
2759                                                                         
2760                                                                         if (e == 'false') { args.push( false); return; }
2761                                                                         if (e == 'true') {  args.push( true);  return; }
2762                                                                         if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
2763                                                                         args.push(e);
2764                                                                     });
2765                                                                     //print(args.join(","));
2766                                                                     
2767                                                                     pack_m = args.shift();
2768                                                                 } else {
2769                                                                     pack_m = item.pack.shift();
2770                                                                     args = item.pack;
2771                                                                 }
2772                                                                 
2773                                                                 // handle error.
2774                                                                 if (pack_m && typeof(par[pack_m]) == 'undefined') {
2775                                                                     throw {
2776                                                                             name: "ArgumentError", 
2777                                                                             message : 'pack method not available : ' + par.id + " : " + par + '.' +  pack_m +
2778                                                                                     "ADDING : " + item.id + " " +  el
2779                                                                                 
2780                                                                     };
2781                                                             
2782                                                                     return;
2783                                                                 }
2784                                                                 
2785                                                                 console.dump(args);
2786                                                                 args.unshift(el);
2787                                                                 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
2788                                                                 //Seed.print('args: ' + args.length);
2789                                                                 if (pack_m) {
2790                                                                     par[pack_m].apply(par, args);
2791                                                                 }
2792                                                                 
2793                                                                 var _this = this;
2794                                                                 item.items = item.items || [];
2795                                                                 item.items.forEach(function(ch) {
2796                                                                     _this.viewAdd(ch, el);
2797                                                                 });
2798                                                                 
2799                                                                 
2800                                                                 
2801                                                                 // add the signal handlers.
2802                                                                 // is it a widget!?!!?
2803                                                                
2804                                                                 
2805                                                                 try {
2806                                                                      
2807                                                                     
2808                                                                     el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item  ], true));
2809                                                                     el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item  ], true));
2810                                                                     el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item  ], true));
2811                                                                     el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item  ], true ));
2812                                                               el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item  ], true ));
2813                                                                 } catch(e) {
2814                                                                     // ignore!
2815                                                                    }
2816                                                                 
2817                                                                 
2818                                                                 
2819                                                                 return el;
2820                                                                 
2821                                                             },
2822                                                             widgetExposeEvent : function() {
2823                                                                ///   print("WIDGET EXPOSE"); // draw highlight??
2824                                                                         return false;
2825                                                             },
2826                                                             widgetDragMotionEvent : function() {
2827                                                                  print("WIDGET DRAGMOTION"); 
2828                                                                         return true;
2829                                                             },
2830                                                             widgetDragDropEvent : function() {
2831                                                                   print("WIDGET DRAGDROP"); 
2832                                                                         return true;
2833                                                             },
2834                                                             widgetPressEvent : function(w,e,u,d) {
2835                                                                  if (this.get('view').pressed) {
2836                                                                     return false;
2837                                                                  }
2838                                                             this.get('view').pressed = true;
2839                                                                   print("WIDGET PRESS " + d.xtreepath );       
2840                                                                       this.get('/LeftTree.view').selectNode(   d.xtreepath );        
2841                                                                         return false;
2842                                                             },
2843                                                             widgetReleaseEvent : function() {
2844                                                                 this.get('view').pressed = false;
2845                                                                return false;
2846                                                             },
2847                                                             items : [
2848                                                                 {
2849                                                                     xtype: Gtk.HBox,
2850                                                                     pack : "pack_start,false,true,0",
2851                                                                     items : [
2852                                                                         {
2853                                                                             xtype: Gtk.Button,
2854                                                                             pack : "pack_start,false,false,0",
2855                                                                             label : "Run The Application",
2856                                                                             listeners : {
2857                                                                                 "button_press_event":function (self, event) {
2858                                                                                   // call render on left tree - with special option!?!
2859                                                                                  
2860                                                                                 
2861                                                                                 
2862                                                                                         print("GET PROEJCT");
2863                                                                                         var pr = this.get('/LeftProjectTree').getActiveProject();
2864                                                                                   
2865                                                                                 var dir = '';
2866                                                                                  for (var i in pr.paths) { 
2867                                                                                       dir = i;
2868                                                                                       break;
2869                                                                                   }
2870                                                                                    var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js'; 
2871                                                                                    print ("RUN DIR:" + dir);
2872                                                                                    
2873                                                                                    this.get('/BottomPane').el.set_current_page(1);
2874                                                                                     this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__) 
2875                                                                                         , false,false,false); 
2876                                                                                     var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
2877                                                                                     this.get('/Terminal').el.feed_child(cmd, cmd.length);
2878                                                                                     return false;
2879                                                                                   
2880                                                                                 
2881                                                                                 }
2882                                                                             }
2883                                                                         }
2884                                                                     ]
2885                                                                 },
2886                                                                 {
2887                                                                     xtype: Gtk.ScrolledWindow,
2888                                                                     pack : "add",
2889                                                                     id : "view-sw",
2890                                                                     shadow_type : Gtk.ShadowType.IN,
2891                                                                     init : function() {
2892                                                                         XObject.prototype.init.call(this);
2893                                                                      this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2894                                                                     },
2895                                                                     items : [
2896                                                                         {
2897                                                                             xtype: Gtk.EventBox,
2898                                                                             pack : "add",
2899                                                                             init : function() {
2900                                                                                 XObject.prototype.init.call(this);
2901                                                                             this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
2902                                                                                         red: 0x9F00, green: 0xB800 , blue : 0xA800
2903                                                                                        }));
2904                                                                             },
2905                                                                             items : [
2906                                                                                 {
2907                                                                                     xtype: Gtk.Fixed,
2908                                                                                     pack : "add",
2909                                                                                     init : function() {
2910                                                                                         XObject.prototype.init.call(this);
2911                                                                                         //this.el.set_hadjustment(this.parent.el.get_hadjustment());
2912                                                                                         //this.el.set_vadjustment(this.parent.el.get_vadjustment());
2913                                                                                      
2914                                                                                     },
2915                                                                                     items : [
2916                                                                                         {
2917                                                                                             xtype: Gtk.EventBox,
2918                                                                                             pack : "put,10,10",
2919                                                                                             init : function() {
2920                                                                                                 //this.el =     new Gtk.Image.from_stock (Gtk.STOCK_HOME,  Gtk.IconSize.MENU);
2921                                                                                                 XObject.prototype.init.call(this);
2922                                                                                             
2923                                                                                                         Gtk.drag_dest_set
2924                                                                                                         (
2925                                                                                                                 this.el,              /* widget that will accept a drop */
2926                                                                                                                 Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
2927                                                                                                                 null,            /* lists of target to support */
2928                                                                                                                 0,              /* size of list */
2929                                                                                                                 Gdk.DragAction.COPY         /* what to do with data after dropped */
2930                                                                                                         );
2931                                                                                                         
2932                                                                                                        // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2933                                                                                                         Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2934                                                                                             },
2935                                                                                             ready : false,
2936                                                                                             getActiveNode : function(x,y)
2937                                                                                             {
2938                                                                                                // workout what node is here..
2939                                                                                                 return '0'; // top..
2940                                                                                             },
2941                                                                                             id : "view",
2942                                                                                             listeners : {
2943                                                                                                 "drag_motion":function (self, ctx, x, y, time) {
2944                                                                                                     
2945                                                                                                                 // A) find out from drag all the places that node could be dropped.
2946                                                                                                                 var src = Gtk.drag_get_source_widget(ctx);
2947                                                                                                                 if (!src.dropList) {
2948                                                                                                                     Gdk.drag_status(ctx, 0, time);
2949                                                                                                                     return true;
2950                                                                                                                 }
2951                                                                                                                 // b) get what we are over.. (from activeNode)
2952                                                                                                                 // tree is empty.. - list should be correct..
2953                                                                                                                 if (!this.get('/LeftTree.model').currentTree) {
2954                                                                                                                     Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2955                                                                                                                     return true;
2956                                                                                                                     
2957                                                                                                                 }
2958                                                                                                                 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2959                                                                                                                 var activeNode = this.getActiveNode(x, y);
2960                                                                                                                 
2961                                                                                                                 
2962                                                                                                                 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
2963                                                                                                                 console.dump(tg);
2964                                                                                                                 if (!tg.length) {
2965                                                                                                                     Gdk.drag_status(ctx, 0,time);
2966                                                                                                                     this.get('/LeftTree.view').highlight(false);
2967                                                                                                                     return true;
2968                                                                                                                 }
2969                                                                                                                  
2970                                                                                                                 // if we have a target..
2971                                                                                                                 // -> highlight it! (in browser)
2972                                                                                                                 // -> highlight it! (in tree)
2973                                                                                                                 
2974                                                                                                                 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2975                                                                                                                 this.get('/LeftTree.view').highlight(tg);
2976                                                                                                                 this.targetData = tg;
2977                                                                                                                 // for tree we should handle this...
2978                                                                                                                 return true;
2979                                                                                                 },
2980                                                                                                 "drag_drop":function (self,ctx, x, y, time) {
2981                                                                                                         Seed.print("TARGET: drag-drop");
2982                                                                                                         var is_valid_drop_site = true;
2983                                                                                                         
2984                                                                                                          
2985                                                                                                         Gtk.drag_get_data
2986                                                                                                         (
2987                                                                                                                 self,         /* will receive 'drag-data-received' signal */
2988                                                                                                                 ctx,        /* represents the current state of the this.gDnD */
2989                                                                                                                 this.get('/Window').atoms["STRING"],    /* the target type we want */
2990                                                                                                                 time            /* time stamp */
2991                                                                                                         );
2992                                                                                                         
2993                                                                                                         
2994                                                                                                         /* No target offered by source => error */
2995                                                                                                        
2996                                                                                                 
2997                                                                                                         return  is_valid_drop_site;
2998                                                                                                   
2999                                                                                                 },
3000                                                                                                 "drag_data_received":function (w, ctx,  x,  y, sel_data,  target_type,  time, ud) 
3001                                                                                                     {
3002                                                                                                         Seed.print("GtkView: drag-data-received");
3003                                                                                                         var delete_selection_data = false;
3004                                                                                                         var dnd_success = false;
3005                                                                                                         /* Deal with what we are given from source */
3006                                                                                                         if( sel_data && sel_data.length ) {
3007                                                                                                             
3008                                                                                                             if (ctx.action == Gdk.DragAction.ASK)  {
3009                                                                                                                 /* Ask the user to move or copy, then set the ctx action. */
3010                                                                                                             }
3011                                                                                                 
3012                                                                                                             if (ctx.action == Gdk.DragAction.MOVE) {
3013                                                                                                                 delete_selection_data = true;
3014                                                                                                             }
3015                                                                                                             var source = Gtk.drag_get_source_widget(ctx);
3016                                                                                                 
3017                                                                                                             Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3018                                                                                                             if (this.targetData) {
3019                                                                                                                 Seed.print(this.targetData);
3020                                                                                                                 this.get('/LeftTree.model').dropNode(this.targetData,  source.dragData);
3021                                                                                                             }
3022                                                                                                             
3023                                                                                                             
3024                                                                                                             
3025                                                                                                             dnd_success = true;
3026                                                                                                 
3027                                                                                                         }
3028                                                                                                 
3029                                                                                                         if (dnd_success == false)
3030                                                                                                         {
3031                                                                                                                 Seed.print ("DnD data transfer failed!\n");
3032                                                                                                         }
3033                                                                                                         
3034                                                                                                         Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3035                                                                                                         return true;
3036                                                                                                     },
3037                                                                                                 "button_press_event":function (self, event) {
3038                                                                                                   this.pressed = false;
3039                                                                                                     return false;
3040                                                                                                 }
3041                                                                                             }
3042                                                                                         }
3043                                                                                     ]
3044                                                                                 }
3045                                                                             ]
3046                                                                         }
3047                                                                     ]
3048                                                                 }
3049                                                             ]
3050                                                         }
3051                                                     ]
3052                                                 }
3053                                             ]
3054                                         },
3055                                         {
3056                                             xtype: Gtk.Notebook,
3057                                             pack : "add",
3058                                             init : function() {
3059                                                 XObject.prototype.init.call(this);
3060                                                 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3061                                                         this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3062                                             },
3063                                             id : "BottomPane",
3064                                             items : [
3065                                                 {
3066                                                     xtype: Gtk.ScrolledWindow,
3067                                                     pack : "add",
3068                                                     id : "RightEditor",
3069                                                     items : [
3070                                                         {
3071                                                             xtype: GtkSource.View,
3072                                                             pack : "add",
3073                                                             id : "view",
3074                                                             init : function() {
3075                                                                 XObject.prototype.init.call(this);
3076                                                                  var description = Pango.Font.description_from_string("monospace")
3077                                                                 description.set_size(8000);
3078                                                                 this.el.modify_font(description);
3079                                                             
3080                                                             },
3081                                                             load : function(str) {
3082                                                                this.get('/BottomPane').el.set_current_page(0);
3083                                                                 this.el.get_buffer().set_text(str, str.length);
3084                                                                 var lm = GtkSource.LanguageManager.get_default();
3085                                                                 
3086                                                                 this.el.get_buffer().set_language(lm.get_language('js'));
3087                                                                 var buf = this.el.get_buffer();
3088                                                                 var cursor = buf.get_mark("insert");
3089                                                                 var iter= new Gtk.TextIter;
3090                                                                 buf.get_iter_at_mark(iter, cursor);
3091                                                                 iter.set_line(1);
3092                                                                 iter.set_line_offset(4);
3093                                                                 buf.move_mark(cursor, iter);
3094                                                                 
3095                                                                 
3096                                                                 cursor = buf.get_mark("selection_bound");
3097                                                                 iter= new Gtk.TextIter;
3098                                                                 buf.get_iter_at_mark(iter, cursor);
3099                                                                 iter.set_line(1);
3100                                                                 iter.set_line_offset(4);
3101                                                                 buf.move_mark(cursor, iter);
3102                                                                  
3103                                                                 this.el.grab_focus();
3104                                                             },
3105                                                             items : [
3106                                                                 {
3107                                                                     xtype: GtkSource.Buffer,
3108                                                                     pack : "set_buffer",
3109                                                                     listeners : {
3110                                                                         "changed":function (self) {
3111                                                                             var s = new Gtk.TextIter();
3112                                                                             var e = new Gtk.TextIter();
3113                                                                             this.el.get_start_iter(s);
3114                                                                             this.el.get_end_iter(e);
3115                                                                             var str = this.el.get_text(s,e,true);
3116                                                                             try {
3117                                                                                 Seed.check_syntax('var e = ' + str);
3118                                                                             } catch (e) {
3119                                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3120                                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3121                                                                                    }));
3122                                                                                 print("SYNTAX ERROR IN EDITOR");   
3123                                                                                 print(e);
3124                                                                                 console.dump(e);
3125                                                                                 return;
3126                                                                             }
3127                                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3128                                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3129                                                                                    }));
3130                                                                             
3131                                                                              this.get('/LeftPanel.model').changed(  str , false);
3132                                                                         }
3133                                                                     }
3134                                                                 }
3135                                                             ]
3136                                                         }
3137                                                     ]
3138                                                 },
3139                                                 {
3140                                                     xtype: Gtk.ScrolledWindow,
3141                                                     pack : "add",
3142                                                     items : [
3143                                                         {
3144                                                             xtype: Vte.Terminal,
3145                                                             pack : "add",
3146                                                             id : "Terminal",
3147                                                             feed : function(str) {
3148                                                                 this.el.feed(str,str.length);
3149                                                             }
3150                                                         }
3151                                                     ]
3152                                                 }
3153                                             ]
3154                                         }
3155                                     ]
3156                                 },
3157                                 {
3158                                     xtype: Gtk.VBox,
3159                                     pack : "pack_start,false,false",
3160                                     id : "RightPalete",
3161                                     hide : function() {
3162                                         
3163                                           this.get('buttonbar').el.show();
3164                                            this.get('viewbox').el.hide();
3165                                         print("TRIED TO HIDE");
3166                                     },
3167                                     show : function() {
3168                                         this.get('buttonbar').el.hide();
3169                                         this.get('viewbox').el.show();
3170                                        // this.get('model').expanded();
3171                                                 
3172                                     },
3173                                     provider : false,
3174                                     items : [
3175                                         {
3176                                             xtype: Gtk.VBox,
3177                                             pack : "add",
3178                                             id : "buttonbar",
3179                                             items : [
3180                                                 {
3181                                                     xtype: Gtk.Button,
3182                                                     pack : "pack_start,false,true",
3183                                                     listeners : {
3184                                                         "clicked":function (self) {
3185                                                                 this.get('/RightPalete').show();
3186                                                         }
3187                                                     },
3188                                                     items : [
3189                                                         {
3190                                                             xtype: Gtk.Image,
3191                                                             pack : "add",
3192                                                             stock : Gtk.STOCK_GOTO_FIRST,
3193                                                             icon_size : Gtk.IconSize.MENU
3194                                                         }
3195                                                     ]
3196                                                 },
3197                                                 {
3198                                                     xtype: Gtk.Label,
3199                                                     pack : "add",
3200                                                     label : "Palete",
3201                                                     angle : 270,
3202                                                     init : function() {
3203                                                         XObject.prototype.init.call(this);
3204                                                         this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3205                                                     },
3206                                                     listeners : {
3207                                                         "enter_notify_event":function (self, event) {
3208                                                             this.get('/RightPalete').show();
3209                                                             return false;
3210                                                         }
3211                                                     }
3212                                                 }
3213                                             ]
3214                                         },
3215                                         {
3216                                             xtype: Gtk.VBox,
3217                                             pack : "add",
3218                                             id : "viewbox",
3219                                             items : [
3220                                                 {
3221                                                     xtype: Gtk.HBox,
3222                                                     pack : "pack_start,false,true",
3223                                                     items : [
3224                                                         {
3225                                                             xtype: Gtk.Label,
3226                                                             pack : "add",
3227                                                             label : "Palete"
3228                                                         },
3229                                                         {
3230                                                             xtype: Gtk.Button,
3231                                                             pack : "pack_start,false,true",
3232                                                             listeners : {
3233                                                                 "clicked":function (self) {
3234                                                                         this.get('/RightPalete').hide();
3235                                                                 }
3236                                                             },
3237                                                             items : [
3238                                                                 {
3239                                                                     xtype: Gtk.Image,
3240                                                                     pack : "add",
3241                                                                     stock : Gtk.STOCK_GOTO_LAST,
3242                                                                     icon_size : Gtk.IconSize.MENU
3243                                                                 }
3244                                                             ]
3245                                                         }
3246                                                     ]
3247                                                 },
3248                                                 {
3249                                                     xtype: Gtk.ScrolledWindow,
3250                                                     pack : "add",
3251                                                     init : function() {
3252                                                         XObject.prototype.init.call(this);
3253                                                         this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3254                                                         this.el.set_size_request(-1,200);
3255                                                     },
3256                                                     shadow_type : Gtk.ShadowType.IN,
3257                                                     items : [
3258                                                         {
3259                                                             xtype: Gtk.TreeView,
3260                                                             pack : "add",
3261                                                             init : function() {
3262                                                                 XObject.prototype.init.call(this);
3263                                                               this.el.set_size_request(150,-1);
3264                                                                                       //  set_reorderable: [1]
3265                                                                                               
3266                                                                         var description = new Pango.FontDescription.c_new();
3267                                                                 description.set_size(8000);
3268                                                                 this.el.modify_font(description);
3269                                                                 
3270                                                                 this.selection = this.el.get_selection();
3271                                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3272                                                                // this.selection.signal['changed'].connect(function() {
3273                                                                 //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3274                                                                 //});
3275                                                                 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3276                                                                  
3277                                                                 Gtk.drag_source_set (
3278                                                                         this.el,            /* widget will be drag-able */
3279                                                                         Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
3280                                                                         null,            /* lists of target to support */
3281                                                                         0,              /* size of list */
3282                                                                         Gdk.DragAction.COPY         /* what to do with data after dropped */
3283                                                                 );
3284                                                                 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3285                                                                
3286                                                                 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3287                                                                 Gtk.drag_source_add_text_targets(this.el); 
3288                                                                 /*
3289                                                                 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3290                                                                 targets = new Gtk.TargetList();
3291                                                                 targets.add( LeftTree.atoms["STRING"], 0, 0);
3292                                                                 targets.add_text_targets( 1 );
3293                                                                 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3294                                                                 
3295                                                                 //if you want to allow text to be output elsewhere..
3296                                                                 //Gtk.drag_source_add_text_targets(this.el);
3297                                                                 */
3298                                                                 return true; 
3299                                                             },
3300                                                             headers_visible : false,
3301                                                             enable_tree_lines : true,
3302                                                             listeners : {
3303                                                                 "drag_begin":function (self, ctx) {
3304                                                                     // we could fill this in now...
3305                                                                         Seed.print('SOURCE: drag-begin');
3306                                                                         
3307                                                                         
3308                                                                         
3309                                                                         var iter = new Gtk.TreeIter();
3310                                                                         var s = this.selection;
3311                                                                         s.get_selected(this.get('/RightPalete.model').el, iter);
3312                                                                         var path = this.get('/RightPalete.model').el.get_path(iter);
3313                                                                         
3314                                                                         var pix = this.el.create_row_drag_icon ( path);
3315                                                                             
3316                                                                                 
3317                                                                         Gtk.drag_set_icon_pixmap (ctx,
3318                                                                             pix.get_colormap(),
3319                                                                             pix,
3320                                                                             null,
3321                                                                             -10,
3322                                                                             -10);
3323                                                                         
3324                                                                         var value = new GObject.Value('');
3325                                                                         this.get('/RightPalete.model').el.get_value(iter, 0, value);
3326                                                                         if (!this.get('/RightPalete').provider) {
3327                                                                             return false;
3328                                                                         }
3329                                                                         this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3330                                                                         this.el.dragData = value.value;
3331                                                                         
3332                                                                         
3333                                                                         
3334                                                                         
3335                                                                         return true;
3336                                                                 },
3337                                                                 "drag_data_get":function (self, drag_context, selection_data, info, time) {
3338                                                                         //Seed.print('Palete: drag-data-get: ' + target_type);
3339                                                                         if (this.el.dragData && this.el.dragData.length ) {
3340                                                                             selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3341                                                                         }
3342                                                                         
3343                                                                         
3344                                                                         //this.el.dragData = "TEST from source widget";
3345                                                                         
3346                                                                         
3347                                                                 },
3348                                                                 "drag_end":function (self, drag_context) {
3349                                                                         Seed.print('SOURCE: drag-end');
3350                                                                         this.el.dragData = false;
3351                                                                         this.el.dropList = false;
3352                                                                         this.get('/LeftTree.view').highlight(false);
3353                                                                         return true;
3354                                                                 }
3355                                                             },
3356                                                             items : [
3357                                                                 {
3358                                                                     xtype: Gtk.ListStore,
3359                                                                     pack : "set_model",
3360                                                                     init : function() {
3361                                                                         XObject.prototype.init.call(this);
3362                                                                     this.el.set_column_types ( 2, [
3363                                                                                                 GObject.TYPE_STRING, // title 
3364                                                                                                 GObject.TYPE_STRING // tip
3365                                                                                                 
3366                                                                                                 ] );
3367                                                                     },
3368                                                                     id : "model",
3369                                                                     load : function(tr,iter)
3370                                                                     {
3371                                                                         if (!iter) {
3372                                                                             this.el.clear();
3373                                                                         }
3374                                                                         //console.log('Project tree load: ' + tr.length);
3375                                                                         var citer = new Gtk.TreeIter();
3376                                                                         //this.insert(citer,iter,0);
3377                                                                         for(var i =0 ; i < tr.length; i++) {
3378                                                                             if (!iter) {
3379                                                                                 
3380                                                                                 this.el.append(citer);   
3381                                                                             } else {
3382                                                                                 this.el.insert(citer,iter,-1);
3383                                                                             }
3384                                                                             
3385                                                                             var r = tr[i];
3386                                                                             //Seed.print(r);
3387                                                                             this.el.set_value(citer, 0,  '' +  r ); // title 
3388                                                                             
3389                                                                             //this.el.set_value(citer, 1,  new GObject.Value( r)); //id
3390                                                                             //if (r.cn && r.cn.length) {
3391                                                                             //    this.load(r.cn, citer);
3392                                                                             //}
3393                                                                         }
3394                                                                         
3395                                                                         
3396                                                                     },
3397                                                                     getValue : function (iter, col) {
3398                                                                         var gval = new GObject.Value('');
3399                                                                          this.el.get_value(iter, col ,gval);
3400                                                                         return  gval.value;
3401                                                                         
3402                                                                         
3403                                                                     }
3404                                                                 },
3405                                                                 {
3406                                                                     xtype: Gtk.TreeViewColumn,
3407                                                                     pack : "append_column",
3408                                                                     init : function() {
3409                                                                         XObject.prototype.init.call(this);
3410                                                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
3411                                                                     },
3412                                                                     items : [
3413                                                                         {
3414                                                                             xtype: Gtk.CellRendererText,
3415                                                                             pack : "pack_start"
3416                                                                         }
3417                                                                     ]
3418                                                                 }
3419                                                             ]
3420                                                         }
3421                                                     ]
3422                                                 }
3423                                             ]
3424                                         }
3425                                     ]
3426                                 }
3427                             ]
3428                         }
3429                     ]
3430                 }
3431             ]
3432         }
3433     ]
3434 });
3435 Window.init();
3436 XObject.cache['/Window'] = Window;