tools
[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                     items : [
58                         {
59                             xtype: Gtk.Label,
60                             label : "Select Template : ",
61                             pack : "pack_start,false,false"
62                         },
63                         {
64                             xtype: Gtk.ComboBox,
65                             id : "combo",
66                             pack : "add",
67                             init : function() {
68                                 XObject.prototype.init.call(this);
69                                  this.el.add_attribute(this.items[0].el , 'markup', 1 );
70                             },
71                             items : [
72                                 {
73                                     xtype: Gtk.CellRendererText,
74                                     pack : "pack_start"
75                                 },
76                                 {
77                                     xtype: Gtk.ListStore,
78                                     id : "model",
79                                     pack : "set_model",
80                                     init : function() {
81                                         XObject.prototype.init.call(this);
82                                                 this.el.set_column_types ( 2, [
83                                                 GObject.TYPE_STRING,  // real key
84                                                 GObject.TYPE_STRING // real type
85                                                 
86                                                 
87                                             ] );
88                                     },
89                                     loadData : function (data) {
90                                         this.el.clear();                                    
91                                         var iter = new Gtk.TreeIter();
92                                         var el = this.el;
93                                         data.forEach(function(p) {
94                                     
95                                             el.append(iter);
96                                             
97                                              
98                                             el.set_value(iter, 0, ''+ p.path);
99                                             el.set_value(iter, 1, ''+ p.name);
100                                             
101                                         });
102                                                   
103                                                                          
104                                     }
105                                 }
106                             ]
107                         }
108                     ]
109                 }
110             ]
111         },
112         {
113             xtype: Gtk.Button,
114             label : "OK",
115             pack : "add_action_widget,0"
116         }
117     ]
118 });
119 DialogTemplateSelect.init();
120 XObject.cache['/DialogTemplateSelect'] = DialogTemplateSelect;