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