1 static DialogTemplateSelect _DialogTemplateSelect;
3 public class DialogTemplateSelect : Object
6 private DialogTemplateSelect _this;
8 public static DialogTemplateSelect singleton()
10 if (_DialogTemplateSelect == null) {
11 _DialogTemplateSelect= new DialogTemplateSelect();
13 return _DialogTemplateSelect;
15 public Xcls_combo combo;
16 public Xcls_cellrenderer cellrenderer;
17 public Xcls_model model;
18 public Xcls_dbcombo dbcombo;
19 public Xcls_dbcellrenderer dbcellrenderer;
20 public Xcls_dbmodel dbmodel;
23 public Xcls_MainWindow window;
24 public signal void complete (JsRender.Node? node);
25 public Palete.Palete palete;
26 public JsRender.Node node;
27 public Project.Project project;
30 public DialogTemplateSelect()
33 this.el = new Gtk.Dialog();
38 this.el.title = "Add an Object";
39 this.el.default_height = 200;
40 this.el.default_width = 400;
42 var child_1 = new Xcls_Box1( _this );
44 this.el.get_content_area().append ( child_1.el );
45 var child_2 = new Xcls_Button12( _this );
47 this.el.add_action_widget ( child_2.el , 0 );
48 var child_3 = new Xcls_Button13( _this );
50 this.el.add_action_widget ( child_3.el , 1 );
51 var child_4 = new Xcls_Button14( _this );
53 this.el.add_action_widget ( child_4.el , 2 );
56 this.el.close_request.connect( ( ) => {
61 this.el.response.connect( (res) => {
63 //var node = _this.node;
64 //var project = _this.project;
68 if (this.plugin == null) {
69 this.plugin = new Xcls_DialogPluginWebkit();
70 this.plugin.complete.connect((json_str) => {
71 print("json_str = %s\n", json_str);
72 if (json_str.length < 1) {
73 this.complete(_this.node);
76 var pa = new Json.Parser();
79 pa.load_from_data(json_str);
82 return; // 1 = just add it..
84 var new_node = pa.get_root();
86 if (new_node.get_node_type () != Json.NodeType.OBJECT) {
90 var obj = new_node.get_object ();
92 var ret = new JsRender.Node();
94 ret.loadFromJson(obj, 1);
104 //var ix = _this.combo.el.get_active();
107 return; // 0 = cancel.
111 return; // 1 = just add it..
115 // have they selected a table??
119 if (_this.dbcombo.el.get_active_iter (out iter)) {
120 this.dbmodel.el.get_value (iter, 0, out vfname);
121 if (((string)vfname).length > 0 && this.plugin.has_plugin(node.fqn())) {
122 this.plugin.showIt(this.window.el, project, node.fqn(), (string)vfname);
126 return; // 1 = just add it..
131 if (!_this.combo.el.get_active_iter (out iter)) {
134 return; // 1 = just add it../ nothing selected...
137 this.model.el.get_value (iter, 0, out vfname);
139 this.complete(this.palete.loadTemplate((string)vfname));
140 return; // 1 = just add it..
146 // user defined functions
148 Xcls_MainWindow mwindow,
151 Project.Project project
156 var opts = pal.listTemplates(node);
157 if (opts.length() < 1) {
162 this.el.set_transient_for( mwindow.el);
164 //opts.unshift({ path: '' , name :'Just add Element' });
165 _this.model.loadData(opts);
166 _this.combo.el.set_active(-1);
169 var db = new Palete.RooDatabase.from_project((Project.Roo) project);
170 _this.dbmodel.loadData(db.readTablesGee());
173 _this.dbcombo.el.set_active(-1);
175 this.window = mwindow;
178 this.project = project;
181 public class Xcls_Box1 : Object
184 private DialogTemplateSelect _this;
190 public Xcls_Box1(DialogTemplateSelect _owner )
193 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
197 // set gobject values
198 var child_1 = new Xcls_Box2( _this );
200 this.el.append ( child_1.el );
201 var child_2 = new Xcls_Box7( _this );
203 this.el.append ( child_2.el );
206 // user defined functions
208 public class Xcls_Box2 : Object
211 private DialogTemplateSelect _this;
217 public Xcls_Box2(DialogTemplateSelect _owner )
220 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
224 // set gobject values
225 this.el.margin_end = 3;
226 this.el.margin_start = 3;
227 var child_1 = new Xcls_Label3( _this );
229 this.el.append ( child_1.el );
230 new Xcls_combo( _this );
231 this.el.append ( _this.combo.el );
234 // user defined functions
236 public class Xcls_Label3 : Object
239 private DialogTemplateSelect _this;
245 public Xcls_Label3(DialogTemplateSelect _owner )
248 this.el = new Gtk.Label( "Select Template : " );
252 // set gobject values
255 // user defined functions
258 public class Xcls_combo : Object
260 public Gtk.ComboBox el;
261 private DialogTemplateSelect _this;
267 public Xcls_combo(DialogTemplateSelect _owner )
271 this.el = new Gtk.ComboBox();
275 // set gobject values
276 new Xcls_cellrenderer( _this );
277 this.el.pack_start ( _this.cellrenderer.el , true );
278 new Xcls_model( _this );
279 this.el.set_model ( _this.model.el );
283 this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
286 // user defined functions
288 public class Xcls_cellrenderer : Object
290 public Gtk.CellRendererText el;
291 private DialogTemplateSelect _this;
297 public Xcls_cellrenderer(DialogTemplateSelect _owner )
300 _this.cellrenderer = this;
301 this.el = new Gtk.CellRendererText();
305 // set gobject values
308 // user defined functions
311 public class Xcls_model : Object
313 public Gtk.ListStore el;
314 private DialogTemplateSelect _this;
320 public Xcls_model(DialogTemplateSelect _owner )
324 this.el = new Gtk.ListStore.newv( { typeof(string),typeof(string) } );
328 // set gobject values
331 // user defined functions
332 public void loadData (GLib.List<string> data) {
337 /// el.append(out iter);
340 // el.set_value(iter, 0, "");
341 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
343 for (var i = 0; i < data.length();i++) {
347 var str = data.nth_data(i);
348 var fn = Path.get_basename (str);
349 fn.replace(".json", "");
351 el.set_value(iter, 0, str);
352 el.set_value(iter, 1, fn);
355 this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);
362 public class Xcls_Box7 : Object
365 private DialogTemplateSelect _this;
371 public Xcls_Box7(DialogTemplateSelect _owner )
374 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
378 // set gobject values
379 this.el.margin_end = 3;
380 this.el.margin_start = 3;
381 var child_1 = new Xcls_Label8( _this );
383 this.el.append ( child_1.el );
384 new Xcls_dbcombo( _this );
385 this.el.append ( _this.dbcombo.el );
388 // user defined functions
390 public class Xcls_Label8 : Object
393 private DialogTemplateSelect _this;
399 public Xcls_Label8(DialogTemplateSelect _owner )
402 this.el = new Gtk.Label( "Select Database Table : " );
406 // set gobject values
409 // user defined functions
412 public class Xcls_dbcombo : Object
414 public Gtk.ComboBox el;
415 private DialogTemplateSelect _this;
421 public Xcls_dbcombo(DialogTemplateSelect _owner )
424 _this.dbcombo = this;
425 this.el = new Gtk.ComboBox();
429 // set gobject values
430 new Xcls_dbcellrenderer( _this );
431 this.el.pack_start ( _this.dbcellrenderer.el , true );
432 new Xcls_dbmodel( _this );
433 this.el.set_model ( _this.dbmodel.el );
437 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
440 // user defined functions
442 public class Xcls_dbcellrenderer : Object
444 public Gtk.CellRendererText el;
445 private DialogTemplateSelect _this;
451 public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
454 _this.dbcellrenderer = this;
455 this.el = new Gtk.CellRendererText();
459 // set gobject values
462 // user defined functions
465 public class Xcls_dbmodel : Object
467 public Gtk.ListStore el;
468 private DialogTemplateSelect _this;
474 public Xcls_dbmodel(DialogTemplateSelect _owner )
477 _this.dbmodel = this;
478 this.el = new Gtk.ListStore.newv( { typeof(string),typeof(string) } );
482 // set gobject values
485 // user defined functions
486 public void loadData (Gee.ArrayList<string> data) {
491 /// el.append(out iter);
494 // el.set_value(iter, 0, "");
495 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
500 el.set_value(iter, 0, "");
501 el.set_value(iter, 1, "-- select a table --");
504 for (var i = 0; i < data.size;i++) {
509 el.set_value(iter, 0, data.get(i));
510 el.set_value(iter, 1, data.get(i));
513 this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
521 public class Xcls_Button12 : Object
523 public Gtk.Button el;
524 private DialogTemplateSelect _this;
530 public Xcls_Button12(DialogTemplateSelect _owner )
533 this.el = new Gtk.Button();
537 // set gobject values
538 this.el.label = "Cancel";
541 // user defined functions
544 public class Xcls_Button13 : Object
546 public Gtk.Button el;
547 private DialogTemplateSelect _this;
553 public Xcls_Button13(DialogTemplateSelect _owner )
556 this.el = new Gtk.Button();
560 // set gobject values
561 this.el.label = "Just add it";
564 // user defined functions
567 public class Xcls_Button14 : Object
569 public Gtk.Button el;
570 private DialogTemplateSelect _this;
576 public Xcls_Button14(DialogTemplateSelect _owner )
579 this.el = new Gtk.Button();
583 // set gobject values
584 this.el.label = "OK";
587 // user defined functions