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