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