# HG changeset patch
# User Sergey Surkov <surkovsv93@gmail.com>
# Date 1481710485 -10800
# Node ID 99a02c6161b6392bd91e6755e64c73af54c4c9f4
# Parent  0b6b6024123064196e5496c6f647e21151074307
add check of new project path in Save As
add dialog window if selected directory is the current directory project, or already contains another project

diff -r 0b6b60241230 -r 99a02c6161b6 ProjectController.py
--- a/ProjectController.py	Wed Dec 14 12:44:30 2016 +0300
+++ b/ProjectController.py	Wed Dec 14 13:14:45 2016 +0300
@@ -415,6 +415,21 @@
         self.ClearChildren()
         self.ResetAppFrame(None)
 
+    def CheckNewProjectPath(self, old_project_path, new_project_path):
+        if old_project_path == new_project_path:
+            message = (_("Save path is the same as path of a project! \n"))
+            dialog = wx.MessageDialog(self.AppFrame, message, _("Error"), wx.OK | wx.ICON_ERROR)
+            dialog.ShowModal()
+            return False
+        else:
+            plc_file = os.path.join(new_project_path, "plc.xml")
+            if os.path.isfile(plc_file):
+                message = (_("Selected directory already contains another project. Overwrite? \n"))
+                dialog = wx.MessageDialog(self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
+                answer = dialog.ShowModal()
+                return answer == wx.ID_YES
+        return True
+
     def SaveProject(self, from_project_path=None):
         if self.CheckProjectPathPerm(False):
             if from_project_path is not None:
@@ -439,9 +454,10 @@
         if answer == wx.ID_OK:
             newprojectpath = dirdialog.GetPath()
             if os.path.isdir(newprojectpath):
-                self.ProjectPath, old_project_path = newprojectpath, self.ProjectPath
-                self.SaveProject(old_project_path)
-                self._setBuildPath(self.BuildPath)
+                if self.CheckNewProjectPath(self.ProjectPath, newprojectpath):
+                    self.ProjectPath, old_project_path = newprojectpath, self.ProjectPath
+                    self.SaveProject(old_project_path)
+                    self._setBuildPath(self.BuildPath)
                 return True
         return False