Fixed bug when editing file name and close editor without modification
authorLaurent Bessard
Tue, 04 Jun 2013 17:29:31 +0200
changeset 1219 f5da9702685a
parent 1218 a5a6072ac944
child 1220 16c283246241
Fixed bug when editing file name and close editor without modification
controls/FolderTree.py
--- a/controls/FolderTree.py	Tue Jun 04 09:56:03 2013 +0200
+++ b/controls/FolderTree.py	Tue Jun 04 17:29:31 2013 +0200
@@ -203,19 +203,23 @@
             event.Veto()
     
     def OnTreeEndLabelEdit(self, event):
-        old_filepath = self.GetPath(event.GetItem())
-        new_filepath = os.path.join(os.path.split(old_filepath)[0], event.GetLabel())
-        if new_filepath != old_filepath:
-            if not os.path.exists(new_filepath):
-                os.rename(old_filepath, new_filepath)
-                event.Skip()
-            else:
-                message =  wx.MessageDialog(self, 
-                    _("File '%s' already exists!") % event.GetLabel(), 
-                    _("Error"), wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-                event.Veto()
+        new_name = event.GetLabel()
+        if new_name != "":
+            old_filepath = self.GetPath(event.GetItem())
+            new_filepath = os.path.join(os.path.split(old_filepath)[0], new_name)
+            if new_filepath != old_filepath:
+                if not os.path.exists(new_filepath):
+                    os.rename(old_filepath, new_filepath)
+                    event.Skip()
+                else:
+                    message =  wx.MessageDialog(self, 
+                        _("File '%s' already exists!") % new_name, 
+                        _("Error"), wx.OK|wx.ICON_ERROR)
+                    message.ShowModal()
+                    message.Destroy()
+                    event.Veto()
+        else:
+            event.Skip()
     
     def OnFilterChanged(self, event):
         self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()]