Fix bug while renaming project file in FileManagementPanel
authorlaurent
Fri, 27 Jul 2012 00:38:45 +0200
changeset 794 5bbf57905011
parent 793 1b24b970a816
child 795 afcc13faecd5
Fix bug while renaming project file in FileManagementPanel
util/FileManagementPanel.py
--- a/util/FileManagementPanel.py	Wed Jul 25 17:37:29 2012 +0200
+++ b/util/FileManagementPanel.py	Fri Jul 27 00:38:45 2012 +0200
@@ -198,7 +198,19 @@
             event.Veto()
     
     def OnTreeEndLabelEdit(self, event):
-        event.Veto()
+        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()
     
     def OnFilterChanged(self, event):
         self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()]