FixBug.bjs
[gitlive] / FixBug.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 FixBug=new XObject({
15     xtype: Gtk.Dialog,
16     listeners : {
17         destroy_event : function (self, event) {
18              this.el.hide();
19                         return false;
20         },
21         response : function (self, id) {
22           // hide
23              if (id < 1) {
24                 this.el.hide();
25                 return;
26             }
27             if (typeof(this.get('bug').getValue()) != 'object') {
28                 print("ERROR");
29                 return;
30             }
31          
32             this.el.hide();
33                 
34             //var val = this.get('bug').getValue();
35              //   Seed.print(val);
36         }
37     },
38     border_width : 3,
39     default_height : 400,
40     default_width : 600,
41     title : "Select Active Bug",
42     deletable : true,
43     modal : true,
44     show : function(c) {
45         
46         if (!this.el) {
47             this.init();
48         }
49         var _this = this;
50         /*[ 'xtype'  ].forEach(function(k) {
51             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
52         });
53         // shouild set path..
54         */
55         this.el.show_all();
56         
57         // block until we return.
58         this.el.run();
59         
60         print(JSON.serialize(this.get('bug').getValue()));
61         
62         //this.success = c.success;
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                             label : "Select Active Bug:",
78                             pack : "pack_start,false,true,3"
79                         },
80                         {
81                             xtype: Gtk.ComboBox,
82                             listeners : {
83                                 changed : function (self) {
84                                     var d = this.getValue();
85                                     this.get('/view').load(d.description);
86                                 }
87                             },
88                             id : "bug",
89                             pack : "pack_end,true,true,3",
90                             getValue : function() {
91                                  var ix = this.el.get_active();
92                                 if (ix < 0 ) {
93                                     return '';
94                                 }
95                                 return this.get('model').data[ix];
96                             },
97                             init : function() {
98                                 XObject.prototype.init.call(this);
99                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
100                             },
101                             setValue : function(v)
102                                             {
103                                                 var el = this.el;
104                                                 el.set_active(-1);
105                                                 this.get('model').data.forEach(function(n, ix) {
106                                                     if (v == n.xtype) {
107                                                         el.set_active(ix);
108                                                         return false;
109                                                     }
110                                                 });
111                                             },
112                             items : [
113                                 {
114                                     xtype: Gtk.CellRendererText,
115                                     pack : "pack_start"
116                                 },
117                                 {
118                                     xtype: Gtk.ListStore,
119                                     id : "model",
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                                             var Tickets = imports.Tickets.Tickets;
131                                             
132                                             this.data = Tickets.fetchBugs("http://www.roojs.com/mtrack/index.php/Gitlive/web.hex");
133                                     /*        this.data = [
134                                                 { xtype: 'Roo', desc : "Roo Project" },
135                                                 { xtype: 'Gtk', desc : "Gtk Project" },    
136                                                 //{ xtype: 'JS', desc : "Javascript Class" }
137                                             ]
138                                       */      
139                                             this.loadData(this.data);
140                                                                     
141                                     },
142                                     loadData : function (data) {
143                                                                                 
144                                                 var iter = new Gtk.TreeIter();
145                                                 var el = this.el;
146                                                 data.forEach(function(p) {
147                                                     
148                                                     el.append(iter);
149                                                     
150                                                      
151                                                     el.set_value(iter, 0, p.id);
152                                                     el.set_value(iter, 1, '#' + p.id + ' - ' + p.summary );
153                                                     
154                                                 });
155                                                   
156                                                                          
157                                     }
158                                 }
159                             ]
160                         }
161                     ]
162                 },
163                 {
164                     xtype: Gtk.ScrolledWindow,
165                     pack : "add",
166                     id : "RightEditor",
167                     items : [
168                         {
169                             xtype: Gtk.TextView,
170                             editable : false,
171                             id : "view",
172                             indent_width : 4,
173                             pack : "add",
174                             auto_indent : true,
175                             init : function() {
176                                 XObject.prototype.init.call(this);
177                                  var description = Pango.Font.description_from_string("monospace")
178                                 description.set_size(8000);
179                                 this.el.modify_font(description);
180                             
181                             },
182                             load : function(str) {
183                             
184                             // show the help page for the active node..
185                              
186                             
187                             
188                              
189                                 this.el.get_buffer().set_text(str, str.length);
190                              
191                                 
192                                  var buf = this.el.get_buffer();
193                                  
194                                  
195                                 
196                             },
197                             show_line_numbers : true,
198                             items : [
199                                 {
200                                     xtype: GtkSource.Buffer,
201                                     listeners : {
202                                         changed : function (self) {
203                                             /*
204                                             var s = new Gtk.TextIter();
205                                             var e = new Gtk.TextIter();
206                                             this.el.get_start_iter(s);
207                                             this.el.get_end_iter(e);
208                                             var str = this.el.get_text(s,e,true);
209                                             try {
210                                                 Seed.check_syntax('var e = ' + str);
211                                             } catch (e) {
212                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
213                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
214                                                    }));
215                                                 //print("SYNTAX ERROR IN EDITOR");   
216                                                 //print(e);
217                                                 //console.dump(e);
218                                                 return;
219                                             }
220                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
221                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
222                                                    }));
223                                             
224                                              this.get('/LeftPanel.model').changed(  str , false);
225                                              */
226                                         }
227                                     },
228                                     pack : "set_buffer"
229                                 }
230                             ]
231                         }
232                     ]
233                 }
234             ]
235         },
236         {
237             xtype: Gtk.Button,
238             pack : "add_action_widget,1",
239             label : "OK"
240         },
241         {
242             xtype: Gtk.Button,
243             pack : "add_action_widget,0",
244             label : "Cancel"
245         }
246     ]
247 });
248 FixBug.init();
249 XObject.cache['/FixBug'] = FixBug;