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