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 console = imports.console;
11 XObject = imports.XObject.XObject;
12 FixBug=new XObject({
13     xtype: Gtk.Window,
14     listeners : {
15         destroy_event : function (self, event) {
16              this.el.hide();
17                         return false;
18         },
19         show : function (self) {
20         print("ON SHOW!");
21         
22             this.el.fullscreen();
23             this.el.grab_focus();
24             this.el.set_keep_above(true);
25         }
26     },
27     border_width : 3,
28     default_height : 400,
29     default_width : 600,
30     title : "Select Active Bug",
31     deletable : true,
32     modal : true,
33     show : function(c) {
34         
35         if (!this.el) {
36             this.init();
37         }
38         var _this = this;
39         /*[ 'xtype'  ].forEach(function(k) {
40             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
41         });
42         // shouild set path..
43         */
44     
45         
46         this.el.show_all();
47        // this.get('/ok_button').el.set_sensitive(false);
48         
49         // block until we return.
50         //    var run_ret = this.el.run();
51         //    if (run_ret < 1 ) {
52         //        return false;
53         //    }
54         //    print("RUN RETURN : " + run_ret);
55         
56         //print(JSON.stringify(this.get('bug').getValue()));
57         //return this.get('bug').getValue();
58         //this.success = c.success;
59     },
60     items : [
61         {
62             xtype: Gtk.VBox,
63             pack : "add",
64             items : [
65                 {
66                     xtype: Gtk.HBox,
67                     pack : "pack_start,false,true,3",
68                     items : [
69                         {
70                             xtype: Gtk.Label,
71                             label : "On this project:"
72                         },
73                         {
74                             xtype: Gtk.ComboBox,
75                             listeners : {
76                                 changed : function (self) {
77                                     print("store: active id = " + this.el.get_active_id());
78                                     this.get('/ticket-store').reload();
79                                     
80                                     
81                                 }
82                             },
83                             id : "project-select",
84                             init : function() {
85                                  this.el = new Gtk.ComboBox.with_entry();
86                                                             
87                                                             
88                                 this.model  = new XObject(this.model);
89                                 this.model.init();
90                                 this.el.set_model(this.model.el);
91                                 this.el.set_entry_text_column (0);
92                                 XObject.prototype.init.call(this);
93                                 
94                                  var t = this;
95                                 imports.Projects.Projects.fetch(  function(res) { 
96                                      t.load(res);
97                                 });
98                             },
99                             load : function(tr) {
100                                   this.model.el.clear();
101                                   this.raw_data = tr;                     
102                                      for(var i =0 ; i < tr.length; i++) {
103                                         var ret = {  };
104                                         this.model.el.append(ret);
105                                         //print(JSON.stringify(ret,null,4));
106                                        
107                                         this.model.el.set_value(ret.iter, 0, '' + tr[i].code + " - " + tr[i].name );
108                                         this.model.el.set_value(ret.iter, 1, '' + tr[i].id  );
109                                  
110                                         
111                                     }     
112                                     
113                             },
114                             model : {
115                                 xtype: Gtk.ListStore,
116                                 id : "project-store",
117                                 init : function() {
118                                     XObject.prototype.init.call(this);
119                                     this.el.set_column_types ( 3, [
120                                            GObject.TYPE_STRING, // file  
121                                           GObject.TYPE_STRING, // added
122                                           GObject.TYPE_STRING, // removed
123                                       ] );
124                                 }
125                             }
126                         },
127                         {
128                             xtype: Gtk.Button,
129                             listeners : {
130                                 button_press_event : function (self, event) {
131                                  
132                                     FixBug.el.hide();
133                                 }
134                             },
135                             height_request : 90,
136                             label : "Not working on Project",
137                             pack : "add"
138                         },
139                         {
140                             xtype: Gtk.Button,
141                             listeners : {
142                                 button_press_event : function (self, event) {
143                                 
144                                    FixBug.el.hide();
145                                 }
146                             },
147                             id : "ok_button",
148                             label : "Working on Selected Ticket",
149                             pack : "add"
150                         }
151                     ]
152                 },
153                 {
154                     xtype: Gtk.HBox,
155                     pack : "pack_end,true,true,3",
156                     items : [
157                         {
158                             xtype: Gtk.VBox,
159                             pack : "pack_start,false,true,3",
160                             items : [
161                                 {
162                                     xtype: Gtk.HBox,
163                                     pack : "pack_start,false,true,3",
164                                     items : [
165                                         {
166                                             xtype: Gtk.Entry,
167                                             pack : "pack_start,false,true,3"
168                                         },
169                                         {
170                                             xtype: Gtk.Button,
171                                             label : "Search",
172                                             pack : "pack_end,false,true,3",
173                                             use_stock : true
174                                         }
175                                     ]
176                                 },
177                                 {
178                                     xtype: Gtk.ScrolledWindow,
179                                     pack : "pack_end,true,true,3",
180                                     shadow_type : Gtk.ShadowType.IN,
181                                     items : [
182                                         {
183                                             xtype: Gtk.TreeView,
184                                             id : "ticket-view",
185                                             pack : "add",
186                                             headers_visible : false,
187                                             init : function() {
188                                                 XObject.prototype.init.call(this);
189                                                 var description = new Pango.FontDescription.c_new();
190                                                 description.set_size(8000);
191                                                 this.el.modify_font(description);
192                                             
193                                                 this.selection = this.el.get_selection();
194                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
195                                                 var _t = this;
196                                             
197                                                 // is this really needed??
198                                                 this.selection.signal['changed'].connect(function() {
199                                                     print('selection changed');
200                                                 
201                                             
202                                                 });
203                                             
204                                             },
205                                             items : [
206                                                 {
207                                                     xtype: Gtk.ListStore,
208                                                     id : "ticket-store",
209                                                     pack : "set_model",
210                                                     columns : [
211                                                             GObject.TYPE_STRING, // title 
212                                                             GObject.TYPE_STRING, // tip
213                                                             GObject.TYPE_STRING // source..
214                                                     ],
215                                                     init : function() {
216                                                         XObject.prototype.init.call(this);
217                                                     
218                                                         this.el.set_column_types ( 2, [
219                                                             GObject.TYPE_STRING,  // real key
220                                                             GObject.TYPE_STRING // real type
221                                                             
222                                                             
223                                                         ] );
224                                                     
225                                                     
226                                                         
227                                                         // var t = this;
228                                                         //imports.Projects.Projects.fetch(  function(res) { 
229                                                         //    t.loadData(res);
230                                                        // });
231                                                             
232                                                                                     
233                                                     },
234                                                     loadData : function (data) {
235                                                             print("loading data");
236                                                                                         
237                                                         var el = this.el;
238                                                         data.forEach(function(p) {
239                                                             var ret = {};
240                                                             el.append(ret);
241                                                            //print("ADD " + p.name);
242                                                              
243                                                             el.set_value(ret.iter, 0, p.id);
244                                                             el.set_value(ret.iter, 1,   p.code + ' - ' + p.name );
245                                                             
246                                                         });
247                                                                   
248                                                                                          
249                                                     },
250                                                     reload : function() {
251                                                      
252                                                         var active_id = this.get('/project-select').el.get_active();
253                                                          
254                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
255                                                         
256                                                         var _t = this;
257                                                         
258                                                         imports.Tasks.Tasks.query({
259                                                             project_id : project_id,
260                                                             'query[filter]' : 'me'
261                                                         }, function(res) { 
262                                                             print(JSON.stringify(res,null,4));
263                                                             _this.loadData(res);
264                                                         });
265                                                          
266                                                         
267                                                     }
268                                                 },
269                                                 {
270                                                     xtype: Gtk.TreeViewColumn,
271                                                     pack : "append_column",
272                                                     init : function() {
273                                                         XObject.prototype.init.call(this);
274                                                         this.el.add_attribute(this.items[0].el , 'markup', 0 );
275                                                     },
276                                                     items : [
277                                                         {
278                                                             xtype: Gtk.CellRendererText,
279                                                             pack : "pack_start"
280                                                         }
281                                                     ]
282                                                 }
283                                             ]
284                                         }
285                                     ]
286                                 }
287                             ]
288                         },
289                         {
290                             xtype: Gtk.VBox,
291                             pack : "pack_start,true,true,3",
292                             items : [
293                                 {
294                                     xtype: Gtk.HBox,
295                                     pack : "pack_start,false,true,3",
296                                     items : [
297                                         {
298                                             xtype: Gtk.Label,
299                                             label : "I am doing this:",
300                                             pack : "pack_start,false,true,3"
301                                         },
302                                         {
303                                             xtype: Gtk.Entry,
304                                             pack : "pack_start,true,true,3"
305                                         }
306                                     ]
307                                 },
308                                 {
309                                     xtype: Gtk.HBox,
310                                     pack : "pack_start,false,true,3",
311                                     items : [
312                                         {
313                                             xtype: Gtk.Label,
314                                             label : "Since:",
315                                             pack : "pack_start,false,true,3"
316                                         },
317                                         {
318                                             xtype: Gtk.Entry,
319                                             pack : "pack_start,false,false,3",
320                                             width_request : 80
321                                         },
322                                         {
323                                             xtype: Gtk.Label,
324                                             label : "Until",
325                                             pack : "pack_start,false,true,3"
326                                         },
327                                         {
328                                             xtype: Gtk.Entry,
329                                             pack : "pack_start,true,true,3"
330                                         }
331                                     ]
332                                 },
333                                 {
334                                     xtype: Gtk.ScrolledWindow,
335                                     pack : "add",
336                                     id : "RightEditor",
337                                     items : [
338                                         {
339                                             xtype: Gtk.TextView,
340                                             editable : false,
341                                             id : "view",
342                                             indent_width : 4,
343                                             pack : "add",
344                                             auto_indent : true,
345                                             init : function() {
346                                                 XObject.prototype.init.call(this);
347                                                 var description = Pango.font_description_from_string("monospace");
348                                             
349                                                 description.set_size(8000);
350                                                 this.el.modify_font(description);
351                                             
352                                             },
353                                             load : function(str) {
354                                             
355                                             // show the help page for the active node..
356                                              
357                                             
358                                             
359                                              
360                                                 this.el.get_buffer().set_text(str, str.length);
361                                              
362                                                 
363                                                  var buf = this.el.get_buffer();
364                                                  
365                                                  
366                                                 
367                                             },
368                                             show_line_numbers : true,
369                                             items : [
370                                                 {
371                                                     xtype: GtkSource.Buffer,
372                                                     listeners : {
373                                                         changed : function (self) {
374                                                             /*
375                                                             var s = new Gtk.TextIter();
376                                                             var e = new Gtk.TextIter();
377                                                             this.el.get_start_iter(s);
378                                                             this.el.get_end_iter(e);
379                                                             var str = this.el.get_text(s,e,true);
380                                                             try {
381                                                                 Seed.check_syntax('var e = ' + str);
382                                                             } catch (e) {
383                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
384                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
385                                                                    }));
386                                                                 //print("SYNTAX ERROR IN EDITOR");   
387                                                                 //print(e);
388                                                                 //console.dump(e);
389                                                                 return;
390                                                             }
391                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
392                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
393                                                                    }));
394                                                             
395                                                              this.get('/LeftPanel.model').changed(  str , false);
396                                                              */
397                                                         }
398                                                     },
399                                                     pack : "set_buffer"
400                                                 }
401                                             ]
402                                         }
403                                     ]
404                                 }
405                             ]
406                         }
407                     ]
408                 }
409             ]
410         }
411     ]
412 });
413 FixBug.init();
414 XObject.cache['/FixBug'] = FixBug;