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