Fix #7247 - icons for object add
[roobuilder] / src / Builder4 / PopoverAddObject.vala
1 static Xcls_PopoverAddObject  _PopoverAddObject;
2
3 public class Xcls_PopoverAddObject : Object
4 {
5     public Gtk.Popover el;
6     private Xcls_PopoverAddObject  _this;
7
8     public static Xcls_PopoverAddObject singleton()
9     {
10         if (_PopoverAddObject == null) {
11             _PopoverAddObject= new Xcls_PopoverAddObject();
12         }
13         return _PopoverAddObject;
14     }
15     public Xcls_model model;
16     public Xcls_iconrender iconrender;
17     public Xcls_txtrender txtrender;
18
19         // my vars (def)
20     public bool active;
21     public signal void before_node_change (JsRender.Node? node);
22     public signal void drag_end ();
23     public Xcls_MainWindow mainwindow;
24     public signal void after_node_change (JsRender.Node? node);
25
26     // ctor
27     public Xcls_PopoverAddObject()
28     {
29         _this = this;
30         this.el = new Gtk.Popover( null );
31
32         // my vars (dec)
33         this.active = false;
34
35         // set gobject values
36         this.el.width_request = 900;
37         this.el.height_request = 800;
38         this.el.hexpand = false;
39         this.el.modal = true;
40         this.el.position = Gtk.PositionType.RIGHT;
41         var child_0 = new Xcls_ScrolledWindow2( _this );
42         child_0.ref();
43         this.el.add (  child_0.el  );
44     }
45
46     // user defined functions
47     public void show (Palete.Palete pal, string cls,  Gtk.Widget onbtn) {
48     
49         
50        
51      
52     
53         var tr = pal.getChildList(cls);
54         this.model.el.clear();
55     
56     
57         Gtk.TreeIter citer;
58         var ic = Gtk.IconTheme.get_default();
59         var pixdef = ic.load_icon("emblem-new", 16,0);
60     
61         for(var i =0 ; i < tr.length; i++) {
62              this.model.el.append(out citer);   
63              var dname = tr[i];
64              var clsname = dname;
65              if (dname.contains(":")) {
66                         var ar = dname.split(":");
67                         dname = "<b>" + ar[1] +"</b> - <i>"+ar[0]+"</i>";
68                         clsname = ar[0]; /// possibly?
69                 }
70              
71             this.model.el.set_value(citer, 0,   tr[i] ); // used data. 
72             this.model.el.set_value(citer, 1,   dname ); // displayed value.
73             
74             var clsb = clsname.split(".");
75             var sub = clsb.length > 1 ? clsb[1].down()  : "";
76             
77             var pix = pixdef;
78             var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
79             if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
80                 pix = new Gdk.Pixbuf.from_file (fn);
81             }
82             
83             
84             this.model.el.set_value(citer, 2,   pix );
85             
86             
87         }
88         this.model.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
89         
90         
91         
92         
93         
94         // set size up...
95         
96         this.model.el.set_sort_column_id(0,Gtk.SortType.ASCENDING);
97         int w,h;
98         this.mainwindow.el.get_size(out w, out h);
99         
100         // left tree = 250, editor area = 500?
101         
102         // min 450?
103         // max hieght ...
104         this.el.set_size_request( 350, h); // full height?
105     
106         
107     
108         if (this.el.relative_to == null) {
109             this.el.set_relative_to(onbtn);
110         }
111         this.el.show_all();
112        
113         while(Gtk.events_pending()) { 
114                 Gtk.main_iteration();
115         }       
116      //   this.hpane.el.set_position( 0);
117     }
118     public void hide () {
119      
120         this.el.hide();
121     }
122     public void clear () {
123      this.model.el.clear();
124     }
125     public class Xcls_ScrolledWindow2 : Object
126     {
127         public Gtk.ScrolledWindow el;
128         private Xcls_PopoverAddObject  _this;
129
130
131             // my vars (def)
132
133         // ctor
134         public Xcls_ScrolledWindow2(Xcls_PopoverAddObject _owner )
135         {
136             _this = _owner;
137             this.el = new Gtk.ScrolledWindow( null, null );
138
139             // my vars (dec)
140
141             // set gobject values
142             this.el.shadow_type = Gtk.ShadowType.IN;
143             var child_0 = new Xcls_TreeView3( _this );
144             child_0.ref();
145             this.el.add (  child_0.el  );
146
147             // init method
148
149             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
150                this.el.set_size_request(-1,200);
151         }
152
153         // user defined functions
154     }
155     public class Xcls_TreeView3 : Object
156     {
157         public Gtk.TreeView el;
158         private Xcls_PopoverAddObject  _this;
159
160
161             // my vars (def)
162         public string dragData;
163
164         // ctor
165         public Xcls_TreeView3(Xcls_PopoverAddObject _owner )
166         {
167             _this = _owner;
168             this.el = new Gtk.TreeView();
169
170             // my vars (dec)
171
172             // set gobject values
173             this.el.enable_tree_lines = true;
174             this.el.headers_visible = true;
175             var child_0 = new Xcls_model( _this );
176             child_0.ref();
177             this.el.set_model (  child_0.el  );
178             var child_1 = new Xcls_TreeViewColumn5( _this );
179             child_1.ref();
180             this.el.append_column (  child_1.el  );
181
182             // init method
183
184             {
185                 this.el.set_size_request(150,-1);
186                                       //  set_reorderable: [1]
187                                               
188                 var description = new Pango.FontDescription();
189                 description.set_size(10000);
190                 this.el.override_font(description);
191                 
192                 var selection = this.el.get_selection();
193                 selection.set_mode( Gtk.SelectionMode.SINGLE);
194                // this.selection.signal['changed'].connect(function() {
195                 //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
196                 //});
197                 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
198                  
199                 Gtk.drag_source_set (
200                         this.el,            /* widget will be drag-able */
201                         Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
202                         BuilderApplication.targetList,            /* lists of target to support */
203                         Gdk.DragAction.COPY         /* what to do with data after dropped */
204                 );
205                 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
206                
207                // Gtk.drag_source_set_target_list(this.el, Application.targetList);
208                // Gtk.drag_source_add_text_targets(this.el); 
209              
210             }
211
212             //listeners
213             this.el.button_press_event.connect( ( event) => {
214             
215              // if (!this.get('/Editor').save()) {
216              //     // popup!! - click handled.. 
217             //      return true;
218             //        }
219                 return false;
220             });
221             this.el.drag_begin.connect( ( ctx) => {
222                 // we could fill this in now...
223             //        Seed.print('SOURCE: drag-begin');
224                     
225                     
226                     
227                     Gtk.TreeIter iter;
228                     var s = this.el.get_selection();
229                     
230                     Gtk.TreeModel mod;
231                     s.get_selected(out mod, out iter);
232                     var path = mod.get_path(iter);
233                     
234                     /// pix is a surface..
235                     var pix = this.el.create_row_drag_icon ( path);
236                         
237                             
238                     Gtk.drag_set_icon_surface (ctx, pix);
239                     GLib.Value value;
240                     
241             
242                     _this.model.el.get_value(iter, 0, out value);
243                     
244                     this.dragData = (string) value;
245                      
246                     
247                     return;
248             });
249             this.el.drag_data_get.connect( (drag_context, selection_data, info, time) => {
250                 //Seed.print('Palete: drag-data-get: ' + target_type);
251                 if (this.dragData.length < 1 ) {
252                     return; 
253                 }
254                 
255                 GLib.debug("setting drag data to %s\n", this.dragData);
256                // selection_data.set_text(this.dragData ,this.dragData.length);
257                selection_data.set (selection_data.get_target (), 8, (uchar[]) this.dragData.to_utf8 ());
258             
259                     //this.el.dragData = "TEST from source widget";
260                     
261                     
262             });
263             this.el.drag_end.connect( ( drag_context)  => {
264                  GLib.debug("SOURCE: drag-end (call listener on this)\n");
265                 
266                 this.dragData = "";
267                 //this.dropList = null;
268                 _this.drag_end(); // call signal..
269                 //this.get('/LeftTree.view').highlight(false);
270                  
271             });
272         }
273
274         // user defined functions
275     }
276     public class Xcls_model : Object
277     {
278         public Gtk.ListStore el;
279         private Xcls_PopoverAddObject  _this;
280
281
282             // my vars (def)
283
284         // ctor
285         public Xcls_model(Xcls_PopoverAddObject _owner )
286         {
287             _this = _owner;
288             _this.model = this;
289             this.el = new Gtk.ListStore( 3, typeof(string),typeof(string),typeof(Gdk.Pixbuf) );
290
291             // my vars (dec)
292
293             // set gobject values
294         }
295
296         // user defined functions
297         public string getValue (Gtk.TreeIter iter, int col)  {
298                 GLib.Value gval;
299                 this.el.get_value(iter, col , out gval);
300                 return  (string)gval;
301              
302         }
303     }
304
305     public class Xcls_TreeViewColumn5 : Object
306     {
307         public Gtk.TreeViewColumn el;
308         private Xcls_PopoverAddObject  _this;
309
310
311             // my vars (def)
312
313         // ctor
314         public Xcls_TreeViewColumn5(Xcls_PopoverAddObject _owner )
315         {
316             _this = _owner;
317             this.el = new Gtk.TreeViewColumn();
318
319             // my vars (dec)
320
321             // set gobject values
322             this.el.title = "Drag to add Object";
323             var child_0 = new Xcls_iconrender( _this );
324             child_0.ref();
325             this.el.pack_start (  child_0.el , true );
326             var child_1 = new Xcls_txtrender( _this );
327             child_1.ref();
328             this.el.pack_start (  child_1.el , true );
329
330             // init method
331
332             this.el.add_attribute(_this.txtrender.el , "markup",  1 );
333             this.el.add_attribute(_this.iconrender.el , "pixbuf",  2 );
334         }
335
336         // user defined functions
337     }
338     public class Xcls_iconrender : Object
339     {
340         public Gtk.CellRendererPixbuf el;
341         private Xcls_PopoverAddObject  _this;
342
343
344             // my vars (def)
345
346         // ctor
347         public Xcls_iconrender(Xcls_PopoverAddObject _owner )
348         {
349             _this = _owner;
350             _this.iconrender = this;
351             this.el = new Gtk.CellRendererPixbuf();
352
353             // my vars (dec)
354
355             // set gobject values
356         }
357
358         // user defined functions
359     }
360
361     public class Xcls_txtrender : Object
362     {
363         public Gtk.CellRendererText el;
364         private Xcls_PopoverAddObject  _this;
365
366
367             // my vars (def)
368
369         // ctor
370         public Xcls_txtrender(Xcls_PopoverAddObject _owner )
371         {
372             _this = _owner;
373             _this.txtrender = this;
374             this.el = new Gtk.CellRendererText();
375
376             // my vars (dec)
377
378             // set gobject values
379         }
380
381         // user defined functions
382     }
383
384
385
386
387 }