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 Project.Project project;
27 public JsRender.Node node;
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_0 = new Xcls_Box2( _this );
44 this.el.get_content_area().append ( child_0.el );
45 var child_1 = new Xcls_Button13( _this );
47 this.el.add_action_widget ( child_1.el , 0 );
48 var child_2 = new Xcls_Button14( _this );
50 this.el.add_action_widget ( child_2.el , 1 );
51 var child_3 = new Xcls_Button15( _this );
53 this.el.add_action_widget ( child_3.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_Box2 : Object
184 private DialogTemplateSelect _this;
190 public Xcls_Box2(DialogTemplateSelect _owner )
193 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
197 // set gobject values
198 var child_0 = new Xcls_Box3( _this );
200 this.el.append ( child_0.el );
201 var child_1 = new Xcls_Box8( _this );
203 this.el.append ( child_1.el );
206 // user defined functions
208 public class Xcls_Box3 : Object
211 private DialogTemplateSelect _this;
217 public Xcls_Box3(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_0 = new Xcls_Label4( _this );
229 this.el.append ( child_0.el );
230 var child_1 = new Xcls_combo( _this );
232 this.el.append ( child_1.el );
235 // user defined functions
237 public class Xcls_Label4 : Object
240 private DialogTemplateSelect _this;
246 public Xcls_Label4(DialogTemplateSelect _owner )
249 this.el = new Gtk.Label( "Select Template : " );
253 // set gobject values
256 // user defined functions
259 public class Xcls_combo : Object
261 public Gtk.ComboBox el;
262 private DialogTemplateSelect _this;
268 public Xcls_combo(DialogTemplateSelect _owner )
272 this.el = new Gtk.ComboBox();
276 // set gobject values
277 var child_0 = new Xcls_cellrenderer( _this );
279 this.el.pack_start ( child_0.el , true );
280 var child_1 = new Xcls_model( _this );
282 this.el.set_model ( child_1.el );
286 this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
289 // user defined functions
291 public class Xcls_cellrenderer : Object
293 public Gtk.CellRendererText el;
294 private DialogTemplateSelect _this;
300 public Xcls_cellrenderer(DialogTemplateSelect _owner )
303 _this.cellrenderer = this;
304 this.el = new Gtk.CellRendererText();
308 // set gobject values
311 // user defined functions
314 public class Xcls_model : Object
316 public Gtk.ListStore el;
317 private DialogTemplateSelect _this;
323 public Xcls_model(DialogTemplateSelect _owner )
327 this.el = new Gtk.ListStore.newv( { typeof(string),typeof(string) } );
331 // set gobject values
334 // user defined functions
335 public void loadData (GLib.List<string> data) {
340 /// el.append(out iter);
343 // el.set_value(iter, 0, "");
344 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
346 for (var i = 0; i < data.length();i++) {
350 var str = data.nth_data(i);
351 var fn = Path.get_basename (str);
352 fn.replace(".json", "");
354 el.set_value(iter, 0, str);
355 el.set_value(iter, 1, fn);
358 this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);
365 public class Xcls_Box8 : Object
368 private DialogTemplateSelect _this;
374 public Xcls_Box8(DialogTemplateSelect _owner )
377 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
381 // set gobject values
382 this.el.margin_end = 3;
383 this.el.margin_start = 3;
384 var child_0 = new Xcls_Label9( _this );
386 this.el.append ( child_0.el );
387 var child_1 = new Xcls_dbcombo( _this );
389 this.el.append ( child_1.el );
392 // user defined functions
394 public class Xcls_Label9 : Object
397 private DialogTemplateSelect _this;
403 public Xcls_Label9(DialogTemplateSelect _owner )
406 this.el = new Gtk.Label( "Select Database Table : " );
410 // set gobject values
413 // user defined functions
416 public class Xcls_dbcombo : Object
418 public Gtk.ComboBox el;
419 private DialogTemplateSelect _this;
425 public Xcls_dbcombo(DialogTemplateSelect _owner )
428 _this.dbcombo = this;
429 this.el = new Gtk.ComboBox();
433 // set gobject values
434 var child_0 = new Xcls_dbcellrenderer( _this );
436 this.el.pack_start ( child_0.el , true );
437 var child_1 = new Xcls_dbmodel( _this );
439 this.el.set_model ( child_1.el );
443 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
446 // user defined functions
448 public class Xcls_dbcellrenderer : Object
450 public Gtk.CellRendererText el;
451 private DialogTemplateSelect _this;
457 public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
460 _this.dbcellrenderer = this;
461 this.el = new Gtk.CellRendererText();
465 // set gobject values
468 // user defined functions
471 public class Xcls_dbmodel : Object
473 public Gtk.ListStore el;
474 private DialogTemplateSelect _this;
480 public Xcls_dbmodel(DialogTemplateSelect _owner )
483 _this.dbmodel = this;
484 this.el = new Gtk.ListStore.newv( { typeof(string),typeof(string) } );
488 // set gobject values
491 // user defined functions
492 public void loadData (Gee.ArrayList<string> data) {
497 /// el.append(out iter);
500 // el.set_value(iter, 0, "");
501 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
506 el.set_value(iter, 0, "");
507 el.set_value(iter, 1, "-- select a table --");
510 for (var i = 0; i < data.size;i++) {
515 el.set_value(iter, 0, data.get(i));
516 el.set_value(iter, 1, data.get(i));
519 this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
527 public class Xcls_Button13 : Object
529 public Gtk.Button el;
530 private DialogTemplateSelect _this;
536 public Xcls_Button13(DialogTemplateSelect _owner )
539 this.el = new Gtk.Button();
543 // set gobject values
544 this.el.label = "Cancel";
547 // user defined functions
550 public class Xcls_Button14 : Object
552 public Gtk.Button el;
553 private DialogTemplateSelect _this;
559 public Xcls_Button14(DialogTemplateSelect _owner )
562 this.el = new Gtk.Button();
566 // set gobject values
567 this.el.label = "Just add it";
570 // user defined functions
573 public class Xcls_Button15 : Object
575 public Gtk.Button el;
576 private DialogTemplateSelect _this;
582 public Xcls_Button15(DialogTemplateSelect _owner )
585 this.el = new Gtk.Button();
589 // set gobject values
590 this.el.label = "OK";
593 // user defined functions