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