# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1547457468 -10800
# Node ID 3487fd4fb9bf18412cb571ca678c4731ed36abaf
# Parent  f3aced6c5f8b4fa2d6e1a2e256c9f40d149d4325
fix 'SaveAs' to non-empty directory and directory without write permissions

diff -r f3aced6c5f8b -r 3487fd4fb9bf ProjectController.py
--- a/ProjectController.py	Sat Jan 12 15:02:17 2019 +0300
+++ b/ProjectController.py	Mon Jan 14 12:17:48 2019 +0300
@@ -549,10 +549,19 @@
             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"))
+            if not CheckPathPerm(new_project_path):
+                dialog = wx.MessageDialog(
+                    self.AppFrame,
+                    _('No write permissions in selected directory! \n'),
+                    _("Error"), wx.OK | wx.ICON_ERROR)
+                dialog.ShowModal()
+                return False
+            if not os.path.isdir(new_project_path) or len(os.listdir(new_project_path)) > 0:
+                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")
+                else:
+                    message = _("Selected directory isn't empty. Continue? \n")
                 dialog = wx.MessageDialog(
                     self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
                 answer = dialog.ShowModal()