[gnome-text-editor] languagedialog: control placeholder visibility



commit 89d59a337062ef6c4256d6a89e7434b2776dca07
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 7 13:07:05 2021 -0800

    languagedialog: control placeholder visibility
    
    Rather than rely on the child-visible fixes in GTK to make the styling
    work correctly, we can just control visibility directly.
    
    Fixes #245

 src/editor-language-dialog.c  | 14 ++++++++++----
 src/editor-language-dialog.ui |  3 ++-
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/src/editor-language-dialog.c b/src/editor-language-dialog.c
index 7b685b6..9bef406 100644
--- a/src/editor-language-dialog.c
+++ b/src/editor-language-dialog.c
@@ -32,6 +32,7 @@ struct _EditorLanguageDialog
 
   GtkListBox        *list_box;
   GtkEntry          *search_entry;
+  GtkWidget         *placeholder;
 
   EditorLanguageRow *selected;
 };
@@ -111,6 +112,7 @@ editor_language_dialog_filter (EditorLanguageDialog *self,
 {
   g_autoptr(GPatternSpec) spec = NULL;
   GtkWidget *child;
+  gboolean had_match = FALSE;
 
   g_assert (EDITOR_IS_LANGUAGE_DIALOG (self));
 
@@ -129,13 +131,16 @@ editor_language_dialog_filter (EditorLanguageDialog *self,
       if (EDITOR_IS_LANGUAGE_ROW (child))
         {
           EditorLanguageRow *row = EDITOR_LANGUAGE_ROW (child);
+          gboolean matches = _editor_language_row_match (row, spec);
 
-          if (_editor_language_row_match (row, spec))
-            gtk_widget_show (GTK_WIDGET (row));
-          else
-            gtk_widget_hide (GTK_WIDGET (row));
+          if (matches != gtk_widget_get_visible (GTK_WIDGET (row)))
+            gtk_widget_set_visible (GTK_WIDGET (row), matches);
+
+          had_match |= matches;
         }
     }
+
+  gtk_widget_set_visible (self->placeholder, !had_match);
 }
 
 static GtkListBoxRow *
@@ -281,6 +286,7 @@ editor_language_dialog_class_init (EditorLanguageDialogClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/TextEditor/ui/editor-language-dialog.ui");
   gtk_widget_class_bind_template_child (widget_class, EditorLanguageDialog, list_box);
+  gtk_widget_class_bind_template_child (widget_class, EditorLanguageDialog, placeholder);
   gtk_widget_class_bind_template_child (widget_class, EditorLanguageDialog, search_entry);
 
   gtk_widget_class_install_action (widget_class, "win.close", NULL, win_close_cb);
diff --git a/src/editor-language-dialog.ui b/src/editor-language-dialog.ui
index 02438a6..e0d84ef 100644
--- a/src/editor-language-dialog.ui
+++ b/src/editor-language-dialog.ui
@@ -43,12 +43,13 @@
                 <property name="child">
                   <object class="GtkListBox" id="list_box">
                     <child type="placeholder">
-                      <object class="GtkLabel">
+                      <object class="GtkLabel" id="placeholder">
                         <property name="label" translatable="yes">No Matches</property>
                         <property name="margin-top">18</property>
                         <property name="margin-bottom">18</property>
                         <property name="margin-end">18</property>
                         <property name="margin-start">18</property>
+                        <property name="visible">false</property>
                         <style>
                           <class name="dim-label"/>
                         </style>


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