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