Sample/EditProject.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 = [ fn ];
62                 
63                 var pr = imports.Builder.Provider.ProjectManager.ProjectManager.update(this.project);
64                 
65                 this.success(pr);
66                 Seed.print(id);
67         }
68     },
69     items : [
70         {
71             xtype: Gtk.VBox,
72             pack : function(p,e) {
73                         p.el.get_content_area().add(e.el)
74                     },
75             items : [
76                 {
77                     xtype: Gtk.HBox,
78                     pack : "pack_start,false,true,3",
79                     items : [
80                         {
81                             xtype: Gtk.Label,
82                             pack : "pack_start,false,true,3",
83                             label : "Project type :"
84                         },
85                         {
86                             xtype: Gtk.ComboBox,
87                             pack : "pack_end,true,true,3",
88                             id : "xtype",
89                             setValue : function(v)
90                                             {
91                                                 var el = this.el;
92                                                 el.set_active(-1);
93                                                 this.get('model').data.forEach(function(n, ix) {
94                                                     if (v == n.xtype) {
95                                                         el.set_active(ix);
96                                                         return false;
97                                                     }
98                                                 });
99                                             },
100                             getValue : function() {
101                                  var ix = this.el.get_active();
102                                         if (ix < 0 ) {
103                                             return '';
104                                         }
105                                         return this.get('model').data[ix].xtype;
106                             },
107                             init : function() {
108                                 XObject.prototype.init.call(this);
109                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
110                             },
111                             items : [
112                                 {
113                                     xtype: Gtk.CellRendererText,
114                                     pack : "pack_start"
115                                 },
116                                 {
117                                     xtype: Gtk.ListStore,
118                                     pack : "set_model",
119                                     init : function() {
120                                         XObject.prototype.init.call(this);
121                                     
122                                                                 this.el.set_column_types ( 2, [
123                                                                     GObject.TYPE_STRING,  // real key
124                                                                     GObject.TYPE_STRING // real type
125                                                                     
126                                                                     
127                                                                 ] );
128                                                                 
129                                                                 this.data = [
130                                                                     { xtype: 'Roo', desc : "Roo Project" },
131                                                                     { xtype: 'Gtk', desc : "Gtk Project" },    
132                                                                     //{ xtype: 'JS', desc : "Javascript Class" }
133                                                                 ]
134                                                                 
135                                                                 this.loadData(this.data);
136                                                                     
137                                     },
138                                     loadData : function (data) {
139                                                                                 
140                                                 var iter = new Gtk.TreeIter();
141                                                 var el = this.el;
142                                                 data.forEach(function(p) {
143                                                     
144                                                     el.append(iter);
145                                                     
146                                                      
147                                                     el.set_value(iter, 0, p.xtype);
148                                                     el.set_value(iter, 1, p.desc);
149                                                     
150                                                 });
151                                                   
152                                                                          
153                                     },
154                                     id : "model"
155                                 }
156                             ]
157                         }
158                     ]
159                 },
160                 {
161                     xtype: Gtk.FileChooserWidget,
162                     pack : "pack_end,true,true,5",
163                     action : Gtk.FileChooserAction.SELECT_FOLDER,
164                     id : "dir",
165                     select_multiple : false
166                 }
167             ]
168         },
169         {
170             xtype: Gtk.Button,
171             pack : "add_action_widget,1",
172             label : "OK"
173         },
174         {
175             xtype: Gtk.Button,
176             pack : "add_action_widget,0",
177             label : "Cancel"
178         }
179     ]
180 });
181 EditProject.init();
182 XObject.cache['/EditProject'] = EditProject;