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