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         var run_ret = this.el.run();
59         print("RUN RETURN : " + run_ret);
60         
61         //print(JSON.stringify(this.get('bug').getValue()));
62         return this.get('bug').getValue();
63         //this.success = c.success;
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                             label : "Select Active Bug:",
79                             pack : "pack_start,false,true,3"
80                         },
81                         {
82                             xtype: Gtk.ComboBox,
83                             listeners : {
84                                 changed : function (self) {
85                                     var d = this.getValue();
86                                     this.get('/view').load(d.description);
87                                 }
88                             },
89                             id : "bug",
90                             pack : "pack_end,true,true,3",
91                             getValue : function() {
92                                  var ix = this.el.get_active();
93                                 if (ix < 0 ) {
94                                     return '';
95                                 }
96                                 return this.get('model').data[ix];
97                             },
98                             init : function() {
99                                 XObject.prototype.init.call(this);
100                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
101                             },
102                             setValue : function(v)
103                                             {
104                                                 var el = this.el;
105                                                 el.set_active(-1);
106                                                 this.get('model').data.forEach(function(n, ix) {
107                                                     if (v == n.xtype) {
108                                                         el.set_active(ix);
109                                                         return false;
110                                                     }
111                                                 });
112                                             },
113                             items : [
114                                 {
115                                     xtype: Gtk.CellRendererText,
116                                     pack : "pack_start"
117                                 },
118                                 {
119                                     xtype: Gtk.ListStore,
120                                     id : "model",
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                                             var Tickets = imports.Tickets.Tickets;
132                                             
133                                             this.data = Tickets.fetchBugs("http://www.roojs.com/mtrack/index.php/Gitlive/web.hex");
134                                     /*        this.data = [
135                                                 { xtype: 'Roo', desc : "Roo Project" },
136                                                 { xtype: 'Gtk', desc : "Gtk Project" },    
137                                                 //{ xtype: 'JS', desc : "Javascript Class" }
138                                             ]
139                                       */      
140                                             this.loadData(this.data);
141                                                                     
142                                     },
143                                     loadData : function (data) {
144                                                                                 
145                                                 var iter = new Gtk.TreeIter();
146                                                 var el = this.el;
147                                                 data.forEach(function(p) {
148                                                     
149                                                     el.append(iter);
150                                                     
151                                                      
152                                                     el.set_value(iter, 0, p.id);
153                                                     el.set_value(iter, 1, '#' + p.id + ' - ' + p.summary );
154                                                     
155                                                 });
156                                                   
157                                                                          
158                                     }
159                                 }
160                             ]
161                         }
162                     ]
163                 },
164                 {
165                     xtype: Gtk.ScrolledWindow,
166                     pack : "add",
167                     id : "RightEditor",
168                     items : [
169                         {
170                             xtype: Gtk.TextView,
171                             editable : false,
172                             id : "view",
173                             indent_width : 4,
174                             pack : "add",
175                             auto_indent : true,
176                             init : function() {
177                                 XObject.prototype.init.call(this);
178                                  var description = Pango.Font.description_from_string("monospace")
179                                 description.set_size(8000);
180                                 this.el.modify_font(description);
181                             
182                             },
183                             load : function(str) {
184                             
185                             // show the help page for the active node..
186                              
187                             
188                             
189                              
190                                 this.el.get_buffer().set_text(str, str.length);
191                              
192                                 
193                                  var buf = this.el.get_buffer();
194                                  
195                                  
196                                 
197                             },
198                             show_line_numbers : true,
199                             items : [
200                                 {
201                                     xtype: GtkSource.Buffer,
202                                     listeners : {
203                                         changed : function (self) {
204                                             /*
205                                             var s = new Gtk.TextIter();
206                                             var e = new Gtk.TextIter();
207                                             this.el.get_start_iter(s);
208                                             this.el.get_end_iter(e);
209                                             var str = this.el.get_text(s,e,true);
210                                             try {
211                                                 Seed.check_syntax('var e = ' + str);
212                                             } catch (e) {
213                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
214                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
215                                                    }));
216                                                 //print("SYNTAX ERROR IN EDITOR");   
217                                                 //print(e);
218                                                 //console.dump(e);
219                                                 return;
220                                             }
221                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
222                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
223                                                    }));
224                                             
225                                              this.get('/LeftPanel.model').changed(  str , false);
226                                              */
227                                         }
228                                     },
229                                     pack : "set_buffer"
230                                 }
231                             ]
232                         }
233                     ]
234                 }
235             ]
236         },
237         {
238             xtype: Gtk.Button,
239             pack : "add_action_widget,0",
240             label : "Cancel"
241         },
242         {
243             xtype: Gtk.Button,
244             pack : "add_action_widget,1",
245             label : "OK"
246         }
247     ]
248 });
249 FixBug.init();
250 XObject.cache['/FixBug'] = FixBug;