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