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