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