src/eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 10694
f46c1e224e8a
parent 10659
43ead32943ca
parent 10692
9becf9ca115c
child 10733
d96c69a235fc
diff -r e6c9ab1dc168 -r f46c1e224e8a src/eric7/QScintilla/Editor.py
--- a/src/eric7/QScintilla/Editor.py	Tue Apr 02 10:13:41 2024 +0200
+++ b/src/eric7/QScintilla/Editor.py	Wed Apr 24 10:14:16 2024 +0200
@@ -1042,6 +1042,9 @@
         self.menu.addSeparator()
         self.reopenEncodingMenu = self.__initContextMenuReopenWithEncoding()
         self.menuActs["Reopen"] = self.menu.addMenu(self.reopenEncodingMenu)
+        self.menuActs["Reload"] = self.menu.addAction(
+            EricPixmapCache.getIcon("reload"), self.tr("Reload"), self.reload
+        )
         self.menuActs["Save"] = self.menu.addAction(
             EricPixmapCache.getIcon("fileSave"), self.tr("Save"), self.__contextSave
         )
@@ -1641,7 +1644,7 @@
                 self.setLanguage(self.supportedLanguages[language][1])
                 self.checkSyntax()
 
-        self.__docstringGenerator = None
+        self.resetDocstringGenerator()
 
     def __languageChanged(self, language, propagate=True):
         """
@@ -1664,7 +1667,7 @@
             self.setLanguage(self.supportedLanguages[language][1], propagate=propagate)
             self.checkSyntax()
 
-        self.__docstringGenerator = None
+        self.resetDocstringGenerator()
 
     def __resetLanguage(self, propagate=True):
         """
@@ -1693,7 +1696,7 @@
         with contextlib.suppress(AttributeError):
             self.menuActs["MonospacedFont"].setChecked(self.useMonospaced)
 
-        self.__docstringGenerator = None
+        self.resetDocstringGenerator()
 
         if not self.inLanguageChanged and propagate:
             self.inLanguageChanged = True
@@ -2414,7 +2417,7 @@
             lineno = self.markerLine(self.lastHighlight)
             self.ensureVisible(lineno + 1)
 
-    def highlight(self, line=None, error=False, syntaxError=False):  # noqa: U100
+    def highlight(self, line=None, error=False):
         """
         Public method to highlight [or de-highlight] a particular line.
 
@@ -2423,8 +2426,6 @@
         @param error flag indicating whether the error highlight should be
             used
         @type bool
-        @param syntaxError flag indicating a syntax error
-        @type bool
         """
         if line is None:
             self.lastHighlight = None
@@ -2465,39 +2466,39 @@
 
     def __modified(
         self,
-        pos,  # noqa: U100
+        _pos,
         mtype,
-        text,  # noqa: U100
-        length,  # noqa: U100
+        _text,
+        _length,
         linesAdded,
         line,
-        foldNow,  # noqa: U100
-        foldPrev,  # noqa: U100
-        token,  # noqa: U100
-        annotationLinesAdded,  # noqa: U100
+        _foldNow,
+        _foldPrev,
+        _token,
+        _annotationLinesAdded,
     ):
         """
         Private method to handle changes of the number of lines.
 
-        @param pos start position of change
+        @param _pos start position of change (unused)
         @type int
         @param mtype flags identifying the change
         @type int
-        @param text text that is given to the Undo system
+        @param _text text that is given to the Undo system (unused)
         @type str
-        @param length length of the change
+        @param _length length of the change (unused)
         @type int
         @param linesAdded number of added/deleted lines
         @type int
         @param line line number of a fold level or marker change
         @type int
-        @param foldNow new fold level
+        @param _foldNow new fold level (unused)
         @type int
-        @param foldPrev previous fold level
+        @param _foldPrev previous fold level (unused)
         @type int
-        @param token ???
+        @param _token ??? (unused)
         @type int
-        @param annotationLinesAdded number of added/deleted annotation lines
+        @param _annotationLinesAdded number of added/deleted annotation lines (unused)
         @type int
         """
         if mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT):
@@ -3059,7 +3060,7 @@
                 printer.setDocName(self.noName)
             if printDialog.printRange() == QAbstractPrintDialog.PrintRange.Selection:
                 # get the selection
-                fromLine, fromIndex, toLine, toIndex = self.getSelection()
+                fromLine, _fromIndex, toLine, toIndex = self.getSelection()
                 if toIndex == 0:
                     toLine -= 1
                 # QScintilla seems to print one line more than told
@@ -3961,7 +3962,7 @@
                 QsciScintilla.SC_FOLDACTION_EXPAND,
             )
 
-    def __marginClicked(self, margin, line, modifiers):  # noqa: U100
+    def __marginClicked(self, margin, line, _modifiers):
         """
         Private slot to handle the marginClicked signal.
 
@@ -3969,7 +3970,7 @@
         @type int
         @param line line number of the click
         @type int
-        @param modifiers keyboard modifiers
+        @param _modifiers keyboard modifiers (unused)
         @type Qt.KeyboardModifiers
         """
         if margin == self.__bmMargin:
@@ -6331,6 +6332,7 @@
         self.menuActs["Reopen"].setEnabled(
             not self.isModified() and bool(self.fileName)
         )
+        self.menuActs["Reload"].setEnabled(bool(self.fileName))
         self.menuActs["Save"].setEnabled(self.isModified())
         self.menuActs["Undo"].setEnabled(self.isUndoAvailable())
         self.menuActs["Redo"].setEnabled(self.isRedoAvailable())
@@ -6824,7 +6826,7 @@
 
         error = problems.get("error")
         if error:
-            _fn, lineno, col, code, msg = error
+            _fn, lineno, col, _code, msg = error
             self.toggleSyntaxError(lineno, col, True, msg)
 
         for _fn, lineno, col, _code, msg in problems.get("py_warnings", []):
@@ -7292,7 +7294,7 @@
     def toggleWarning(
         self,
         line,
-        col,  # noqa: U100
+        _col,
         setWarning,
         msg="",
         warningType=EditorWarningKind.Code,
@@ -7304,7 +7306,7 @@
 
         @param line line number of the warning
         @type int
-        @param col column of the warning
+        @param _col column of the warning (unused)
         @type int
         @param setWarning flag indicating if the warning marker should be
             set or deleted
@@ -8262,6 +8264,15 @@
                     # do not prompt for this change again...
                     self.lastModified = pathlib.Path(self.fileName).stat().st_mtime
 
+    def getModificationTime(self):
+        """
+        Public method to get the time of the latest (saved) modification.
+
+        @return time of the latest modification
+        @rtype int
+        """
+        return self.lastModified
+
     @pyqtSlot()
     def recordModificationTime(self):
         """
@@ -8327,6 +8338,28 @@
 
         self.refreshed.emit()
 
+    @pyqtSlot()
+    def reload(self):
+        """
+        Public slot to reload the editor contents checking its modification state first.
+        """
+        ok = (
+            EricMessageBox.yesNo(
+                self,
+                self.tr("Reload File"),
+                self.tr(
+                    "<p>The editor contains unsaved modifications.</p>"
+                    "<p><b>Warning:</b> You will lose your changes upon reloading"
+                    " it.</p><p>Shall the editor really be reloaded?</p>"
+                ),
+                icon=EricMessageBox.Warning,
+            )
+            if self.isModified()
+            else True
+        )
+        if ok:
+            self.refresh()
+
     def setMonospaced(self, on):
         """
         Public method to set/reset a monospaced font.
@@ -9820,6 +9853,12 @@
     ## Methods implementing the docstring generator interface
     #######################################################################
 
+    def resetDocstringGenerator(self):
+        """
+        Public method to reset the current docstring generator.
+        """
+        self.__docstringGenerator = None
+
     def getDocstringGenerator(self):
         """
         Public method to get a reference to the docstring generator.

eric ide

mercurial