[gtk/suggestion-entry: 1/2] suggestionentry: Update action enabledness



commit e2eba253cb6ed91a7732e8372c306e585d23b7fa
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jul 10 14:47:21 2020 -0400

    suggestionentry: Update action enabledness
    
    Update the action enabledness when appropriate so
    that an explicit button does not appear insensitive
    when it shouldn't.

 gtk/gtksuggestionentry.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtksuggestionentry.c b/gtk/gtksuggestionentry.c
index 9c93d1ab14..35c5bc1e37 100644
--- a/gtk/gtksuggestionentry.c
+++ b/gtk/gtksuggestionentry.c
@@ -588,7 +588,7 @@ text_changed_idle (gpointer data)
   if (GTK_IS_STRING_FILTER (filter))
     gtk_string_filter_set_search (GTK_STRING_FILTER (filter), self->search);
 
-  matches = g_list_model_get_n_items (G_LIST_MODEL (self->selection));
+  matches = g_list_model_get_n_items (G_LIST_MODEL (self->filter_model));
 
   if (len < self->minimum_length)
     gtk_suggestion_entry_set_popup_visible (self, FALSE);
@@ -1027,12 +1027,25 @@ update_filter (GtkSuggestionEntry *self)
   else
     filter = NULL;
 
-  gtk_filter_list_model_set_filter (GTK_FILTER_LIST_MODEL (self->filter_model), filter);
+  gtk_filter_list_model_set_filter (self->filter_model, filter);
 
   g_clear_pointer (&expression, gtk_expression_unref);
   g_clear_object (&filter);
 }
 
+static void
+update_popup_action (GtkSuggestionEntry *self)
+{
+  guint n_items;
+
+  if (self->filter_model)
+    n_items = g_list_model_get_n_items (G_LIST_MODEL (self->filter_model));
+  else
+    n_items = 0;
+
+  gtk_widget_action_set_enabled (GTK_WIDGET (self), "popup.show", n_items > 0);
+}
+
 static void
 selection_changed (GtkSingleSelection *selection,
                    GParamSpec         *pspec,
@@ -1200,6 +1213,7 @@ items_changed (GListModel         *model,
                GtkSuggestionEntry *self)
 {
   update_prefix (self);
+  update_popup_action (self);
 }
 
 /**
@@ -1255,8 +1269,8 @@ gtk_suggestion_entry_set_model (GtkSuggestionEntry *self,
       g_signal_connect (self->selection, "items-changed",
                         G_CALLBACK (items_changed), self);
     }
-  else
-    gtk_widget_action_set_enabled (GTK_WIDGET (self), "popup.show", FALSE);
+
+  update_popup_action (self);
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
 }


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