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