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