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