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