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