dbgenerate.js
[app.Builder.js] / Sample / DialogTemplateSelect.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 GtkClutter = imports.gi.GtkClutter;
11 Gdl = imports.gi.Gdl;
12 console = imports.console;
13 XObject = imports.XObject.XObject;
14 DialogTemplateSelect=new XObject({
15     xtype: Gtk.Dialog,
16     listeners : {
17         delete_event : function (self, event) {
18             this.el.hide();
19             return true;
20         }
21     },
22     default_height : 200,
23     default_width : 400,
24     modal : true,
25     show : function(node) {
26         
27         var pal = this.get('/Window.LeftTree').getPaleteProvider();
28         var opts = pal.listTemplates(node);
29         if (!opts.length) {
30             return node;
31         }
32       
33         opts.unshift({ path: '' , name :'Just add Element' });
34         this.get('combo.model').loadData(opts);
35          this.get('combo').el.set_active(0);
36          
37         this.el.show_all();
38         this.el.run();
39         this.el.hide();
40         var ix = this.get('combo').el.get_active();
41         if (ix < 1 ) {
42             return node;
43         }
44         
45     
46         return pal.loadTemplate(opts[ix].path)
47     
48     },
49     items : [
50         {
51             xtype: Gtk.VBox,
52             pack : function(p,e) {
53                                 p.el.get_content_area().add(e.el)
54                             },
55             items : [
56                 {
57                     xtype: Gtk.HBox,
58                     pack : "pack_start,false,false,0",
59                     items : [
60                         {
61                             xtype: Gtk.Label,
62                             label : "Select Template : ",
63                             pack : "pack_start,false,false"
64                         },
65                         {
66                             xtype: Gtk.ComboBox,
67                             id : "combo",
68                             pack : "add",
69                             init : function() {
70                                 XObject.prototype.init.call(this);
71                                  this.el.add_attribute(this.items[0].el , 'markup', 1 );
72                             },
73                             items : [
74                                 {
75                                     xtype: Gtk.CellRendererText,
76                                     pack : "pack_start"
77                                 },
78                                 {
79                                     xtype: Gtk.ListStore,
80                                     id : "model",
81                                     pack : "set_model",
82                                     init : function() {
83                                         XObject.prototype.init.call(this);
84                                                 this.el.set_column_types ( 2, [
85                                                 GObject.TYPE_STRING,  // real key
86                                                 GObject.TYPE_STRING // real type
87                                                 
88                                                 
89                                             ] );
90                                     },
91                                     loadData : function (data) {
92                                         this.el.clear();                                    
93                                         var iter = new Gtk.TreeIter();
94                                         var el = this.el;
95                                         data.forEach(function(p) {
96                                     
97                                             el.append(iter);
98                                             
99                                              
100                                             el.set_value(iter, 0, ''+ p.path);
101                                             el.set_value(iter, 1, ''+ p.name);
102                                             
103                                         });
104                                                   
105                                                                          
106                                     }
107                                 }
108                             ]
109                         }
110                     ]
111                 }
112             ]
113         },
114         {
115             xtype: Gtk.Button,
116             label : "OK",
117             pack : "add_action_widget,0"
118         }
119     ]
120 });
121 DialogTemplateSelect.init();
122 XObject.cache['/DialogTemplateSelect'] = DialogTemplateSelect;