Project: fixed some issue renaming files and directories via the active VCS.

Fri, 10 Apr 2020 14:48:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 10 Apr 2020 14:48:05 +0200
changeset 7518
6dea4abd3097
parent 7517
d6910340b538
child 7519
0e93f5167e71

Project: fixed some issue renaming files and directories via the active VCS.

eric6/APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.Project.Project.html file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.Project.ProjectBrowserModel.html file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsGit/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Project/Project.py file | annotate | diff | comparison | revisions
eric6/Project/ProjectBrowserModel.py file | annotate | diff | comparison | revisions
eric6/UI/BrowserModel.py file | annotate | diff | comparison | revisions
--- a/eric6/APIs/Python3/eric6.api	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/APIs/Python3/eric6.api	Fri Apr 10 14:48:05 2020 +0200
@@ -6886,8 +6886,10 @@
 eric6.Project.Project.Project.setTranslationPattern?4(pattern)
 eric6.Project.Project.Project.showMenu?7
 eric6.Project.Project.Project.sourceFile?7
+eric6.Project.Project.Project.startFileSystemMonitoring?4()
 eric6.Project.Project.Project.startStatusMonitor?4()
 eric6.Project.Project.Project.startswithProjectPath?4(path)
+eric6.Project.Project.Project.stopFileSystemMonitoring?4()
 eric6.Project.Project.Project.stopStatusMonitor?4()
 eric6.Project.Project.Project.unregisterProjectType?4(type_)
 eric6.Project.Project.Project.updateFileTypes?4()
@@ -6987,6 +6989,8 @@
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel.removeItem?4(name)
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel.renameItem?4(name, newFilename)
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel.repopulateItem?4(name)
+eric6.Project.ProjectBrowserModel.ProjectBrowserModel.startFileSystemMonitoring?4()
+eric6.Project.ProjectBrowserModel.ProjectBrowserModel.stopFileSystemMonitoring?4()
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel.updateVCSStatus?4(name, recursive=True)
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel.vcsStateChanged?7
 eric6.Project.ProjectBrowserModel.ProjectBrowserModel?1(parent)
Binary file eric6/Documentation/Help/source.qch has changed
--- a/eric6/Documentation/Help/source.qhp	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Documentation/Help/source.qhp	Fri Apr 10 14:48:05 2020 +0200
@@ -11078,6 +11078,7 @@
       <keyword name="Project.__initData" id="Project.__initData" ref="eric6.Project.Project.html#Project.__initData" />
       <keyword name="Project.__initDebugProperties" id="Project.__initDebugProperties" ref="eric6.Project.Project.html#Project.__initDebugProperties" />
       <keyword name="Project.__initProjectTypes" id="Project.__initProjectTypes" ref="eric6.Project.Project.html#Project.__initProjectTypes" />
+      <keyword name="Project.__isInPdata" id="Project.__isInPdata" ref="eric6.Project.Project.html#Project.__isInPdata" />
       <keyword name="Project.__loadDiagram" id="Project.__loadDiagram" ref="eric6.Project.Project.html#Project.__loadDiagram" />
       <keyword name="Project.__loadRecent" id="Project.__loadRecent" ref="eric6.Project.Project.html#Project.__loadRecent" />
       <keyword name="Project.__makeFinished" id="Project.__makeFinished" ref="eric6.Project.Project.html#Project.__makeFinished" />
@@ -11251,8 +11252,10 @@
       <keyword name="Project.setStatusMonitorAutoUpdate" id="Project.setStatusMonitorAutoUpdate" ref="eric6.Project.Project.html#Project.setStatusMonitorAutoUpdate" />
       <keyword name="Project.setStatusMonitorInterval" id="Project.setStatusMonitorInterval" ref="eric6.Project.Project.html#Project.setStatusMonitorInterval" />
       <keyword name="Project.setTranslationPattern" id="Project.setTranslationPattern" ref="eric6.Project.Project.html#Project.setTranslationPattern" />
+      <keyword name="Project.startFileSystemMonitoring" id="Project.startFileSystemMonitoring" ref="eric6.Project.Project.html#Project.startFileSystemMonitoring" />
       <keyword name="Project.startStatusMonitor" id="Project.startStatusMonitor" ref="eric6.Project.Project.html#Project.startStatusMonitor" />
       <keyword name="Project.startswithProjectPath" id="Project.startswithProjectPath" ref="eric6.Project.Project.html#Project.startswithProjectPath" />
+      <keyword name="Project.stopFileSystemMonitoring" id="Project.stopFileSystemMonitoring" ref="eric6.Project.Project.html#Project.stopFileSystemMonitoring" />
       <keyword name="Project.stopStatusMonitor" id="Project.stopStatusMonitor" ref="eric6.Project.Project.html#Project.stopStatusMonitor" />
       <keyword name="Project.unregisterProjectType" id="Project.unregisterProjectType" ref="eric6.Project.Project.html#Project.unregisterProjectType" />
       <keyword name="Project.updateFileTypes" id="Project.updateFileTypes" ref="eric6.Project.Project.html#Project.updateFileTypes" />
@@ -11367,6 +11370,8 @@
       <keyword name="ProjectBrowserModel.removeItem" id="ProjectBrowserModel.removeItem" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.removeItem" />
       <keyword name="ProjectBrowserModel.renameItem" id="ProjectBrowserModel.renameItem" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.renameItem" />
       <keyword name="ProjectBrowserModel.repopulateItem" id="ProjectBrowserModel.repopulateItem" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.repopulateItem" />
+      <keyword name="ProjectBrowserModel.startFileSystemMonitoring" id="ProjectBrowserModel.startFileSystemMonitoring" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.startFileSystemMonitoring" />
+      <keyword name="ProjectBrowserModel.stopFileSystemMonitoring" id="ProjectBrowserModel.stopFileSystemMonitoring" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.stopFileSystemMonitoring" />
       <keyword name="ProjectBrowserModel.updateVCSStatus" id="ProjectBrowserModel.updateVCSStatus" ref="eric6.Project.ProjectBrowserModel.html#ProjectBrowserModel.updateVCSStatus" />
       <keyword name="ProjectBrowserPage" id="ProjectBrowserPage" ref="eric6.Preferences.ConfigurationPages.ProjectBrowserPage.html#ProjectBrowserPage" />
       <keyword name="ProjectBrowserPage (Constructor)" id="ProjectBrowserPage (Constructor)" ref="eric6.Preferences.ConfigurationPages.ProjectBrowserPage.html#ProjectBrowserPage.__init__" />
--- a/eric6/Documentation/Source/eric6.Project.Project.html	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Documentation/Source/eric6.Project.Project.html	Fri Apr 10 14:48:05 2020 +0200
@@ -321,6 +321,10 @@
 <td>Private method to initialize the list of supported project types.</td>
 </tr>
 <tr>
+<td><a href="#Project.__isInPdata">__isInPdata</a></td>
+<td>Private method used to check, if the passed in filename is project controlled..</td>
+</tr>
+<tr>
 <td><a href="#Project.__loadDiagram">__loadDiagram</a></td>
 <td>Private slot to load a diagram from file.</td>
 </tr>
@@ -1013,6 +1017,10 @@
 <td>Public method to set the translation pattern.</td>
 </tr>
 <tr>
+<td><a href="#Project.startFileSystemMonitoring">startFileSystemMonitoring</a></td>
+<td>Public method to (re)start monitoring the project file system.</td>
+</tr>
+<tr>
 <td><a href="#Project.startStatusMonitor">startStatusMonitor</a></td>
 <td>Public method to start the VCS status monitor thread.</td>
 </tr>
@@ -1021,6 +1029,10 @@
 <td>Public method to check, if a path starts with the project path.</td>
 </tr>
 <tr>
+<td><a href="#Project.stopFileSystemMonitoring">stopFileSystemMonitoring</a></td>
+<td>Public method to stop monitoring the project file system.</td>
+</tr>
+<tr>
 <td><a href="#Project.stopStatusMonitor">stopStatusMonitor</a></td>
 <td>Public method to stop the VCS status monitor thread.</td>
 </tr>
@@ -1324,6 +1336,33 @@
 <p>
         Private method to initialize the list of supported project types.
 </p>
+<a NAME="Project.__isInPdata" ID="Project.__isInPdata"></a>
+<h4>Project.__isInPdata</h4>
+<b>__isInPdata</b>(<i>fn</i>)
+
+<p>
+        Private method used to check, if the passed in filename is project
+        controlled..
+</p>
+<dl>
+
+<dt><i>fn</i> (str)</dt>
+<dd>
+filename to be checked
+</dd>
+</dl>
+<dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating membership
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
 <a NAME="Project.__loadDiagram" ID="Project.__loadDiagram"></a>
 <h4>Project.__loadDiagram</h4>
 <b>__loadDiagram</b>(<i></i>)
@@ -3878,6 +3917,13 @@
 translation pattern
 </dd>
 </dl>
+<a NAME="Project.startFileSystemMonitoring" ID="Project.startFileSystemMonitoring"></a>
+<h4>Project.startFileSystemMonitoring</h4>
+<b>startFileSystemMonitoring</b>(<i></i>)
+
+<p>
+        Public method to (re)start monitoring the project file system.
+</p>
 <a NAME="Project.startStatusMonitor" ID="Project.startStatusMonitor"></a>
 <h4>Project.startStatusMonitor</h4>
 <b>startStatusMonitor</b>(<i></i>)
@@ -3906,6 +3952,13 @@
             (boolean)
 </dd>
 </dl>
+<a NAME="Project.stopFileSystemMonitoring" ID="Project.stopFileSystemMonitoring"></a>
+<h4>Project.stopFileSystemMonitoring</h4>
+<b>stopFileSystemMonitoring</b>(<i></i>)
+
+<p>
+        Public method to stop monitoring the project file system.
+</p>
 <a NAME="Project.stopStatusMonitor" ID="Project.stopStatusMonitor"></a>
 <h4>Project.stopStatusMonitor</h4>
 <b>stopStatusMonitor</b>(<i></i>)
--- a/eric6/Documentation/Source/eric6.Project.ProjectBrowserModel.html	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Documentation/Source/eric6.Project.ProjectBrowserModel.html	Fri Apr 10 14:48:05 2020 +0200
@@ -480,6 +480,14 @@
 <td>Public method to repopulate an item.</td>
 </tr>
 <tr>
+<td><a href="#ProjectBrowserModel.startFileSystemMonitoring">startFileSystemMonitoring</a></td>
+<td>Public method to (re)start monitoring the project file system.</td>
+</tr>
+<tr>
+<td><a href="#ProjectBrowserModel.stopFileSystemMonitoring">stopFileSystemMonitoring</a></td>
+<td>Public method to stop monitoring the project file system.</td>
+</tr>
+<tr>
 <td><a href="#ProjectBrowserModel.updateVCSStatus">updateVCSStatus</a></td>
 <td>Public method used to update the vcs status of a node.</td>
 </tr>
@@ -884,6 +892,20 @@
 name of the file relative to the project root (string)
 </dd>
 </dl>
+<a NAME="ProjectBrowserModel.startFileSystemMonitoring" ID="ProjectBrowserModel.startFileSystemMonitoring"></a>
+<h4>ProjectBrowserModel.startFileSystemMonitoring</h4>
+<b>startFileSystemMonitoring</b>(<i></i>)
+
+<p>
+        Public method to (re)start monitoring the project file system.
+</p>
+<a NAME="ProjectBrowserModel.stopFileSystemMonitoring" ID="ProjectBrowserModel.stopFileSystemMonitoring"></a>
+<h4>ProjectBrowserModel.stopFileSystemMonitoring</h4>
+<b>stopFileSystemMonitoring</b>(<i></i>)
+
+<p>
+        Public method to stop monitoring the project file system.
+</p>
 <a NAME="ProjectBrowserModel.updateVCSStatus" ID="ProjectBrowserModel.updateVCSStatus"></a>
 <h4>ProjectBrowserModel.updateVCSStatus</h4>
 <b>updateVCSStatus</b>(<i>name, recursive=True</i>)
--- a/eric6/Plugins/VcsPlugins/vcsGit/ProjectBrowserHelper.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsGit/ProjectBrowserHelper.py	Fri Apr 10 14:48:05 2020 +0200
@@ -620,12 +620,14 @@
             fn = itm.dirName()
         isFile = os.path.isfile(fn)
         movefiles = self.browser.project.getFiles(fn)
+        self.browser.project.stopFileSystemMonitoring()
         if self.vcs.vcsMove(fn, self.project):
             if isFile:
                 self.browser.closeSourceWindow.emit(fn)
             else:
                 for mf in movefiles:
                     self.browser.closeSourceWindow.emit(mf)
+        self.browser.project.startFileSystemMonitoring()
     
     def __GitExtendedDiff(self):
         """
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py	Fri Apr 10 14:48:05 2020 +0200
@@ -716,12 +716,14 @@
             fn = itm.dirName()
         isFile = os.path.isfile(fn)
         movefiles = self.browser.project.getFiles(fn)
+        self.browser.project.stopFileSystemMonitoring()
         if self.vcs.vcsMove(fn, self.project):
             if isFile:
                 self.browser.closeSourceWindow.emit(fn)
             else:
                 for mf in movefiles:
                     self.browser.closeSourceWindow.emit(mf)
+        self.browser.project.startFileSystemMonitoring()
     
     def __HgExtendedDiff(self):
         """
--- a/eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py	Fri Apr 10 14:48:05 2020 +0200
@@ -760,13 +760,15 @@
             fn = itm.dirName()
         isFile = os.path.isfile(fn)
         movefiles = self.browser.project.getFiles(fn)
+        self.browser.project.stopFileSystemMonitoring()
         if self.vcs.vcsMove(fn, self.project):
             if isFile:
                 self.browser.closeSourceWindow.emit(fn)
             else:
                 for mf in movefiles:
                     self.browser.closeSourceWindow.emit(mf)
-        
+        self.browser.project.startFileSystemMonitoring()
+    
     def __SVNResolve(self):
         """
         Private slot called by the context menu to resolve conflicts of a file.
--- a/eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py	Fri Apr 10 14:48:05 2020 +0200
@@ -755,13 +755,15 @@
             fn = itm.dirName()
         isFile = os.path.isfile(fn)
         movefiles = self.browser.project.getFiles(fn)
+        self.browser.project.stopFileSystemMonitoring()
         if self.vcs.vcsMove(fn, self.project):
             if isFile:
                 self.browser.closeSourceWindow.emit(fn)
             else:
                 for mf in movefiles:
                     self.browser.closeSourceWindow.emit(mf)
-        
+        self.browser.project.startFileSystemMonitoring()
+    
     def __SVNResolve(self):
         """
         Private slot called by the context menu to resolve conflicts of a file.
--- a/eric6/Project/Project.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Project/Project.py	Fri Apr 10 14:48:05 2020 +0200
@@ -711,6 +711,18 @@
         @return reference to the project browser model (ProjectBrowserModel)
         """
         return self.__model
+    
+    def startFileSystemMonitoring(self):
+        """
+        Public method to (re)start monitoring the project file system.
+        """
+        self.__model.startFileSystemMonitoring()
+    
+    def stopFileSystemMonitoring(self):
+        """
+        Public method to stop monitoring the project file system.
+        """
+        self.__model.stopFileSystemMonitoring()
         
     def getVcs(self):
         """
@@ -2017,8 +2029,9 @@
         """
         fn = self.getRelativePath(oldname)
         if os.path.dirname(oldname) == os.path.dirname(newname):
-            self.removeFile(oldname, False)
-            self.appendFile(newname, isSourceFile, False)
+            if self.__isInPdata(oldname):
+                self.removeFile(oldname, False)
+                self.appendFile(newname, isSourceFile, False)
             self.__model.renameItem(fn, newname)
         else:
             self.removeFile(oldname)
@@ -2125,11 +2138,15 @@
             else:
                 if newdn not in self.subdirs:
                     self.subdirs.append(newdn)
-        self.setDirty(True)
-        typeString = typeStrings[0]
-        del typeStrings[0]
-        self.__model.removeItem(olddn)
-        self.__model.addNewItem(typeString, newdn, typeStrings)
+        if typeStrings:
+            # the directory is controlled by the project
+            self.setDirty(True)
+            self.__model.removeItem(olddn)
+            typeString = typeStrings[0]
+            del typeStrings[0]
+            self.__model.addNewItem(typeString, newdn, typeStrings)
+        else:
+            self.__model.renameItem(olddn, self.getAbsolutePath(newdn))
         self.directoryRemoved.emit(olddn)
         
     def removeFile(self, fn, updateModel=True):
@@ -3721,7 +3738,25 @@
         @rtype str
         """
         return self.pdata["DESCRIPTION"]
-        
+    
+    def __isInPdata(self, fn):
+        """
+        Private method used to check, if the passed in filename is project
+        controlled..
+        
+        @param fn filename to be checked
+        @type str
+        @return flag indicating membership
+        @rtype bool
+        """
+        newfn = os.path.abspath(fn)
+        newfn = self.getRelativePath(newfn)
+        for group in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
+                      "RESOURCES", "TRANSLATIONS", "OTHERS"]:
+            if newfn in self.pdata[group]:
+                return True
+        return False
+    
     def isProjectFile(self, fn):
         """
         Public method used to check, if the passed in filename belongs to the
--- a/eric6/Project/ProjectBrowserModel.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/Project/ProjectBrowserModel.py	Fri Apr 10 14:48:05 2020 +0200
@@ -244,6 +244,7 @@
         self.project = parent
         
         self.watchedItems = {}
+        self.__watcherActive = True
         self.watcher = QFileSystemWatcher(self)
         self.watcher.directoryChanged.connect(self.directoryChanged)
         
@@ -589,7 +590,7 @@
             return
         
         index = self.createIndex(itm.row(), 0, itm)
-        itm.setName(newFilename)
+        itm.setName(newFilename, full=False)
         self.dataChanged.emit(index, index)
         self.repopulateItem(newFilename)
     
@@ -668,12 +669,27 @@
         
         return index
     
+    def startFileSystemMonitoring(self):
+        """
+        Public method to (re)start monitoring the project file system.
+        """
+        self.__watcherActive = True
+    
+    def stopFileSystemMonitoring(self):
+        """
+        Public method to stop monitoring the project file system.
+        """
+        self.__watcherActive = False
+        
     def directoryChanged(self, path):
         """
         Public slot to handle the directoryChanged signal of the watcher.
         
         @param path path of the directory (string)
         """
+        if not self.__watcherActive:
+            return
+        
         if path not in self.watchedItems:
             # just ignore the situation we don't have a reference to the item
             return
--- a/eric6/UI/BrowserModel.py	Fri Apr 10 14:39:13 2020 +0200
+++ b/eric6/UI/BrowserModel.py	Fri Apr 10 14:48:05 2020 +0200
@@ -51,14 +51,15 @@
         super(BrowserModel, self).__init__(parent)
         
         self.progDir = None
-        self.watchedItems = {}
-        self.watcher = QFileSystemWatcher(self)
-        self.watcher.directoryChanged.connect(self.directoryChanged)
         
         self.__sysPathInterpreter = ""
         self.__sysPathItem = None
         
         if not nopopulate:
+            self.watchedItems = {}
+            self.watcher = QFileSystemWatcher(self)
+            self.watcher.directoryChanged.connect(self.directoryChanged)
+            
             rootData = QCoreApplication.translate("BrowserModel", "Name")
             self.rootItem = BrowserItem(None, rootData)
             

eric ide

mercurial