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