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