[gnome-builder] grep: set initial sensitivity of replace button



commit c831f5e13e44a10405720ade6a92967fa4950e28
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 30 14:32:45 2018 -0700

    grep: set initial sensitivity of replace button
    
    We want the button insensitive until there are results to display.

 src/plugins/grep/gbp-grep-panel.c  | 11 +++++++++++
 src/plugins/grep/gbp-grep-panel.ui |  1 +
 2 files changed, 12 insertions(+)
---
diff --git a/src/plugins/grep/gbp-grep-panel.c b/src/plugins/grep/gbp-grep-panel.c
index 2f41ed33e..f48bd634f 100644
--- a/src/plugins/grep/gbp-grep-panel.c
+++ b/src/plugins/grep/gbp-grep-panel.c
@@ -511,6 +511,17 @@ gbp_grep_panel_set_model (GbpGrepPanel *self,
   g_return_if_fail (GBP_IS_GREP_PANEL (self));
   g_return_if_fail (!model || GBP_IS_GREP_MODEL (model));
 
+  if (model != NULL)
+    {
+      /* Disable replace button if we have nothing to replace. We only
+       * support setting the model after it has scanned, so this is fine.
+       */
+      if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 0)
+        gtk_widget_set_sensitive (GTK_WIDGET (self->replace_button), FALSE);
+      else
+        gtk_widget_set_sensitive (GTK_WIDGET (self->replace_button), TRUE);
+    }
+
   gtk_tree_view_set_model (self->tree_view, GTK_TREE_MODEL (model));
 }
 
diff --git a/src/plugins/grep/gbp-grep-panel.ui b/src/plugins/grep/gbp-grep-panel.ui
index c8f92de59..075256925 100644
--- a/src/plugins/grep/gbp-grep-panel.ui
+++ b/src/plugins/grep/gbp-grep-panel.ui
@@ -65,6 +65,7 @@
                 <child>
                   <object class="GtkButton" id="replace_button">
                     <property name="label" translatable="yes">Replace</property>
+                    <property name="sensitive">false</property>
                     <property name="visible">true</property>
                     <style>
                       <class name="destructive-action"/>


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