07b1a3fa0c8aa0b0ea5193d47305f3a862fdcf23
[roobuilder] / src / Builder4 / PopoverAddProp.vala
1 static Xcls_PopoverAddProp  _PopoverAddProp;
2
3 public class Xcls_PopoverAddProp : Object
4 {
5     public Gtk.Popover el;
6     private Xcls_PopoverAddProp  _this;
7
8     public static Xcls_PopoverAddProp singleton()
9     {
10         if (_PopoverAddProp == null) {
11             _PopoverAddProp= new Xcls_PopoverAddProp();
12         }
13         return _PopoverAddProp;
14     }
15     public Xcls_model model;
16     public Xcls_namecol namecol;
17     public Xcls_namerender namerender;
18
19         // my vars (def)
20     public bool active;
21     public signal void select (string key, string type, string skel, string prop_or_listener);
22     public Xcls_MainWindow mainwindow;
23     public string prop_or_listener;
24
25     // ctor
26     public Xcls_PopoverAddProp()
27     {
28         _this = this;
29         this.el = new Gtk.Popover( null );
30
31         // my vars (dec)
32         this.active = false;
33         this.prop_or_listener = "";
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 prop_or_listener, string xtype,  Gtk.Widget onbtn) {
48     
49         
50         if (this.prop_or_listener  != "" && this.prop_or_listener == prop_or_listener) {
51                 this.prop_or_listener = "";
52                 this.el.hide();
53                 return;
54         }
55         this.prop_or_listener = prop_or_listener;
56         
57         this.model.el.clear();
58     
59         Gtk.TreeIter iter;
60         var elementList = pal.getPropertiesFor( xtype,prop_or_listener);
61          
62         //print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
63                // console.dump(elementList);
64                
65         var miter = elementList.map_iterator();
66         while (miter.next()) {
67            var p = miter.get_value();
68             
69             this.model.el.append(out iter);
70     
71                 var dname = p.name;
72                 var dtype = p.type;
73                  
74     
75             this.model.el.set(iter,
76                     0,  p.name, 
77                     1, p.type,
78                     2, "<b>" + p.name +"</b> <i>"+p.type+"</i>\n" + 
79                             GLib.Markup.escape_text(p.doctxt),
80                     3, p.sig,
81                     4, "<b>" + dname +"</b> <span size=\"small\"><i>"+dtype+"</i></span>",
82                     5, prop_or_listener,
83                     -1
84             );
85         }
86         this.model.el.set_sort_column_id(0,Gtk.SortType.ASCENDING);    
87         
88         // set size up...
89         
90     
91         int w,h;
92         this.mainwindow.el.get_size(out w, out h);
93         
94         // left tree = 250, editor area = 500?
95         
96         // min 450?
97         // max hieght ...
98         this.el.set_size_request( 250, h);
99     
100         
101     
102         if (this.el.relative_to == null) {
103             this.el.set_relative_to(onbtn);
104         }
105         this.el.show_all();
106        
107         while(Gtk.events_pending()) { 
108                 Gtk.main_iteration();   // why?
109         }       
110      //   this.hpane.el.set_position( 0);
111     }
112     public void hide () {
113         this.prop_or_listener = "";
114         this.el.hide();
115     }
116     public void clear () {
117      this.model.el.clear();
118     }
119     public class Xcls_ScrolledWindow2 : Object
120     {
121         public Gtk.ScrolledWindow el;
122         private Xcls_PopoverAddProp  _this;
123
124
125             // my vars (def)
126
127         // ctor
128         public Xcls_ScrolledWindow2(Xcls_PopoverAddProp _owner )
129         {
130             _this = _owner;
131             this.el = new Gtk.ScrolledWindow( null, null );
132
133             // my vars (dec)
134
135             // set gobject values
136             this.el.shadow_type = Gtk.ShadowType.IN;
137             var child_0 = new Xcls_TreeView3( _this );
138             child_0.ref();
139             this.el.add (  child_0.el  );
140
141             // init method
142
143             this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
144         }
145
146         // user defined functions
147     }
148     public class Xcls_TreeView3 : Object
149     {
150         public Gtk.TreeView el;
151         private Xcls_PopoverAddProp  _this;
152
153
154             // my vars (def)
155
156         // ctor
157         public Xcls_TreeView3(Xcls_PopoverAddProp _owner )
158         {
159             _this = _owner;
160             this.el = new Gtk.TreeView();
161
162             // my vars (dec)
163
164             // set gobject values
165             this.el.tooltip_column = 2;
166             this.el.enable_tree_lines = true;
167             this.el.headers_visible = true;
168             var child_0 = new Xcls_model( _this );
169             child_0.ref();
170             this.el.set_model (  child_0.el  );
171             var child_1 = new Xcls_namecol( _this );
172             child_1.ref();
173             this.el.append_column (  child_1.el  );
174
175             // init method
176
177             {  
178                    var description = new Pango.FontDescription();
179                  description.set_size(10000);
180                 this.el.override_font(description);     
181                                 
182                 this.el.get_selection().set_mode( Gtk.SelectionMode.SINGLE);
183              
184             
185                 
186               
187                 
188             }
189
190             //listeners
191             this.el.row_activated.connect( (path, column)  => {
192             
193                 Gtk.TreeIter iter;
194             
195             
196                 var m = _this.model;
197             
198                 m.el.get_iter(out iter,path);
199             
200             
201                 // var val = "";
202             
203             
204                 var key = m.getValue(iter, 0);
205             
206                 var type = m.getValue(iter, 1);
207                 var skel = m.getValue(iter, 3);
208                 var etype = m.getValue(iter, 5);
209             
210                 // hide the popover
211                 _this.el.hide();
212                 _this.prop_or_listener = "";
213                 
214                 
215                 _this.select(key,etype == "signals" ? "" : type,skel, etype);
216              
217             });
218         }
219
220         // user defined functions
221     }
222     public class Xcls_model : Object
223     {
224         public Gtk.ListStore el;
225         private Xcls_PopoverAddProp  _this;
226
227
228             // my vars (def)
229
230         // ctor
231         public Xcls_model(Xcls_PopoverAddProp _owner )
232         {
233             _this = _owner;
234             _this.model = this;
235             this.el = new Gtk.ListStore( 6, typeof(string),  // 0 real key
236 typeof(string), // 1 real type
237 typeof(string), // 2 docs ?
238 typeof(string), // 3 visable desc
239 typeof(string), // 4 function desc
240 typeof(string) // 5 element type (event|prop)
241          );
242
243             // my vars (dec)
244
245             // set gobject values
246         }
247
248         // user defined functions
249         public string getValue (Gtk.TreeIter iter, int col)
250         {
251         
252             GLib.Value value;
253             this.el.get_value(iter, col, out value);
254          
255             return (string)value;
256             
257         }
258     }
259
260     public class Xcls_namecol : Object
261     {
262         public Gtk.TreeViewColumn el;
263         private Xcls_PopoverAddProp  _this;
264
265
266             // my vars (def)
267
268         // ctor
269         public Xcls_namecol(Xcls_PopoverAddProp _owner )
270         {
271             _this = _owner;
272             _this.namecol = this;
273             this.el = new Gtk.TreeViewColumn();
274
275             // my vars (dec)
276
277             // set gobject values
278             this.el.title = "Double click to add";
279             var child_0 = new Xcls_namerender( _this );
280             child_0.ref();
281             this.el.pack_start (  child_0.el , true );
282
283             // init method
284
285             this.el.add_attribute(_this.namerender.el , "markup", 4  );
286         }
287
288         // user defined functions
289     }
290     public class Xcls_namerender : Object
291     {
292         public Gtk.CellRendererText el;
293         private Xcls_PopoverAddProp  _this;
294
295
296             // my vars (def)
297
298         // ctor
299         public Xcls_namerender(Xcls_PopoverAddProp _owner )
300         {
301             _this = _owner;
302             _this.namerender = this;
303             this.el = new Gtk.CellRendererText();
304
305             // my vars (dec)
306
307             // set gobject values
308         }
309
310         // user defined functions
311     }
312
313
314
315
316 }