[meld/ui-next] ui.findbar: Rework find bar appearance based on Builder's design



commit 00f4924c67d732dd2688fb32ba588bb23d1e5b67
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Mar 11 05:57:30 2019 +1000

    ui.findbar: Rework find bar appearance based on Builder's design
    
    This isn't that far from our existing design, while looking
    significantly better. This also adds in a button for switching between
    find + find/replace, which seems like a reasonable addition.

 meld/resources/ui/findbar.ui | 152 ++++++++++++++++++++++---------------------
 meld/ui/findbar.py           |  30 +++++----
 2 files changed, 98 insertions(+), 84 deletions(-)
---
diff --git a/meld/resources/ui/findbar.ui b/meld/resources/ui/findbar.ui
index 26646dde..1bc1a6ac 100644
--- a/meld/resources/ui/findbar.ui
+++ b/meld/resources/ui/findbar.ui
@@ -2,79 +2,29 @@
 <!-- Generated with glade 3.22.1 -->
 <interface>
   <requires lib="gtk+" version="3.20"/>
-  <object class="GtkArrow" id="arrow_left">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="arrow_type">left</property>
-  </object>
-  <object class="GtkArrow" id="arrow_right">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-  </object>
   <template class="FindBar" parent="GtkGrid">
     <property name="can_focus">False</property>
     <property name="column_spacing">6</property>
     <child>
-      <object class="GtkHButtonBox" id="hbuttonbox2">
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="layout_style">start</property>
-        <child>
-          <object class="GtkButton" id="replace_button">
-            <property name="label" translatable="yes">_Replace</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="focus_on_click">False</property>
-            <property name="receives_default">True</property>
-            <property name="relief">none</property>
-            <property name="use_underline">True</property>
-            <signal name="clicked" handler="on_replace_button_clicked" swapped="no"/>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="replace_all_button">
-            <property name="label" translatable="yes">Replace _All</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="focus_on_click">False</property>
-            <property name="receives_default">True</property>
-            <property name="relief">none</property>
-            <property name="use_underline">True</property>
-            <signal name="clicked" handler="on_replace_all_button_clicked" swapped="no"/>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkHButtonBox" id="hbuttonbox1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="layout_style">start</property>
+        <property name="valign">center</property>
+        <property name="homogeneous">True</property>
         <child>
           <object class="GtkButton" id="find_previous_button">
-            <property name="label" translatable="yes">_Previous</property>
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="focus_on_click">False</property>
-            <property name="receives_default">True</property>
-            <property name="image">arrow_left</property>
-            <property name="relief">none</property>
-            <property name="use_underline">True</property>
+            <property name="can_focus">False</property>
+            <property name="receives_default">False</property>
             <signal name="clicked" handler="on_find_previous_button_clicked" swapped="no"/>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-up-symbolic</property>
+                <property name="icon_size">1</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -84,22 +34,28 @@
         </child>
         <child>
           <object class="GtkButton" id="find_next_button">
-            <property name="label" translatable="yes">_Next</property>
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="focus_on_click">False</property>
-            <property name="receives_default">True</property>
-            <property name="image">arrow_right</property>
-            <property name="relief">none</property>
-            <property name="use_underline">True</property>
+            <property name="can_focus">False</property>
+            <property name="receives_default">False</property>
             <signal name="clicked" handler="on_find_next_button_clicked" swapped="no"/>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-down-symbolic</property>
+                <property name="icon_size">1</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="fill">False</property>
+            <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
+        <style>
+          <class name="linked"/>
+        </style>
       </object>
       <packing>
         <property name="left_attach">1</property>
@@ -192,7 +148,7 @@
         </child>
       </object>
       <packing>
-        <property name="left_attach">2</property>
+        <property name="left_attach">3</property>
         <property name="top_attach">0</property>
       </packing>
     </child>
@@ -228,7 +184,57 @@
         </child>
       </object>
       <packing>
-        <property name="left_attach">3</property>
+        <property name="left_attach">4</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="replace_all_button">
+        <property name="label" translatable="yes">Replace _All</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="focus_on_click">False</property>
+        <property name="receives_default">True</property>
+        <property name="use_underline">True</property>
+        <signal name="clicked" handler="on_replace_all_button_clicked" swapped="no"/>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="replace_button">
+        <property name="label" translatable="yes">_Replace</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="focus_on_click">False</property>
+        <property name="receives_default">True</property>
+        <property name="use_underline">True</property>
+        <signal name="clicked" handler="on_replace_button_clicked" swapped="no"/>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="tooltip_text" translatable="yes">Switch between Find and Find-and-Replace</property>
+        <signal name="clicked" handler="on_toggle_replace_button_clicked" swapped="no"/>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">edit-find-replace-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
         <property name="top_attach">0</property>
       </packing>
     </child>
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index 17893ec7..6fa36195 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import GtkSource
 
@@ -25,25 +26,24 @@ class FindBar(Gtk.Grid):
 
     __gtype_name__ = 'FindBar'
 
-    arrow_left = Template.Child()
-    arrow_right = Template.Child()
     find_entry = Template.Child()
     find_next_button = Template.Child()
     find_previous_button = Template.Child()
-    hbuttonbox2 = Template.Child()
     match_case = Template.Child()
     regex = Template.Child()
+    replace_all_button = Template.Child()
+    replace_button = Template.Child()
     replace_entry = Template.Child()
     whole_word = Template.Child()
     wrap_box = Template.Child()
 
+    replace_mode = GObject.Property(type=bool, default=False)
+
     def __init__(self, parent):
         super().__init__()
         self.init_template()
 
         self.set_text_view(None)
-        self.arrow_left.show()
-        self.arrow_right.show()
         parent.connect('set-focus-child', self.on_focus_child)
 
         settings = GtkSource.SearchSettings()
@@ -54,6 +54,13 @@ class FindBar(Gtk.Grid):
         settings.set_wrap_around(True)
         self.search_settings = settings
 
+        self.bind_property('replace_mode', self.replace_entry, 'visible')
+        self.bind_property('replace_mode', self.replace_all_button, 'visible')
+        self.bind_property('replace_mode', self.replace_button, 'visible')
+        self.bind_property(
+            'replace_mode', self, 'row-spacing', GObject.BindingFlags.DEFAULT,
+            lambda binding, replace_mode: 6 if replace_mode else 0)
+
     def on_focus_child(self, container, widget):
         if widget is not None:
             visible = self.props.visible
@@ -76,13 +83,11 @@ class FindBar(Gtk.Grid):
             self.search_context = None
 
     def start_find(self, textview, text=None):
+        self.replace_mode = False
         self.set_text_view(textview)
-        self.replace_entry.hide()
-        self.hbuttonbox2.hide()
         self.find_entry.get_style_context().remove_class("not-found")
         if text:
             self.find_entry.set_text(text)
-        self.set_row_spacing(0)
         self.show()
         self.find_entry.grab_focus()
 
@@ -101,14 +106,13 @@ class FindBar(Gtk.Grid):
             self.start_find(self.textview)
 
     def start_replace(self, textview, text=None):
+        self.replace_mode = True
         self.set_text_view(textview)
         self.find_entry.get_style_context().remove_class("not-found")
         if text:
             self.find_entry.set_text(text)
-        self.set_row_spacing(6)
-        self.show_all()
+        self.show()
         self.find_entry.grab_focus()
-        self.wrap_box.set_visible(False)
 
     @Template.Callback()
     def on_find_next_button_clicked(self, button):
@@ -142,6 +146,10 @@ class FindBar(Gtk.Grid):
             self.textview.scroll_to_mark(
                 buf.get_insert(), 0.25, True, 0.5, 0.5)
 
+    @Template.Callback()
+    def on_toggle_replace_button_clicked(self, button):
+        self.replace_mode = not self.replace_mode
+
     @Template.Callback()
     def on_find_entry_changed(self, entry):
         self.find_entry.get_style_context().remove_class("not-found")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]