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