Sample/DialogTemplateSelect.js
[app.Builder.js] / Sample / EditProject.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 EditProject=new XObject({
13     xtype: Gtk.Dialog,
14     default_height : 500,
15     default_width : 600,
16     deletable : true,
17     modal : true,
18     border_width : 3,
19     title : "Project Properties",
20     show : function(c) {
21            c = c || { name : '' , xtype : '' };
22         this.project  = c;
23         if (!this.el) {
24             this.init();
25         }
26         var _this = this;
27         [ 'xtype'  ].forEach(function(k) {
28             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
29         });
30         // shouild set path..
31         
32         this.el.show_all();
33         this.success = c.success;
34     },
35     listeners : {
36         destroy_event : function (self, event) {
37              this.el.hide();
38                         return false;
39         },
40         response : function (self, id) {
41          if (id < 1) {
42                     this.el.hide();
43                     return;
44                 }
45                 if (!this.get('xtype').getValue().length) {
46                     this.get('/StandardErrorDialog').show("You have to set Project type");             
47                     return;
48                 }
49                 if (!this.get('dir').el.get_filename().length) {
50                     this.get('/StandardErrorDialog').show("You have to select a folder");             
51                     return;
52                 }
53         
54                 this.el.hide();
55                 
56                 
57                 var fn = this.get('dir').el.get_filename();
58                 
59                 this.project.name  = GLib.basename(fn);
60                 this.project.xtype  = this.get('xtype').getValue();
61                 this.project.paths = {};
62                 this.project.paths[fn] =  'dir' ;
63                 
64                 var pr = imports.Builder.Provider.ProjectManager.ProjectManager.update(this.project);
65                 
66                 this.success(pr);
67                 Seed.print(id);
68         }
69     },
70     items : [
71         {
72             xtype: Gtk.VBox,
73             pack : function(p,e) {
74                         p.el.get_content_area().add(e.el)
75                     },
76             items : [
77                 {
78                     xtype: Gtk.HBox,
79                     pack : "pack_start,false,true,3",
80                     items : [
81                         {
82                             xtype: Gtk.Label,
83                             pack : "pack_start,false,true,3",
84                             label : "Project type :"
85                         },
86                         {
87                             xtype: Gtk.ComboBox,
88                             pack : "pack_end,true,true,3",
89                             id : "xtype",
90                             setValue : function(v)
91                                             {
92                                                 var el = this.el;
93                                                 el.set_active(-1);
94                                                 this.get('model').data.forEach(function(n, ix) {
95                                                     if (v == n.xtype) {
96                                                         el.set_active(ix);
97                                                         return false;
98                                                     }
99                                                 });
100                                             },
101                             getValue : function() {
102                                  var ix = this.el.get_active();
103                                         if (ix < 0 ) {
104                                             return '';
105                                         }
106                                         return this.get('model').data[ix].xtype;
107                             },
108                             init : function() {
109                                 XObject.prototype.init.call(this);
110                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
111                             },
112                             items : [
113                                 {
114                                     xtype: Gtk.CellRendererText,
115                                     pack : "pack_start"
116                                 },
117                                 {
118                                     xtype: Gtk.ListStore,
119                                     pack : "set_model",
120                                     init : function() {
121                                         XObject.prototype.init.call(this);
122                                     
123                                                                 this.el.set_column_types ( 2, [
124                                                                     GObject.TYPE_STRING,  // real key
125                                                                     GObject.TYPE_STRING // real type
126                                                                     
127                                                                     
128                                                                 ] );
129                                                                 
130                                                                 this.data = [
131                                                                     { xtype: 'Roo', desc : "Roo Project" },
132                                                                     { xtype: 'Gtk', desc : "Gtk Project" },    
133                                                                     //{ xtype: 'JS', desc : "Javascript Class" }
134                                                                 ]
135                                                                 
136                                                                 this.loadData(this.data);
137                                                                     
138                                     },
139                                     loadData : function (data) {
140                                                                                 
141                                                 var iter = new Gtk.TreeIter();
142                                                 var el = this.el;
143                                                 data.forEach(function(p) {
144                                                     
145                                                     el.append(iter);
146                                                     
147                                                      
148                                                     el.set_value(iter, 0, p.xtype);
149                                                     el.set_value(iter, 1, p.desc);
150                                                     
151                                                 });
152                                                   
153                                                                          
154                                     },
155                                     id : "model"
156                                 }
157                             ]
158                         }
159                     ]
160                 },
161                 {
162                     xtype: Gtk.FileChooserWidget,
163                     pack : "pack_end,true,true,5",
164                     action : Gtk.FileChooserAction.SELECT_FOLDER,
165                     id : "dir",
166                     select_multiple : false
167                 }
168             ]
169         },
170         {
171             xtype: Gtk.Button,
172             pack : "add_action_widget,1",
173             label : "OK"
174         },
175         {
176             xtype: Gtk.Button,
177             pack : "add_action_widget,0",
178             label : "Cancel"
179         }
180     ]
181 });
182 EditProject.init();
183 XObject.cache['/EditProject'] = EditProject;