Attribute changed old-javascript
[app.Builder.js] / old-javascript / Builder3 / 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.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().pack_start(e.el,true,true,3);
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                                                     return true;
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 el = this.el;
143                                                 data.forEach(function(p) {
144                                                     var ret = {};
145                                                     el.append(ret);
146                                                     
147                                                      
148                                                     el.set_value(ret.iter, 0, p.xtype);
149                                                     el.set_value(ret.iter, 1, p.desc);
150                                                     
151                                                 });
152                                                   
153                                                                          
154                                     },
155                                     id : "model"
156                                 }
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;