src/eric7/ViewManager/ViewManager.py

branch
server
changeset 10680
306373ccf8fd
parent 10632
1109854f15f9
parent 10679
4d3e0ce54322
child 10704
27d21e5163b8
--- a/src/eric7/ViewManager/ViewManager.py	Tue Mar 26 10:55:04 2024 +0100
+++ b/src/eric7/ViewManager/ViewManager.py	Wed Apr 10 17:03:56 2024 +0200
@@ -15,7 +15,6 @@
 from PyQt6.Qsci import QsciScintilla
 from PyQt6.QtCore import (
     QCoreApplication,
-    QFileSystemWatcher,
     QPoint,
     QSignalMapper,
     Qt,
@@ -26,6 +25,7 @@
 from PyQt6.QtWidgets import QApplication, QDialog, QMenu, QToolBar, QWidget
 
 from eric7 import Preferences
+from eric7.EricCore import EricFileSystemWatcher
 from eric7.EricGui import EricPixmapCache
 from eric7.EricGui.EricAction import EricAction, createActionGroup
 from eric7.EricWidgets import EricFileDialog, EricMessageBox
@@ -146,8 +146,10 @@
         self.__lastFocusWidget = None
 
         # initialize the file system watcher
-        self.__watcher = QFileSystemWatcher(self)
-        self.__watcher.fileChanged.connect(self.__watchedFileChanged)
+        watcher = EricFileSystemWatcher.instance()
+        watcher.fileModified.connect(self.__watchedFileChanged)
+
+        self.__watchedFilePaths = []
 
     def setReferences(self, ui, dbs, remoteServerInterface):
         """
@@ -680,6 +682,29 @@
         self.openRemoteAct.setEnabled(False)
         self.fileActions.append(self.openRemoteAct)
 
+        self.reloadAct = EricAction(
+            QCoreApplication.translate("ViewManager", "Reload"),
+            EricPixmapCache.getIcon("reload"),
+            QCoreApplication.translate("ViewManager", "Reload"),
+            0,
+            0,
+            self,
+            "vm_file_reload",
+        )
+        self.reloadAct.setStatusTip(
+            QCoreApplication.translate("ViewManager", "Reload the current file")
+        )
+        self.reloadAct.setWhatsThis(
+            QCoreApplication.translate(
+                "ViewManager",
+                """<b>Reload</b>"""
+                """<p>Reload the contents of current editor window. If the editor"""
+                """ contents was modified, a warning will be issued.</p>""",
+            )
+        )
+        self.reloadAct.triggered.connect(self.__reloadCurrentEditor)
+        self.fileActions.append(self.reloadAct)
+
         self.closeActGrp = createActionGroup(self)
 
         self.closeAct = EricAction(
@@ -954,6 +979,7 @@
         menu.addAction(self.newAct)
         menu.addAction(self.openAct)
         menu.addAction(self.openRemoteAct)
+        menu.addAction(self.reloadAct)
         self.menuRecentAct = menu.addMenu(self.recentMenu)
         menu.addMenu(self.bookmarkedMenu)
         menu.addSeparator()
@@ -998,6 +1024,7 @@
         tb.addAction(self.newAct)
         tb.addAction(self.openAct)
         tb.addAction(self.openRemoteAct)
+        tb.addAction(self.reloadAct)
         tb.addAction(self.closeAct)
         tb.addSeparator()
         tb.addAction(self.saveAct)
@@ -5507,6 +5534,15 @@
         # Open up the new files.
         self.openSourceFile(prog)
 
+    @pyqtSlot()
+    def __reloadCurrentEditor(self):
+        """
+        Private slot to reload the contents of the current editor.
+        """
+        aw = self.activeWindow()
+        if aw:
+            aw.reload()
+
     def checkDirty(self, editor, autosave=False, closeIt=False):
         """
         Public method to check the dirty status and open a message window.
@@ -5772,7 +5808,7 @@
         @param addNext flag indicating to add the file next to the current
             editor
         @type bool
-        @param indexes of the editor, first the split view index, second the
+        @param indexes indexes of the editor, first the split view index, second the
             index within the view
         @type tuple of two int
         @return reference to the opened editor
@@ -5817,6 +5853,20 @@
 
         return editor
 
+    @pyqtSlot(str, int, int)
+    def openSourceFileLinePos(self, fn, lineno, pos):
+        """
+        Public slot to display a file in an editor at a given line and position.
+
+        @param fn name of file to be opened
+        @type str
+        @param lineno line number to place the cursor at
+        @type int
+        @param pos position within line to position cursor at
+        @type int
+        """
+        self.openSourceFile(fn, lineno=lineno, pos=pos + 1)
+
     def __connectEditor(self, editor):
         """
         Private method to establish all editor connections.
@@ -5849,7 +5899,6 @@
         )
         editor.selectionChanged.connect(lambda: self.__editorSelectionChanged(editor))
         editor.lastEditPositionAvailable.connect(self.__lastEditPositionAvailable)
-        editor.zoomValueChanged.connect(lambda v: self.zoomValueChanged(v, editor))
         editor.mouseDoubleClick.connect(
             lambda pos, buttons: self.__editorDoubleClicked(editor, pos, buttons)
         )
@@ -6695,7 +6744,8 @@
             self.sbZoom.setEnabled(False)
         else:
             self.sbZoom.setEnabled(True)
-            self.sbZoom.setValue(now.getZoom())
+            if isinstance(now, Shell):
+                self.sbZoom.setValue(now.getZoom())
 
         if not isinstance(now, (Editor, Shell)):
             self.searchActGrp.setEnabled(False)
@@ -7127,11 +7177,14 @@
         @param zoomingWidget reference to the widget triggering the slot
         @type Editor or Shell
         """
-        aw = (
-            ericApp().getObject("Shell")
-            if QApplication.focusWidget() == ericApp().getObject("Shell")
-            else self.activeWindow()
-        )
+        if QApplication.focusWidget() == ericApp().getObject("Shell"):  # noqa: Y108
+            aw = ericApp().getObject("Shell")
+        else:
+            aw = (
+                self.activeWindow()
+                if self.activeWindow() == QApplication.focusWidget()
+                else QApplication.focusWidget()
+            )
         if aw and aw == zoomingWidget:
             self.sbZoom.setValue(value)
 
@@ -7705,6 +7758,7 @@
         """
         Private slot to handle the lastEditorClosed signal.
         """
+        self.reloadAct.setEnabled(False)
         self.closeActGrp.setEnabled(False)
         self.saveActGrp.setEnabled(False)
         self.exportersMenuAct.setEnabled(False)
@@ -7782,6 +7836,7 @@
         @type bool
         """
         if editor is not None:
+            self.reloadAct.setEnabled(bool(editor.getFileName()))
             self.saveAct.setEnabled(editor.isModified())
             self.revertAct.setEnabled(editor.isModified())
 
@@ -8152,8 +8207,14 @@
         @param filePath path of the file to be added
         @type str
         """
-        if filePath and FileSystemUtilities.isPlainFileName(filePath):
-            self.__watcher.addPath(filePath)
+        if (
+            filePath
+            and FileSystemUtilities.isPlainFileName(filePath)
+            and filePath not in self.__watchedFilePaths
+        ):
+            watcher = EricFileSystemWatcher.instance()
+            watcher.addPath(filePath)
+            self.__watchedFilePaths.append(filePath)
 
     def removeWatchedFilePath(self, filePath):
         """
@@ -8162,10 +8223,15 @@
         @param filePath path of the file to be removed
         @type str
         """
-        if self.getOpenEditorCount(
+        if (
             filePath
-        ) == 0 and FileSystemUtilities.isPlainFileName(filePath):
-            self.__watcher.removePath(filePath)
+            and self.getOpenEditorCount(filePath) == 0
+            and FileSystemUtilities.isPlainFileName(filePath)
+            and filePath in self.__watchedFilePaths
+        ):
+            watcher = EricFileSystemWatcher.instance()
+            watcher.removePath(filePath)
+            self.__watchedFilePaths.remove(filePath)
 
     ##################################################################
     ## Below are protected utility methods

eric ide

mercurial