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