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