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