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