Repository: spyder-ide/spyder
Pull request: PR: Add button to show and hide replace widget from find widget
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes


* [ ] Wrote at least one-line docstrings (for any new functions)
* [ ] Added unit test(s) covering the changes (if testable)
<!--- Remember that an image/animation is worth a thousand words! --->
* [ ] Included a screenshot or animation (if affecting the UI, see [Licecap](https://www.cockos.com/licecap/))


<!--- Explain what you've done and why --->

Added button to show and hide replace widget from find widget as discussed in https://github.com/spyder-ide/ux-improvements/issues/25

![replace](https://user-images.githubusercontent.com/18587879/105259609-215f2580-5b5a-11eb-8694-1a2e0166d701.gif)


### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes https://github.com/spyder-ide/ux-improvements/issues/25


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct:
Juanis2112

<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
Remove all secondary toolbars and relocate the actions that are needed
1. Remove the source toolbar completely 
- [x] Remove toolbar menu item in the toolbars menu
- [ ] Embed content of warnings in code analysis and have some options to decide which linter to use. (Pylint (Non Real time) VS Real time)  -> Spyder 6
- [ ] Deactivate run analysis button when real time analysis is selected -> Spyder 6
- [x] Move the TODO list button to Editor toolbar (Probably just leave this in the source menu)

2. Remove the search toolbar completely
- [x] Remove toolbar menu item in the toolbars menu
- [x] Add icon to the find widget in editor, to open the “replace widget”.

3. Remove Edit toolbar
- [x] Remove toolbar menu item in the toolbars menu

Hints from issue discussion:

Commit message: Add button to show and hide replace widget from find widget

Patch to review:
diff --git a/spyder/widgets/findreplace.py b/spyder/widgets/findreplace.py
index fed446cabd8..1b3f24304b5 100644
--- a/spyder/widgets/findreplace.py
+++ b/spyder/widgets/findreplace.py
@@ -89,6 +89,12 @@ def __init__(self, parent, enable_replace=False):
                                                      self.text_has_been_edited)
 
         self.number_matches_text = QLabel(self)
+        self.replace_on = False
+        self.replace_text_button = create_toolbutton(
+                                       self,
+                                       toggled=self.change_replace_state,
+                                       icon=ima.icon('replace'),
+                                       tip=_("Replace text"))
         self.previous_button = create_toolbutton(self,
                                                  triggered=self.find_previous,
                                                  icon=ima.icon('ArrowUp'),
@@ -126,8 +132,9 @@ def __init__(self, parent, enable_replace=False):
 
         hlayout = QHBoxLayout()
         self.widgets = [self.close_button, self.search_text,
-                        self.number_matches_text, self.previous_button,
-                        self.next_button, self.re_button, self.case_button,
+                        self.number_matches_text, self.replace_text_button,
+                        self.previous_button, self.next_button,
+                        self.re_button, self.case_button,
                         self.words_button, self.highlight_button]
         for widget in self.widgets[1:]:
             hlayout.addWidget(widget)
@@ -302,6 +309,19 @@ def show(self, hide_replace=True):
             self.search_text.setFocus()
 
     @Slot()
+    def replace_widget(self, replace_on):
+        """Show and hide replace widget"""
+        if replace_on:
+            self.show_replace()
+        else:
+            self.hide_replace()
+
+    def change_replace_state(self):
+        """Handle the change of the replace state widget."""
+        self.replace_on = not self.replace_on
+        self.replace_text_button.setChecked(self.replace_on)
+        self.replace_widget(self.replace_on)
+
     def hide(self):
         """Overrides Qt Method"""
         for widget in self.replace_widgets:


Code review comments:
diff_hunk: @@ -89,6 +89,12 @@ def __init__(self, parent, enable_replace=False):
                                                      self.text_has_been_edited)
 
         self.number_matches_text = QLabel(self)
+        self.replace_on = False
+        self.replace_text_button = create_toolbutton(
+                                       self,
+                                       toggled=self.change_replace_state,
+                                       icon=ima.icon('replace'),
+                                       tip=_("Replace text"))
path: spyder/widgets/findreplace.py
text: @user1:
```suggestion
        self.replace_text_button = create_toolbutton(
            self,
            toggled=self.change_replace_state,
            icon=ima.icon('replace'),
            tip=_("Replace text")
        )
```