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; // 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         }
138
139         // user defined functions 
140     }
141     public class Xcls_Label4 : Object 
142     {
143         public Gtk.Label el;
144         private DialogTemplateSelect  _this;
145
146
147             // my vars (def)
148
149         // ctor 
150         public Xcls_Label4(DialogTemplateSelect _owner )
151         {
152             _this = _owner;
153             this.el = new Gtk.Label( "Select Template : " );
154
155             // my vars (dec)
156
157             // set gobject values
158         }
159
160         // user defined functions 
161     }
162     public class Xcls_combo : Object 
163     {
164         public Gtk.ComboBox el;
165         private DialogTemplateSelect  _this;
166
167
168             // my vars (def)
169
170         // ctor 
171         public Xcls_combo(DialogTemplateSelect _owner )
172         {
173             _this = _owner;
174             _this.combo = this;
175             this.el = new Gtk.ComboBox();
176
177             // my vars (dec)
178
179             // set gobject values
180             var child_0 = new Xcls_cellrenderer( _this );
181             child_0.ref();
182             this.el.pack_start (  child_0.el , true );
183             var child_1 = new Xcls_model( _this );
184             child_1.ref();
185             this.el.set_model (  child_1.el  );
186
187             // init method 
188
189             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
190         }
191
192         // user defined functions 
193     }
194     public class Xcls_cellrenderer : Object 
195     {
196         public Gtk.CellRendererText el;
197         private DialogTemplateSelect  _this;
198
199
200             // my vars (def)
201
202         // ctor 
203         public Xcls_cellrenderer(DialogTemplateSelect _owner )
204         {
205             _this = _owner;
206             _this.cellrenderer = this;
207             this.el = new Gtk.CellRendererText();
208
209             // my vars (dec)
210
211             // set gobject values
212         }
213
214         // user defined functions 
215     }
216     public class Xcls_model : Object 
217     {
218         public Gtk.ListStore el;
219         private DialogTemplateSelect  _this;
220
221
222             // my vars (def)
223
224         // ctor 
225         public Xcls_model(DialogTemplateSelect _owner )
226         {
227             _this = _owner;
228             _this.model = this;
229             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
230
231             // my vars (dec)
232
233             // set gobject values
234         }
235
236         // user defined functions 
237         public void loadData (GLib.List<string> data) {
238             this.el.clear();                                    
239             Gtk.TreeIter iter;
240             var el = this.el;
241             
242            /// el.append(out iter);
243             
244              
245            // el.set_value(iter, 0, "");
246            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
247             
248             for (var i = 0; i < data.length();i++) {
249             
250         
251                 el.append(out iter);
252                 var str = data.nth_data(i);
253                 var fn = Path.get_basename (str);
254                 fn.replace(".json", "");
255                 
256                 el.set_value(iter, 0, str);
257                 el.set_value(iter, 1, fn);
258                 
259             }
260             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
261                                              
262         }
263     }
264     public class Xcls_Button8 : Object 
265     {
266         public Gtk.Button el;
267         private DialogTemplateSelect  _this;
268
269
270             // my vars (def)
271
272         // ctor 
273         public Xcls_Button8(DialogTemplateSelect _owner )
274         {
275             _this = _owner;
276             this.el = new Gtk.Button();
277
278             // my vars (dec)
279
280             // set gobject values
281             this.el.label = "Cancel";
282         }
283
284         // user defined functions 
285     }
286     public class Xcls_Button9 : Object 
287     {
288         public Gtk.Button el;
289         private DialogTemplateSelect  _this;
290
291
292             // my vars (def)
293
294         // ctor 
295         public Xcls_Button9(DialogTemplateSelect _owner )
296         {
297             _this = _owner;
298             this.el = new Gtk.Button();
299
300             // my vars (dec)
301
302             // set gobject values
303             this.el.label = "Just add it";
304         }
305
306         // user defined functions 
307     }
308     public class Xcls_Button10 : Object 
309     {
310         public Gtk.Button el;
311         private DialogTemplateSelect  _this;
312
313
314             // my vars (def)
315
316         // ctor 
317         public Xcls_Button10(DialogTemplateSelect _owner )
318         {
319             _this = _owner;
320             this.el = new Gtk.Button();
321
322             // my vars (dec)
323
324             // set gobject values
325             this.el.label = "OK";
326         }
327
328         // user defined functions 
329     }
330 }