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