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