--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/hg.py Wed Apr 10 10:45:31 2024 +0200 +++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/hg.py Wed Apr 10 16:45:06 2024 +0200 @@ -12,10 +12,11 @@ import pathlib import shutil -from PyQt6.QtCore import QCoreApplication, QFileSystemWatcher, pyqtSignal +from PyQt6.QtCore import QCoreApplication, pyqtSignal from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog from eric7 import Preferences, Utilities +from eric7.EricCore import EricFileSystemWatcher from eric7.EricWidgets import EricFileDialog, EricMessageBox from eric7.EricWidgets.EricApplication import ericApp from eric7.QScintilla.MiniEditor import MiniEditor @@ -132,11 +133,14 @@ self.__activeExtensions = [] - self.__iniWatcher = QFileSystemWatcher(self) - self.__iniWatcher.fileChanged.connect(self.__iniFileChanged) - cfgFile = getConfigPath() - if os.path.exists(cfgFile): - self.__iniWatcher.addPath(cfgFile) + self.__iniFileChangedFlag = False + + watcher = EricFileSystemWatcher.instance() + watcher.fileDeleted.connect(self.__iniFileChanged) + watcher.fileModified.connect(self.__iniFileChanged) + self.__cfgFile = getConfigPath() + if os.path.exists(self.__cfgFile): + watcher.addPath(self.__cfgFile) self.__client = None self.__createClient() @@ -225,6 +229,13 @@ # shut down the client self.__client and self.__client.stopServer() + watcher = EricFileSystemWatcher.instance() + watcher.fileDeleted.disconnect(self.__iniFileChanged) + watcher.fileModified.disconnect(self.__iniFileChanged) + watcher.removePath(self.__cfgFile) + if self.__repoIniFile: + watcher.removePath(self.__repoIniFile) + def initCommand(self, command): """ Public method to initialize a command arguments list. @@ -3032,24 +3043,31 @@ @param path name of the changed file @type str """ - if self.__client: - ok, err = self.__client.restartServer() - if not ok: - EricMessageBox.warning( - None, - self.tr("Mercurial Command Server"), - self.tr( - """<p>The Mercurial Command Server could not be""" - """ restarted.</p><p>Reason: {0}</p>""" - ).format(err), - ) - - self.__getExtensionsInfo() - - if self.__repoIniFile and path == self.__repoIniFile: - self.__checkDefaults() - - self.iniFileChanged.emit() + if ( + path in (self.__cfgFile, self.__repoIniFile) + and not self.__iniFileChangedFlag + ): + self.__iniFileChangedFlag = True + if self.__client: + ok, err = self.__client.restartServer() + if not ok: + EricMessageBox.warning( + None, + self.tr("Mercurial Command Server"), + self.tr( + """<p>The Mercurial Command Server could not be""" + """ restarted.</p><p>Reason: {0}</p>""" + ).format(err), + ) + + self.__getExtensionsInfo() + + if self.__repoIniFile and path == self.__repoIniFile: + self.__checkDefaults() + + self.iniFileChanged.emit() + + self.__iniFileChangedFlag = False def __monitorRepoIniFile(self, repodir): """ @@ -3061,7 +3079,8 @@ """ cfgFile = os.path.join(repodir, self.adminDir, "hgrc") if os.path.exists(cfgFile): - self.__iniWatcher.addPath(cfgFile) + watcher = EricFileSystemWatcher.instance() + watcher.addPath(cfgFile) self.__repoIniFile = cfgFile self.__checkDefaults()