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_Button8( _this );
38         child_1.ref();
39         this.el.add_action_widget (  child_1.el , 0 );
40         var child_2 = new Xcls_Button9( _this );
41         child_2.ref();
42         this.el.add_action_widget (  child_2.el , 1 );
43         var child_3 = new Xcls_Button10( _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         this.el.run();
72         this.el.hide();    
73         //var ix = _this.combo.el.get_active();
74         //if (ix < 1 ) {
75         //    return node;
76        // }
77        Gtk.TreeIter iter;
78         _this.combo.el.get_active_iter (out iter);
79         Value vfname;
80         this.model.el.get_value (iter, 0, out vfname);
81         
82         if (((string)vfname).length < 1) {
83             return node;
84         }
85         return pal.loadTemplate((string)vfname);
86     
87     }
88     public class Xcls_VBox2 : Object 
89     {
90         public Gtk.VBox el;
91         private DialogTemplateSelect  _this;
92
93
94             // my vars (def)
95
96         // ctor 
97         public Xcls_VBox2(DialogTemplateSelect _owner )
98         {
99             _this = _owner;
100             this.el = new Gtk.VBox( true, 0 );
101
102             // my vars (dec)
103
104             // set gobject values
105             var child_0 = new Xcls_HBox3( _this );
106             child_0.ref();
107             this.el.pack_start (  child_0.el , false,false,0 );
108         }
109
110         // user defined functions 
111     }
112     public class Xcls_HBox3 : Object 
113     {
114         public Gtk.HBox el;
115         private DialogTemplateSelect  _this;
116
117
118             // my vars (def)
119
120         // ctor 
121         public Xcls_HBox3(DialogTemplateSelect _owner )
122         {
123             _this = _owner;
124             this.el = new Gtk.HBox( true, 0 );
125
126             // my vars (dec)
127
128             // set gobject values
129             var child_0 = new Xcls_Label4( _this );
130             child_0.ref();
131             this.el.pack_start (  child_0.el , false,false );
132             var child_1 = new Xcls_combo( _this );
133             child_1.ref();
134             this.el.add (  child_1.el  );
135         }
136
137         // user defined functions 
138     }
139     public class Xcls_Label4 : Object 
140     {
141         public Gtk.Label el;
142         private DialogTemplateSelect  _this;
143
144
145             // my vars (def)
146
147         // ctor 
148         public Xcls_Label4(DialogTemplateSelect _owner )
149         {
150             _this = _owner;
151             this.el = new Gtk.Label( "Select Template : " );
152
153             // my vars (dec)
154
155             // set gobject values
156         }
157
158         // user defined functions 
159     }
160     public class Xcls_combo : Object 
161     {
162         public Gtk.ComboBox el;
163         private DialogTemplateSelect  _this;
164
165
166             // my vars (def)
167
168         // ctor 
169         public Xcls_combo(DialogTemplateSelect _owner )
170         {
171             _this = _owner;
172             _this.combo = this;
173             this.el = new Gtk.ComboBox();
174
175             // my vars (dec)
176
177             // set gobject values
178             var child_0 = new Xcls_cellrenderer( _this );
179             child_0.ref();
180             this.el.pack_start (  child_0.el , true );
181             var child_1 = new Xcls_model( _this );
182             child_1.ref();
183             this.el.set_model (  child_1.el  );
184
185             // init method 
186
187             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
188         }
189
190         // user defined functions 
191     }
192     public class Xcls_cellrenderer : Object 
193     {
194         public Gtk.CellRendererText el;
195         private DialogTemplateSelect  _this;
196
197
198             // my vars (def)
199
200         // ctor 
201         public Xcls_cellrenderer(DialogTemplateSelect _owner )
202         {
203             _this = _owner;
204             _this.cellrenderer = this;
205             this.el = new Gtk.CellRendererText();
206
207             // my vars (dec)
208
209             // set gobject values
210         }
211
212         // user defined functions 
213     }
214     public class Xcls_model : Object 
215     {
216         public Gtk.ListStore el;
217         private DialogTemplateSelect  _this;
218
219
220             // my vars (def)
221
222         // ctor 
223         public Xcls_model(DialogTemplateSelect _owner )
224         {
225             _this = _owner;
226             _this.model = this;
227             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
228
229             // my vars (dec)
230
231             // set gobject values
232         }
233
234         // user defined functions 
235         public void loadData (GLib.List<string> data) {
236             this.el.clear();                                    
237             Gtk.TreeIter iter;
238             var el = this.el;
239             
240            /// el.append(out iter);
241             
242              
243            // el.set_value(iter, 0, "");
244            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
245             
246             for (var i = 0; i < data.length();i++) {
247             
248         
249                 el.append(out iter);
250                 var str = data.nth_data(i);
251                 var fn = Path.get_basename (str);
252                 fn.replace(".json", "");
253                 
254                 el.set_value(iter, 0, str);
255                 el.set_value(iter, 1, fn);
256                 
257             }
258             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
259                                              
260         }
261     }
262     public class Xcls_Button8 : Object 
263     {
264         public Gtk.Button el;
265         private DialogTemplateSelect  _this;
266
267
268             // my vars (def)
269
270         // ctor 
271         public Xcls_Button8(DialogTemplateSelect _owner )
272         {
273             _this = _owner;
274             this.el = new Gtk.Button();
275
276             // my vars (dec)
277
278             // set gobject values
279             this.el.label = "Cancel";
280         }
281
282         // user defined functions 
283     }
284     public class Xcls_Button9 : Object 
285     {
286         public Gtk.Button el;
287         private DialogTemplateSelect  _this;
288
289
290             // my vars (def)
291
292         // ctor 
293         public Xcls_Button9(DialogTemplateSelect _owner )
294         {
295             _this = _owner;
296             this.el = new Gtk.Button();
297
298             // my vars (dec)
299
300             // set gobject values
301             this.el.label = "Just add it";
302         }
303
304         // user defined functions 
305     }
306     public class Xcls_Button10 : Object 
307     {
308         public Gtk.Button el;
309         private DialogTemplateSelect  _this;
310
311
312             // my vars (def)
313
314         // ctor 
315         public Xcls_Button10(DialogTemplateSelect _owner )
316         {
317             _this = _owner;
318             this.el = new Gtk.Button();
319
320             // my vars (dec)
321
322             // set gobject values
323             this.el.label = "OK";
324         }
325
326         // user defined functions 
327     }
328 }