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