sync
[app.Builder.js] / oldbuilder / RightPalete.js
1 //<Script type="text/javascript">
2 Gio = imports.gi.Gio;
3 Gtk = imports.gi.Gtk;
4 Gdk = imports.gi.Gdk;
5 GObject = imports.gi.GObject;
6 Pango = imports.gi.Pango ;
7
8 XObject = imports.XObject.XObject;
9 console = imports.console;
10
11
12 LeftTree =   imports.Builder.LeftTree.LeftTree;
13 Roo = imports.Builder.Provider.Palete.Roo.Roo;
14 // normally appears as a vbox with a expander button,
15 // when you put your mouse over though, it expands.
16
17 RightPalete = new XObject({
18          
19         
20         xtype: Gtk.VBox,
21         pack : [ 'pack_start', false, false ],
22         
23         hide : function() {
24             this.get('hidden').el.show();
25             this.get('visible').el.hide();
26         },
27         show : function() {
28             this.get('hidden').el.hide();
29             this.get('visible').el.show();
30             this.get('model').expanded();
31             
32         },
33         provider : false,
34         
35         items : [
36             {
37                     
38                 id : 'hidden',
39                 xtype: Gtk.VBox,
40                  
41                 items : [
42                 
43                 
44                     {
45                         
46                         xtype: Gtk.Button,
47                         pack : [ 'pack_start', false, true ],
48                         listeners : {
49                             clicked : function() {
50                                 RightPalete.show();
51                             }
52                         },
53                         items : [
54                             {
55                                 
56                                 xtype: Gtk.Image,
57                                 
58                                 stock : Gtk.STOCK_GOTO_FIRST,
59                                 'icon-size' : Gtk.IconSize.MENU,
60                                 pack : ['add']
61                             }
62                         ]
63                     },
64                     {
65                         pack : [ 'pack_start', true, true ],
66                         
67                         xtype: Gtk.Label,
68                         label: 'Palete',
69                         angle : 270,
70                         init : function() {
71                             XObject.prototype.init.call(this);  
72                             this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
73                         },
74                         listeners : {
75                             'enter-notify-event' : function (w,e)
76                             {
77                                 RightPalete.show();
78                                 //console.log("enter!");
79                                 //this.el.expanded = !this.el.expanded;
80                                 //this.listeners.activate.call(this);
81                                 return true;
82                             }
83                         }
84                     }
85                 ]
86             },
87             
88             {
89                     
90                 id : 'visible',
91                 xtype: Gtk.VBox,
92                 
93                 items : [         
94                     {
95                         
96                         
97                         xtype: Gtk.HBox,
98                         pack : [ 'pack_start', false, true ],
99                         items : [
100                             {
101                                  
102                                 
103                                 xtype: Gtk.Label,
104                                 label: "Palete"
105                              
106                             },
107                             {
108                                 
109                                 xtype: Gtk.Button,
110                                 pack : [ 'pack_start', false, true ],
111                                 listeners : {
112                                     clicked : function() {
113                                         RightPalete.hide();
114                                     }
115                                 },
116                                 items : [
117                                     {
118                                         
119                                         xtype: Gtk.Image,
120                                         stock : Gtk.STOCK_GOTO_LAST,
121                                         'icon-size' : Gtk.IconSize.MENU,
122                                 
123                                         // open arrow...
124                                     }
125                                 ]
126                             }
127                         ]
128                     },
129                     
130                     // expandable here...( show all.. )
131                     
132                                 // our pallete goes here...
133             // two trees technically...
134             
135                     
136                     {
137                 
138                         
139                         xtype: Gtk.ScrolledWindow,
140                         smooth_scroll : true,
141                         shadow_type :  Gtk.ShadowType.IN ,
142                         
143                         init : function() {
144                             XObject.prototype.init.call(this);  
145                        
146                             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
147                             this.el.set_size_request(-1,200);
148                         },
149                         items : [        
150                             {
151                                 
152                                     
153                                 id : 'view',
154                                 xtype : Gtk.TreeView,
155                                 headers_visible :  false,
156                                 enable_tree_lines :  true ,
157                                 tooltip_column : 1,
158                                 init : function() {
159                                     XObject.prototype.init.call(this);  
160                                     this.el.set_size_request(150,-1);
161                                   //  set_reorderable: [1]
162                                   
163                                     var description = new Pango.FontDescription.c_new();
164                                     description.set_size(8000);
165                                     this.el.modify_font(description);
166                                     
167                                     this.selection = this.el.get_selection();
168                                     this.selection.set_mode( Gtk.SelectionMode.SINGLE);
169                                    // this.selection.signal['changed'].connect(function() {
170                                     //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
171                                     //});
172                                     // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
173                                      
174                                     Gtk.drag_source_set (
175                                             this.el,            /* widget will be drag-able */
176                                             Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
177                                             null,            /* lists of target to support */
178                                             0,              /* size of list */
179                                             Gdk.DragAction.COPY         /* what to do with data after dropped */
180                                     );
181                                     Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
182                                     /*
183                                     print("RP: TARGET:" + LeftTree.atoms["STRING"]);
184                                     targets = new Gtk.TargetList();
185                                     targets.add( LeftTree.atoms["STRING"], 0, 0);
186                                     targets.add_text_targets( 1 );
187                                     Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
188                                     
189                                     //if you want to allow text to be output elsewhere..
190                                     //Gtk.drag_source_add_text_targets(this.el);
191                                     */
192                                     return true; 
193                                 },  
194                                 listeners : {
195                                     
196                               
197                                     'drag-data-get' : function (w, ctx, selection_data, target_type,  time, ud) 
198                                     {
199                                         
200                                         Seed.print('Palete: drag-data-get: ' + target_type);
201                                         if (this.el.dragData && this.el.dragData.length ) {
202                                             selection_data.set_text(this.el.dragData ,this.el.dragData.length);
203                                         }
204                                         
205                                         
206                                         //this.el.dragData = "TEST from source widget";
207                                         
208                                         
209                                         
210                                         return true;
211                                     },
212                                    
213                                     'drag-begin' : function (w, ctx, ud) 
214                                     {
215                                         // we could fill this in now...
216                                         Seed.print('SOURCE: drag-begin');
217                                         
218                                         
219                                         
220                                         var iter = new Gtk.TreeIter();
221                                         var s = this.selection;
222                                         s.get_selected(RightPalete.get('model').el, iter);
223                                         var path = RightPalete.get('model').el.get_path(iter);
224                                         
225                                         var pix = this.el.create_row_drag_icon ( path);
226                                             
227                                                 
228                                         Gtk.drag_set_icon_pixmap (ctx,
229                                             pix.get_colormap(),
230                                             pix,
231                                             null,
232                                             -10,
233                                             -10);
234                                         
235                                         var value = new GObject.Value('');
236                                         RightPalete.get('model').el.get_value(iter, 0, value);
237                                         if (!RightPalete.provider) {
238                                             return false;
239                                         }
240                                         this.el.dropList = RightPalete.provider.getDropList(value.value);
241                                         this.el.dragData = value.value;
242                                         
243                                         
244                                         
245                                         
246                                         return true;
247                                     },
248                                     'drag-end' : function () 
249                                     {
250                                         Seed.print('SOURCE: drag-end');
251                                         this.el.dragData = false;
252                                         this.el.dropList = false;
253                                         LeftTree.get('view').highlight(false);
254                                         return true;
255                                     },
256                                     
257                                     /*
258                                     'cursor-changed'  : function(tv, a) { 
259                                         //select -- should save existing...
260                                         var iter = new Gtk.TreeIter();
261                                         
262                                         if (this.selection.count_selected_rows() < 1) {
263                                             
264                                             Builder.LeftTree._model.load( false);
265                                             
266                                             return;
267                                         }
268                                         
269                                         //console.log('changed');
270                                         var s = this.selection;
271                                         s.get_selected(_model, iter);
272                                         value = new GObject.Value('');
273                                         _model.el.get_value(iter, 2, value);
274                                         
275                                         console.log(value.value);
276                                         var file = _model.project.get(value.value);
277                                         
278                                         
279                                         console.log(file);
280                                         _expander.el.set_expanded(false);
281
282                                         Builder.LeftTree._model.loadFile(file);
283                                         
284                                         return true;
285                                         
286                                         
287                                     
288                                     }
289                                     */
290                                 },
291                                 
292                                 items  : [
293                                     {
294                                         pack : ['set_model'],
295                                         
296                                         id : 'model',
297                                         xtype : Gtk.ListStore,
298                                          
299                                         init  :  function()
300                                         {
301                                            
302                                            XObject.prototype.init.call(this);  
303                                  
304                                             
305                                             
306                                             
307                                             this.el.set_column_types ( 2, [
308                                                     GObject.TYPE_STRING, // title 
309                                                     GObject.TYPE_STRING // tip
310                                                     
311                                                     ] );
312                                              
313                                               
314                                             
315                                         },
316                                         expanded : function() // event handler realy.
317                                         {
318                                             // should ask tree for list of current compeents.
319                                             
320                                             //console.dump(this.provider);
321                                             //var li = this.provider.gatherList([]);
322                                             //console.dump(li);
323                                             //this.load( this.provider.gatherList([]));
324                                             
325                                             
326                                             
327                                             
328                                         },
329                                         
330                                         load : function(tr,iter)
331                                         {
332                                             if (!iter) {
333                                                 this.el.clear();
334                                             }
335                                             //console.log('Project tree load: ' + tr.length);
336                                             var citer = new Gtk.TreeIter();
337                                             //this.insert(citer,iter,0);
338                                             for(var i =0 ; i < tr.length; i++) {
339                                                 if (!iter) {
340                                                     
341                                                     this.el.append(citer);   
342                                                 } else {
343                                                     this.el.insert(citer,iter,-1);
344                                                 }
345                                                 
346                                                 var r = tr[i];
347                                                 //Seed.print(r);
348                                                 this.el.set_value(citer, 0,  '' +  r ); // title 
349                                                 
350                                                 //this.el.set_value(citer, 1,  new GObject.Value( r)); //id
351                                                 //if (r.cn && r.cn.length) {
352                                                 //    this.load(r.cn, citer);
353                                                 //}
354                                             }
355                                             
356                                             
357                                         },
358                                         
359                                         
360                                         
361                                         
362                                         getValue: function (iter, col) {
363                                             var gval = new GObject.Value('');
364                                              this.el.get_value(iter, col ,gval);
365                                             return  gval.value;
366                                             
367                                             
368                                         }
369                                         
370                                         
371                                         
372                                       //  this.expand_all();
373                                     },
374                                     
375                                       
376                                     {
377                                         pack : ['append_column'],
378                                         
379                                         xtype : Gtk.TreeViewColumn,
380                                         init  :  function()
381                                         {
382                                            
383                                             XObject.prototype.init.call(this);  
384                                             this.el.add_attribute(this.items[0].el , 'markup', 0 );
385                                         },
386
387                                         items : [
388                                             {
389                                                 
390                                                 xtype : Gtk.CellRendererText,
391                                                 pack: [ 'pack_start']
392                                                   
393                                             } 
394                                         ]
395                                         
396                                     
397                                       
398                                     }
399                                     
400                                ]
401                             }
402                         ]
403                     }
404                 ]
405
406             }
407         ]
408             
409     }
410 )