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