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