keyboard: Improve Empty Search State.

The empty search state looks out-of place due to it being nested inside
a listbox. This is because we can only detect empty states through
gtk_list_filter_func().

Refine it by making the empty search placeholder a child of the main stack.
Introduce an additional helper function to detect when all the listbox
rows would be hidden by the filter.

As a part of https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1222
This commit is contained in:
Rachit Keerti Das 2021-02-06 20:24:37 +05:30 committed by Robert Ancell
parent 0e2d4f78a7
commit fccfb52cad
2 changed files with 68 additions and 52 deletions

View file

@ -79,6 +79,9 @@ struct _CcKeyboardShortcutDialog
};
G_DEFINE_TYPE (CcKeyboardShortcutDialog, cc_keyboard_shortcut_dialog, GTK_TYPE_DIALOG)
static gboolean
is_matched_shortcut_present (GtkListBox *listbox,
gpointer user_data);
static SectionRowData*
section_row_data_new (const gchar *section_id,
@ -320,12 +323,6 @@ show_shortcut_list (CcKeyboardShortcutDialog *self)
is_custom_shortcuts = (strcmp (section_data->section_id, "custom") == 0);
gtk_stack_set_transition_type (self->stack, GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT);
}
if (is_custom_shortcuts)
gtk_list_box_set_placeholder (self->shortcut_listbox, NULL);
else
gtk_list_box_set_placeholder (self->shortcut_listbox, self->empty_search_placeholder);
gtk_list_box_invalidate_filter (self->shortcut_listbox);
if (is_custom_shortcuts && (self->custom_shortcut_count == 0))
@ -458,7 +455,10 @@ reset_all_clicked_cb (CcKeyboardShortcutDialog *self)
static void
search_entry_cb (CcKeyboardShortcutDialog *self)
{
if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0 && self->section_row == NULL)
gboolean is_shortcut = is_matched_shortcut_present (self->shortcut_listbox, self);
if (!is_shortcut)
gtk_stack_set_visible_child (self->stack, self->empty_search_placeholder);
else if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0 && self->section_row == NULL)
show_section_list (self);
else if (gtk_stack_get_visible_child (self->stack) != GTK_WIDGET (self->shortcut_scrolled_window))
show_shortcut_list (self);
@ -664,6 +664,20 @@ shortcut_filter_function (GtkListBoxRow *row,
return retval;
}
static gboolean
is_matched_shortcut_present (GtkListBox* listbox,
gpointer user_data)
{
for (gint i = 0; ; i++)
{
GtkListBoxRow *current = gtk_list_box_get_row_at_index (listbox, i);
if (!current)
return FALSE;
if (shortcut_filter_function (current, user_data))
return TRUE;
}
}
static void
shortcut_header_function (GtkListBoxRow *row,
GtkListBoxRow *before,

View file

@ -28,7 +28,7 @@
<property name="hscrollbar_policy">never</property>
<property name="propagate_natural_width">True</property>
<property name="propagate_natural_height">True</property>
<property name="max_content_height">350</property>
<property name="max_content_height">450</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -58,7 +58,7 @@
<property name="hscrollbar_policy">never</property>
<property name="propagate_natural_width">True</property>
<property name="propagate_natural_height">True</property>
<property name="max_content_height">350</property>
<property name="max_content_height">450</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -137,6 +137,51 @@
</child>
</object>
</child>
<child>
<object class="GtkBox" id="empty_search_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">80</property>
<property name="icon_name">edit-find-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">No keyboard shortcut found</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.44"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Try a different search</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
@ -200,48 +245,5 @@
</object>
</child>
</template>
<object class="GtkBox" id="empty_search_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">80</property>
<property name="icon_name">edit-find-symbolic</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">No keyboard shortcut found</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.44"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Try a different search</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
<object class="GtkSizeGroup" id="accelerator_sizegroup" />
</interface>