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