src/Builder4/DialogTemplateSelect.bjs
[app.Builder.js] / src / Builder4 / DialogTemplateSelect.vala
1 static DialogTemplateSelect  _DialogTemplateSelect;
2
3 public class DialogTemplateSelect : Object 
4 {
5     public Gtk.Dialog el;
6     private DialogTemplateSelect  _this;
7
8     public static DialogTemplateSelect singleton()
9     {
10         if (_DialogTemplateSelect == null) {
11             _DialogTemplateSelect= new DialogTemplateSelect();
12         }
13         return _DialogTemplateSelect;
14     }
15     public Xcls_combo combo;
16     public Xcls_cellrenderer cellrenderer;
17     public Xcls_model model;
18
19         // my vars (def)
20
21     // ctor 
22     public DialogTemplateSelect()
23     {
24         _this = this;
25         this.el = new Gtk.Dialog();
26
27         // my vars (dec)
28
29         // set gobject values
30         this.el.title = "Add an Object";
31         this.el.default_height = 200;
32         this.el.default_width = 400;
33         this.el.modal = true;
34         var child_0 = new Xcls_VBox2( _this );
35         child_0.ref();
36         this.el.get_content_area().add (  child_0.el  );
37         var child_1 = new Xcls_Button9( _this );
38         child_1.ref();
39         this.el.add_action_widget (  child_1.el , 0 );
40         var child_2 = new Xcls_Button10( _this );
41         child_2.ref();
42         this.el.add_action_widget (  child_2.el , 1 );
43         var child_3 = new Xcls_Button11( _this );
44         child_3.ref();
45         this.el.add_action_widget (  child_3.el , 2 );
46
47         // listeners 
48         this.el.delete_event.connect( (self, event)  =>{
49             this.el.hide();
50             return true;
51         });
52     }
53
54     // user defined functions 
55     public JsRender.Node? show (Gtk.Window pwindow, Palete.Palete pal, JsRender.Node node) {
56         
57         this.el.show_all();
58         var opts = pal.listTemplates(node);
59         if (opts.length() < 1) {
60             this.el.hide();
61             return node;
62         }
63         this.el.set_attached_to( pwindow);
64          this.el.set_transient_for( pwindow);
65         
66         //opts.unshift({ path: '' , name :'Just add Element' });
67          _this.model.loadData(opts);
68          _this.combo.el.set_active(0);
69          
70        
71         var res = this.el.run();
72         this.el.hide();    
73         //var ix = _this.combo.el.get_active();
74         if (res < 1 ) {
75             return null; // 0 = cancel.
76         }
77         if (res < 2 ) {
78             return node; // 1 = just add it..
79         }
80         
81        Gtk.TreeIter iter;
82         _this.combo.el.get_active_iter (out iter);
83         Value vfname;
84         this.model.el.get_value (iter, 0, out vfname);
85         
86         
87         return pal.loadTemplate((string)vfname);
88     
89     }
90     public class Xcls_VBox2 : Object 
91     {
92         public Gtk.VBox el;
93         private DialogTemplateSelect  _this;
94
95
96             // my vars (def)
97
98         // ctor 
99         public Xcls_VBox2(DialogTemplateSelect _owner )
100         {
101             _this = _owner;
102             this.el = new Gtk.VBox( true, 0 );
103
104             // my vars (dec)
105
106             // set gobject values
107             var child_0 = new Xcls_HBox3( _this );
108             child_0.ref();
109             this.el.pack_start (  child_0.el , false,false,0 );
110         }
111
112         // user defined functions 
113     }
114     public class Xcls_HBox3 : Object 
115     {
116         public Gtk.HBox el;
117         private DialogTemplateSelect  _this;
118
119
120             // my vars (def)
121
122         // ctor 
123         public Xcls_HBox3(DialogTemplateSelect _owner )
124         {
125             _this = _owner;
126             this.el = new Gtk.HBox( true, 0 );
127
128             // my vars (dec)
129
130             // set gobject values
131             var child_0 = new Xcls_Label4( _this );
132             child_0.ref();
133             this.el.pack_start (  child_0.el , false,false );
134             var child_1 = new Xcls_combo( _this );
135             child_1.ref();
136             this.el.add (  child_1.el  );
137             var child_2 = new Xcls_Label8( _this );
138             child_2.ref();
139             this.el.pack_start (  child_2.el , false,false );
140         }
141
142         // user defined functions 
143     }
144     public class Xcls_Label4 : Object 
145     {
146         public Gtk.Label el;
147         private DialogTemplateSelect  _this;
148
149
150             // my vars (def)
151
152         // ctor 
153         public Xcls_Label4(DialogTemplateSelect _owner )
154         {
155             _this = _owner;
156             this.el = new Gtk.Label( "Select Template : " );
157
158             // my vars (dec)
159
160             // set gobject values
161         }
162
163         // user defined functions 
164     }
165     public class Xcls_combo : Object 
166     {
167         public Gtk.ComboBox el;
168         private DialogTemplateSelect  _this;
169
170
171             // my vars (def)
172
173         // ctor 
174         public Xcls_combo(DialogTemplateSelect _owner )
175         {
176             _this = _owner;
177             _this.combo = this;
178             this.el = new Gtk.ComboBox();
179
180             // my vars (dec)
181
182             // set gobject values
183             var child_0 = new Xcls_cellrenderer( _this );
184             child_0.ref();
185             this.el.pack_start (  child_0.el , true );
186             var child_1 = new Xcls_model( _this );
187             child_1.ref();
188             this.el.set_model (  child_1.el  );
189
190             // init method 
191
192             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
193         }
194
195         // user defined functions 
196     }
197     public class Xcls_cellrenderer : Object 
198     {
199         public Gtk.CellRendererText el;
200         private DialogTemplateSelect  _this;
201
202
203             // my vars (def)
204
205         // ctor 
206         public Xcls_cellrenderer(DialogTemplateSelect _owner )
207         {
208             _this = _owner;
209             _this.cellrenderer = this;
210             this.el = new Gtk.CellRendererText();
211
212             // my vars (dec)
213
214             // set gobject values
215         }
216
217         // user defined functions 
218     }
219     public class Xcls_model : Object 
220     {
221         public Gtk.ListStore el;
222         private DialogTemplateSelect  _this;
223
224
225             // my vars (def)
226
227         // ctor 
228         public Xcls_model(DialogTemplateSelect _owner )
229         {
230             _this = _owner;
231             _this.model = this;
232             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
233
234             // my vars (dec)
235
236             // set gobject values
237         }
238
239         // user defined functions 
240         public void loadData (GLib.List<string> data) {
241             this.el.clear();                                    
242             Gtk.TreeIter iter;
243             var el = this.el;
244             
245            /// el.append(out iter);
246             
247              
248            // el.set_value(iter, 0, "");
249            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
250             
251             for (var i = 0; i < data.length();i++) {
252             
253         
254                 el.append(out iter);
255                 var str = data.nth_data(i);
256                 var fn = Path.get_basename (str);
257                 fn.replace(".json", "");
258                 
259                 el.set_value(iter, 0, str);
260                 el.set_value(iter, 1, fn);
261                 
262             }
263             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
264                                              
265         }
266     }
267     public class Xcls_Label8 : Object 
268     {
269         public Gtk.Label el;
270         private DialogTemplateSelect  _this;
271
272
273             // my vars (def)
274
275         // ctor 
276         public Xcls_Label8(DialogTemplateSelect _owner )
277         {
278             _this = _owner;
279             this.el = new Gtk.Label( "Select Template : " );
280
281             // my vars (dec)
282
283             // set gobject values
284         }
285
286         // user defined functions 
287     }
288     public class Xcls_Button9 : Object 
289     {
290         public Gtk.Button el;
291         private DialogTemplateSelect  _this;
292
293
294             // my vars (def)
295
296         // ctor 
297         public Xcls_Button9(DialogTemplateSelect _owner )
298         {
299             _this = _owner;
300             this.el = new Gtk.Button();
301
302             // my vars (dec)
303
304             // set gobject values
305             this.el.label = "Cancel";
306         }
307
308         // user defined functions 
309     }
310     public class Xcls_Button10 : Object 
311     {
312         public Gtk.Button el;
313         private DialogTemplateSelect  _this;
314
315
316             // my vars (def)
317
318         // ctor 
319         public Xcls_Button10(DialogTemplateSelect _owner )
320         {
321             _this = _owner;
322             this.el = new Gtk.Button();
323
324             // my vars (dec)
325
326             // set gobject values
327             this.el.label = "Just add it";
328         }
329
330         // user defined functions 
331     }
332     public class Xcls_Button11 : Object 
333     {
334         public Gtk.Button el;
335         private DialogTemplateSelect  _this;
336
337
338             // my vars (def)
339
340         // ctor 
341         public Xcls_Button11(DialogTemplateSelect _owner )
342         {
343             _this = _owner;
344             this.el = new Gtk.Button();
345
346             // my vars (dec)
347
348             // set gobject values
349             this.el.label = "OK";
350         }
351
352         // user defined functions 
353     }
354 }