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