Attribute changed old-javascript
[app.Builder.js] / old-javascript / 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 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       
32         var dopts = [];
33       
34       
35         dopts.push({ path: '' , name :'Just add Element' });
36         
37         
38         
39          
40         var project = this.get('/Window.LeftTree').getActiveFile().project;
41         var m = project.dbcon ? project.dbcon + '_' : false;
42         
43       
44                         //print (project.fn);
45         
46         opts.forEach(function(p) {
47             // if we have a dbname - ignore _ named.
48             if (m  && p.name.match(/_/) && 
49                 p.name.substring(0, m.length) != m) {
50                 return;
51                 
52             }
53             dopts.push(p);
54         });
55             
56         
57         this.get('combo.model').loadData(dopts);
58          this.get('combo').el.set_active(0);
59          
60         this.el.show_all();
61         this.el.run();
62         this.el.hide();
63         var ix = this.get('combo').el.get_active();
64         if (ix < 1 ) {
65             return node;
66         }
67          
68         return pal.loadTemplate(dopts[ix].path)
69     
70     },
71     items : [
72         {
73             xtype: Gtk.VBox,
74             pack : function(p,e) {
75                                 p.el.get_content_area().add(e.el)
76                             },
77             items : [
78                 {
79                     xtype: Gtk.HBox,
80                     pack : "pack_start,false,false,0",
81                     items : [
82                         {
83                             xtype: Gtk.Label,
84                             label : "Select Template : ",
85                             pack : "pack_start,false,false"
86                         },
87                         {
88                             xtype: Gtk.ComboBox,
89                             id : "combo",
90                             pack : "add",
91                             init : function() {
92                                 XObject.prototype.init.call(this);
93                                  this.el.add_attribute(this.items[0].el , 'markup', 1 );
94                             },
95                             items : [
96                                 {
97                                     xtype: Gtk.CellRendererText,
98                                     pack : "pack_start"
99                                 },
100                                 {
101                                     xtype: Gtk.ListStore,
102                                     id : "model",
103                                     pack : "set_model",
104                                     init : function() {
105                                         XObject.prototype.init.call(this);
106                                                 this.el.set_column_types ( 2, [
107                                                 GObject.TYPE_STRING,  // real key
108                                                 GObject.TYPE_STRING // real type
109                                                 
110                                                 
111                                             ] );
112                                     },
113                                     loadData : function (data) {
114                                         this.el.clear();                                    
115                                          
116                                         var project = this.get('/Window.LeftTree').getActiveFile().project;
117                                         var m = project.dbcon ? project.dbcon + '_' : false;
118                                         
119                                       
120                                                         //print (project.fn);
121                                         var el = this.el;
122                                         data.forEach(function(p) {
123                                             // if we have a dbname - ignore _ named.
124                                             if (m  && p.name.match(/_/) && 
125                                                 p.name.substring(0, m.length) != m) {
126                                                 return;
127                                                 
128                                             }
129                                             
130                                             var iret = {};
131                                             el.append(iret);
132                                             
133                                              
134                                             el.set_value(iret.iter, 0, ''+ p.path);
135                                             el.set_value(iret.iter, 1, ''+ p.name);
136                                             
137                                         });
138                                                   
139                                                                          
140                                     }
141                                 }
142                             ]
143                         }
144                     ]
145                 }  
146             ]
147         },
148         {
149             xtype: Gtk.Button,
150             label : "OK",
151             pack : "add_action_widget,0"
152         }
153     ]
154 });
155 DialogTemplateSelect.init();
156 XObject.cache['/DialogTemplateSelect'] = DialogTemplateSelect;