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.HPaned,
155                     pack : "pack_end,true,true,3",
156                     items : [
157                         {
158                             xtype: Gtk.VBox,
159                             pack : "add",
160                             width_request : 400,
161                             items : [
162                                 {
163                                     xtype: Gtk.HBox,
164                                     pack : "pack_start,false,true,3",
165                                     items : [
166                                         {
167                                             xtype: Gtk.Entry,
168                                             listeners : {
169                                                 key_release_event : function (self, event) {
170                                                     print(JSON.stringify(event,null,4)); //.keyval);
171                                                     return true;
172                                                 }
173                                             },
174                                             id : "search-entry",
175                                             pack : "pack_start,true,true,3"
176                                         },
177                                         {
178                                             xtype: Gtk.Button,
179                                             listeners : {
180                                                 activate : function (self) {
181                                                 
182                                                      
183                                                 },
184                                                 clicked : function (self) {
185                                                 
186                                                 }
187                                             },
188                                             label : "Search",
189                                             pack : "pack_end,false,true,3",
190                                             use_stock : true
191                                         }
192                                     ]
193                                 },
194                                 {
195                                     xtype: Gtk.ScrolledWindow,
196                                     pack : "pack_end,true,true,3",
197                                     shadow_type : Gtk.ShadowType.IN,
198                                     items : [
199                                         {
200                                             xtype: Gtk.TreeView,
201                                             fixed_height_mode : true,
202                                             id : "ticket-view",
203                                             pack : "add",
204                                             can_focus : true,
205                                             headers_visible : false,
206                                             init : function() {
207                                                 XObject.prototype.init.call(this);
208                                                 var description = new Pango.FontDescription.c_new();
209                                                 description.set_size(10000);
210                                                 this.el.modify_font(description);
211                                             
212                                                 this.selection = this.el.get_selection();
213                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
214                                                 var _t = this;
215                                             
216                                                 // is this really needed??
217                                                 this.selection.signal['changed'].connect(function() {
218                                                     print('selection changed');
219                                                 
220                                             
221                                                 });
222                                             
223                                             },
224                                             items : [
225                                                 {
226                                                     xtype: Gtk.ListStore,
227                                                     id : "ticket-store",
228                                                     pack : "set_model",
229                                                     columns : [
230                                                             GObject.TYPE_STRING, // title 
231                                                             GObject.TYPE_STRING, // tip
232                                                             GObject.TYPE_STRING // source..
233                                                     ],
234                                                     init : function() {
235                                                         XObject.prototype.init.call(this);
236                                                     
237                                                         this.el.set_column_types ( 2, [
238                                                             GObject.TYPE_STRING,  // real key
239                                                             GObject.TYPE_STRING // real type
240                                                             
241                                                             
242                                                         ] );
243                                                     
244                                                     
245                                                         
246                                                         // var t = this;
247                                                         //imports.Projects.Projects.fetch(  function(res) { 
248                                                         //    t.loadData(res);
249                                                        // });
250                                                             
251                                                                                     
252                                                     },
253                                                     loadData : function (data) {
254                                                             print("loading data");
255                                                                                         
256                                                         var el = this.el;
257                                                         this.el.clear();
258                                                         data.forEach(function(p) {
259                                                             var ret = {};
260                                                             el.append(ret);
261                                                            //print("ADD " + p.name);
262                                                              
263                                                             el.set_value(ret.iter, 0, p.id);
264                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
265                                                                 '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
266                                                                  '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
267                                                                  '</span>'
268                                                                  
269                                                                   );
270                                                             
271                                                         });
272                                                                   
273                                                                                          
274                                                     },
275                                                     reload : function() {
276                                                      
277                                                         var active_id = this.get('/project-select').el.get_active();
278                                                          
279                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
280                                                         
281                                                         var _t = this;
282                                                         
283                                                         imports.Tasks.Tasks.query({
284                                                             project_id : project_id,
285                                                             'query[filter]' : 'me'
286                                                         }, function(res) { 
287                                                             print(JSON.stringify(res,null,4));
288                                                             _t.loadData(res);
289                                                         });
290                                                          
291                                                         
292                                                     }
293                                                 },
294                                                 {
295                                                     xtype: Gtk.TreeViewColumn,
296                                                     pack : "append_column",
297                                                     sizing : Gtk.TreeViewColumnSizing.FIXED,
298                                                     init : function() {
299                                                         XObject.prototype.init.call(this);
300                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
301                                                     },
302                                                     items : [
303                                                         {
304                                                             xtype: Gtk.CellRendererText,
305                                                             pack : "pack_start"
306                                                         }
307                                                     ]
308                                                 }
309                                             ]
310                                         }
311                                     ]
312                                 }
313                             ]
314                         },
315                         {
316                             xtype: Gtk.VBox,
317                             pack : "add",
318                             items : [
319                                 {
320                                     xtype: Gtk.HBox,
321                                     pack : "pack_start,false,true,3",
322                                     items : [
323                                         {
324                                             xtype: Gtk.Label,
325                                             label : "I am doing this:",
326                                             pack : "pack_start,false,true,3"
327                                         },
328                                         {
329                                             xtype: Gtk.Entry,
330                                             pack : "pack_start,true,true,3"
331                                         }
332                                     ]
333                                 },
334                                 {
335                                     xtype: Gtk.HBox,
336                                     pack : "pack_start,false,true,3",
337                                     items : [
338                                         {
339                                             xtype: Gtk.Label,
340                                             label : "Since:",
341                                             pack : "pack_start,false,true,3"
342                                         },
343                                         {
344                                             xtype: Gtk.Entry,
345                                             pack : "pack_start,false,false,3",
346                                             width_request : 80
347                                         },
348                                         {
349                                             xtype: Gtk.Label,
350                                             label : "Until",
351                                             pack : "pack_start,false,true,3"
352                                         },
353                                         {
354                                             xtype: Gtk.Entry,
355                                             pack : "pack_start,true,true,3"
356                                         }
357                                     ]
358                                 },
359                                 {
360                                     xtype: Gtk.ScrolledWindow,
361                                     pack : "add",
362                                     id : "RightEditor",
363                                     items : [
364                                         {
365                                             xtype: Gtk.TextView,
366                                             editable : false,
367                                             id : "view",
368                                             indent_width : 4,
369                                             pack : "add",
370                                             auto_indent : true,
371                                             init : function() {
372                                                 XObject.prototype.init.call(this);
373                                                 var description = Pango.font_description_from_string("monospace");
374                                             
375                                                 description.set_size(8000);
376                                                 this.el.modify_font(description);
377                                             
378                                             },
379                                             load : function(str) {
380                                             
381                                             // show the help page for the active node..
382                                              
383                                             
384                                             
385                                              
386                                                 this.el.get_buffer().set_text(str, str.length);
387                                              
388                                                 
389                                                  var buf = this.el.get_buffer();
390                                                  
391                                                  
392                                                 
393                                             },
394                                             show_line_numbers : true,
395                                             items : [
396                                                 {
397                                                     xtype: GtkSource.Buffer,
398                                                     listeners : {
399                                                         changed : function (self) {
400                                                             /*
401                                                             var s = new Gtk.TextIter();
402                                                             var e = new Gtk.TextIter();
403                                                             this.el.get_start_iter(s);
404                                                             this.el.get_end_iter(e);
405                                                             var str = this.el.get_text(s,e,true);
406                                                             try {
407                                                                 Seed.check_syntax('var e = ' + str);
408                                                             } catch (e) {
409                                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
410                                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
411                                                                    }));
412                                                                 //print("SYNTAX ERROR IN EDITOR");   
413                                                                 //print(e);
414                                                                 //console.dump(e);
415                                                                 return;
416                                                             }
417                                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
418                                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
419                                                                    }));
420                                                             
421                                                              this.get('/LeftPanel.model').changed(  str , false);
422                                                              */
423                                                         }
424                                                     },
425                                                     pack : "set_buffer"
426                                                 }
427                                             ]
428                                         }
429                                     ]
430                                 }
431                             ]
432                         }
433                     ]
434                 }
435             ]
436         }
437     ]
438 });
439 FixBug.init();
440 XObject.cache['/FixBug'] = FixBug;