Editor, Search & Replace widget: eric7

Fri, 19 May 2023 15:09:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 19 May 2023 15:09:24 +0200
branch
eric7
changeset 10040
b5ef1a93cd1a
parent 10039
3a47235d3469
child 10041
67c8efa6d098

Editor, Search & Replace widget:
- Changed the logic in replace mode such, that the find text is copied to the replace text entry, when it receives the focus and is empty. (see issue 502).

src/eric7/APIs/Python3/eric7.api file | annotate | diff | comparison | revisions
src/eric7/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
src/eric7/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
src/eric7/Documentation/Source/eric7.QScintilla.SearchReplaceWidget.html file | annotate | diff | comparison | revisions
src/eric7/QScintilla/SearchReplaceWidget.py file | annotate | diff | comparison | revisions
--- a/src/eric7/APIs/Python3/eric7.api	Fri May 19 14:25:31 2023 +0200
+++ b/src/eric7/APIs/Python3/eric7.api	Fri May 19 15:09:24 2023 +0200
@@ -9561,6 +9561,7 @@
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceSlidingWidget?1(vm, parent=None)
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.changeEvent?4(evt)
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.editorClosed?4(editor)
+eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.eventFilter?4(obj, evt)
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.findNext?4()
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.findPrev?4()
 eric7.QScintilla.SearchReplaceWidget.SearchReplaceWidget.keyPressEvent?4(event)
Binary file src/eric7/Documentation/Help/source.qch has changed
--- a/src/eric7/Documentation/Help/source.qhp	Fri May 19 14:25:31 2023 +0200
+++ b/src/eric7/Documentation/Help/source.qhp	Fri May 19 15:09:24 2023 +0200
@@ -14384,6 +14384,7 @@
       <keyword name="SearchReplaceWidget.__updateQuickSearchMarkers" id="SearchReplaceWidget.__updateQuickSearchMarkers" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.__updateQuickSearchMarkers" />
       <keyword name="SearchReplaceWidget.changeEvent" id="SearchReplaceWidget.changeEvent" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.changeEvent" />
       <keyword name="SearchReplaceWidget.editorClosed" id="SearchReplaceWidget.editorClosed" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.editorClosed" />
+      <keyword name="SearchReplaceWidget.eventFilter" id="SearchReplaceWidget.eventFilter" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.eventFilter" />
       <keyword name="SearchReplaceWidget.findNext" id="SearchReplaceWidget.findNext" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.findNext" />
       <keyword name="SearchReplaceWidget.findPrev" id="SearchReplaceWidget.findPrev" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.findPrev" />
       <keyword name="SearchReplaceWidget.keyPressEvent" id="SearchReplaceWidget.keyPressEvent" ref="eric7.QScintilla.SearchReplaceWidget.html#SearchReplaceWidget.keyPressEvent" />
--- a/src/eric7/Documentation/Source/eric7.QScintilla.SearchReplaceWidget.html	Fri May 19 14:25:31 2023 +0200
+++ b/src/eric7/Documentation/Source/eric7.QScintilla.SearchReplaceWidget.html	Fri May 19 15:09:24 2023 +0200
@@ -430,6 +430,10 @@
 <td>Public slot to handle the closing of an editor.</td>
 </tr>
 <tr>
+<td><a href="#SearchReplaceWidget.eventFilter">eventFilter</a></td>
+<td>Public method to handle events for other objects.</td>
+</tr>
+<tr>
 <td><a href="#SearchReplaceWidget.findNext">findNext</a></td>
 <td>Public slot to find the next occurrence of text.</td>
 </tr>
@@ -536,10 +540,9 @@
 </p>
 <dl>
 
-<dt><i>searchNext</i></dt>
+<dt><i>searchNext</i> (bool)</dt>
 <dd>
-flag indicating to search for the next occurrence
-        (boolean).
+flag indicating to search for the next occurrence.
 </dd>
 </dl>
 <a NAME="SearchReplaceWidget.__findByReturnPressed" ID="SearchReplaceWidget.__findByReturnPressed"></a>
@@ -811,6 +814,36 @@
 reference to the closed editor
 </dd>
 </dl>
+<a NAME="SearchReplaceWidget.eventFilter" ID="SearchReplaceWidget.eventFilter"></a>
+<h4>SearchReplaceWidget.eventFilter</h4>
+<b>eventFilter</b>(<i>obj, evt</i>)
+
+<p>
+        Public method to handle events for other objects.
+</p>
+<dl>
+
+<dt><i>obj</i> (QObject)</dt>
+<dd>
+reference to the object
+</dd>
+<dt><i>evt</i> (QEvent)</dt>
+<dd>
+reference to the event
+</dd>
+</dl>
+<dl>
+<dt>Return:</dt>
+<dd>
+flag indicating that the event should be filtered out
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
 <a NAME="SearchReplaceWidget.findNext" ID="SearchReplaceWidget.findNext"></a>
 <h4>SearchReplaceWidget.findNext</h4>
 <b>findNext</b>(<i></i>)
--- a/src/eric7/QScintilla/SearchReplaceWidget.py	Fri May 19 14:25:31 2023 +0200
+++ b/src/eric7/QScintilla/SearchReplaceWidget.py	Fri May 19 15:09:24 2023 +0200
@@ -138,12 +138,15 @@
         )
 
         self.__currentEditor = None
+        self.__replaceMode = False
 
         self.findtextCombo.lineEdit().textEdited.connect(self.__quickSearch)
         self.caseCheckBox.toggled.connect(self.__updateQuickSearchMarkers)
         self.wordCheckBox.toggled.connect(self.__updateQuickSearchMarkers)
         self.regexpCheckBox.toggled.connect(self.__updateQuickSearchMarkers)
 
+        self.replacetextCombo.installEventFilter(self)
+
         self.__findtextComboStyleSheet = self.findtextCombo.styleSheet()
 
         # define actions
@@ -236,6 +239,39 @@
         self.__selections = []
         self.__finding = False
 
+    def eventFilter(self, obj, evt):
+        """
+        Public method to handle events for other objects.
+
+        @param obj reference to the object
+        @type QObject
+        @param evt reference to the event
+        @type QEvent
+        @return flag indicating that the event should be filtered out
+        @rtype bool
+        """
+        if (
+            obj is self.replacetextCombo
+            and evt.type() == QEvent.Type.FocusIn
+            and self.__replaceMode
+        ):
+            if not bool(self.replacetextCombo.currentText()):
+                self.replacetextCombo.setCurrentText(self.findtextCombo.currentText())
+            self.replacetextCombo.lineEdit().selectAll()
+            return True
+
+        return super().eventFilter(obj, evt)
+
+    def changeEvent(self, evt):
+        """
+        Protected method handling state changes.
+
+        @param evt event containing the state change
+        @type QEvent
+        """
+        if evt.type() == QEvent.Type.FontChange:
+            self.adjustSize()
+
     def __setShortcuts(self):
         """
         Private method to set the local action's shortcuts to the same key
@@ -346,16 +382,6 @@
         self.replaceAllButton.setEnabled(enable)
         self.replaceAllAct.setEnabled(enable)
 
-    def changeEvent(self, evt):
-        """
-        Protected method handling state changes.
-
-        @param evt event containing the state change
-        @type QEvent
-        """
-        if evt.type() == QEvent.Type.FontChange:
-            self.adjustSize()
-
     def __selectionBoundary(self, selections=None):
         """
         Private method to calculate the current selection boundary.
@@ -1048,8 +1074,8 @@
         """
         Private method to replace one occurrence of text.
 
-        @param searchNext flag indicating to search for the next occurrence
-        (boolean).
+        @param searchNext flag indicating to search for the next occurrence.
+        @type bool
         """
         self.__finding = True
 
@@ -1310,6 +1336,8 @@
         @type bool (optional)
         """
         super().hide()
+
+        self.__replaceMode = replaceMode
         if replaceMode:
             self.__showReplace(text)
         else:

eric ide

mercurial