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