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

stable gtklib: centralize file overwrite confirmation

On Linux, file overwrite confirmation occurs twice:
- due to dlg.set_do_overwrite_confirmation(True)
- and at the caller of gtklib.NativeSaveFileDialogWrapper()

This changeset adds overwrite confirmation to
gtklib.NativeSaveFileDialogWrapper() so that it works the
same way on Windows and Linux.

Changeset d72d0c6765e4

Parent e99854462f58

by Emmanuel Rosa

Changes to one file · Browse files at d72d0c6765e4 Showing diff from parent e99854462f58 Diff from another changeset...

 
16
17
18
19
 
20
21
22
 
162
163
164
165
166
 
 
167
168
 
 
169
170
171
 
217
218
219
220
221
222
223
 
233
234
235
 
 
 
 
 
 
 
 
 
 
 
 
236
237
238
 
16
17
18
 
19
20
21
22
 
162
163
164
 
 
165
166
167
 
168
169
170
171
172
 
218
219
220
 
221
222
223
 
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
@@ -16,7 +16,7 @@
 from tortoisehg.util.i18n import _  from tortoisehg.util import paths, hglib, thread2   -from tortoisehg.hgtk import hgtk +from tortoisehg.hgtk import hgtk, gdialog    if gtk.gtk_version < (2, 14, 0):   # at least on 2.12.12, gtk widgets can be confused by control @@ -162,10 +162,11 @@
  """run the file dialog, either return a file name, or False if   the user aborted the dialog"""   try: - import win32gui, win32con, pywintypes - return self.runWindows() + import win32gui, win32con, pywintypes + filepath = self.runWindows()   except ImportError: - return self.runCompatible() + filepath = self.runCompatible() + return self.overwriteConfirmation(filepath)     def runWindows(self):   @@ -217,7 +218,6 @@
  buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,   gtk.STOCK_SAVE, gtk.RESPONSE_OK)   dlg = gtk.FileChooserDialog(self.title, None, action, buttons) - dlg.set_do_overwrite_confirmation(True)   dlg.set_default_response(gtk.RESPONSE_OK)   dlg.set_current_folder(self.initial)   if not self.open: @@ -233,6 +233,18 @@
  result = False   dlg.destroy()   return result + + def overwriteConfirmation(self, filepath): + result = filepath + if os.path.exists(filepath): + res = gdialog.Confirm(_('Confirm Overwrite'), [], None, + _('The file "%s" already exists!\n\n' + 'Do you want to overwrite it?') % filepath).run() + if res == gtk.RESPONSE_YES: + os.remove(filepath) + else: + result = False + return result    class NativeFolderSelectDialog:   """Wrap the windows folder dialog, or display default gtk dialog if