Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

update: improve the handling of dialog responses

Changeset c18b6db78eaf

Parent 59337c5fc902

by Yuki KODAMA

Changes to one file · Browse files at c18b6db78eaf Showing diff from parent 59337c5fc902 Diff from another changeset...

 
19
20
21
22
 
23
24
25
 
32
33
34
35
36
37
38
 
54
55
56
57
58
 
59
60
61
 
106
107
108
109
110
111
112
 
 
 
113
114
115
 
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 
163
164
165
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
168
169
170
171
 
172
173
 
174
175
176
 
177
178
179
180
181
182
183
184
 
 
185
186
187
 
311
312
313
314
 
 
 
315
316
317
 
322
323
324
325
 
326
327
328
 
19
20
21
 
22
23
24
25
 
32
33
34
 
35
36
37
 
53
54
55
 
56
57
58
59
60
 
105
106
107
 
 
 
 
108
109
110
111
112
113
 
142
143
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
175
176
 
177
178
179
 
180
181
182
183
184
185
186
 
 
187
188
189
190
191
 
315
316
317
 
318
319
320
321
322
323
 
328
329
330
 
331
332
333
334
@@ -19,7 +19,7 @@
 from tortoisehg.hgtk import hgcmd, gtklib, gdialog    MODE_NORMAL = 'normal' -MODE_UPDATING = 'updating' +MODE_WORKING = 'working'    class UpdateDialog(gtk.Dialog):   """ Dialog to update Mercurial repo """ @@ -32,7 +32,6 @@
  self.set_size_request(450, -1)   self.set_has_separator(False)   self.connect('response', self.dialog_response) - self.connect('delete-event', self.delete_event)     try:   repo = hg.repository(ui.ui(), path=paths.find_root()) @@ -54,8 +53,8 @@
  ## revision label & combobox   self.revcombo = combo = gtk.combo_box_entry_new_text()   entry = combo.child - entry.connect('activate', lambda b: self.update(repo))   entry.set_width_chars(38) + entry.connect('activate', lambda b: self.response(gtk.RESPONSE_OK))   table.add_row(_('Update to:'), combo, padding=False)     ## update method @@ -106,10 +105,9 @@
  self.cmd.hide()   self.vbox.pack_start(self.cmd, True, True, 6)   - # cancel button - self.cancelbtn = gtk.Button(_('Cancel')) - self.cancelbtn.connect('clicked', self.cancel_clicked) - self.action_area.pack_end(self.cancelbtn) + # abort button + self.abortbtn = self.add_button(_('Abort'), gtk.RESPONSE_CANCEL) + self.abortbtn.hide()     def build_summaries(self):   table = self.tables['summary'] @@ -144,44 +142,50 @@
  table.show_all()   self.revcombo.connect('changed', lambda b: self.update_summaries())   - def dialog_response(self, dialog, response_id): - if response_id == gtk.RESPONSE_OK: - self.update(self.repo) - elif not self.cmd.is_alive(): - self.destroy() - - def delete_event(self, dialog, event): - if self.cmd.is_alive(): - ret = gdialog.Confirm(_('Confirm Cancel'), [], self, - _('Do you want to cancel updating?')).run() - if ret == gtk.RESPONSE_YES: - self.cancel_clicked(self.cancelbtn) - return True - self.destroy() - - def cancel_clicked(self, button): + def abort(self):   self.cmd.stop()   self.cmd.show_log()   self.switch_to(MODE_NORMAL, cmd=False)   + def dialog_response(self, dialog, response_id): + # Update button + if response_id == gtk.RESPONSE_OK: + self.update(self.repo) + # Close button or dialog closing by the user + elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT): + if self.cmd.is_alive(): + ret = gdialog.Confirm(_('Confirm Abort'), [], self, + _('Do you want to abort?')).run() + if ret == gtk.RESPONSE_YES: + self.abort() + else: + return # close dialog + # Abort button + elif response_id == gtk.RESPONSE_CANCEL: + self.abort() + else: + raise _('unexpected response id: %s') % response_id + + self.run() # don't close dialog +   def switch_to(self, mode, cmd=True):   if mode == MODE_NORMAL:   normal = True   self.closebtn.grab_focus() - elif mode == MODE_UPDATING: + elif mode == MODE_WORKING:   normal = False - self.cancelbtn.grab_focus() + self.abortbtn.grab_focus()   else:   raise _('unknown mode name: %s') % mode - updating = not normal + working = not normal     for table in self.tables.values():   table.set_sensitive(normal)   self.updatebtn.set_property('visible', normal)   self.closebtn.set_property('visible', normal)   if cmd: - self.cmd.set_property('visible', updating) - self.cancelbtn.set_property('visible', updating) + self.cmd.set_property('visible', working) + self.abortbtn.set_property('visible', working)     def show_summaries(self, visible=True):   if visible and not hasattr(self, 'ctxs'): @@ -311,7 +315,9 @@
  elif ret['merge']:   pass # no args   elif ret['cancel']: - self.destroy() + self.cmd.log.append(_('[user canceled]\n'), error=True) + self.switch_to(MODE_WORKING) + self.abort()   return   else:   raise _('invalid dialog result: %s') % ret @@ -322,7 +328,7 @@
  self.notify_func(self.notify_args)   if returncode == 0 and not self.cmd.is_show_log():   self.destroy() - self.switch_to(MODE_UPDATING) + self.switch_to(MODE_WORKING)   self.cmd.execute(cmdline, cmd_done)     def set_notify_func(self, func, *args):