[epiphany/mcatanzaro/web-extension-autoptr: 1/4] history-dialog: Improve search UI
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/web-extension-autoptr: 1/4] history-dialog: Improve search UI
- Date: Wed, 27 Feb 2019 20:19:20 +0000 (UTC)
commit beba55abb80531eaf3931818bc0c57fe8bb974b4
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Tue Feb 26 19:09:01 2019 +0100
history-dialog: Improve search UI
Add a search toggle button and allow "type-to-search".
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/632
src/ephy-history-dialog.c | 26 ++++++++++++++++++++++++++
src/resources/gtk/history-dialog.ui | 23 +++++++++++++++++++++--
2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index c3d4e8b2a..056f0ebdd 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -34,6 +34,7 @@
#include "ephy-time-helpers.h"
#include "ephy-window.h"
+#include <ctype.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <string.h>
@@ -51,6 +52,8 @@ struct _EphyHistoryDialog {
GtkWidget *listbox;
GtkWidget *forget_all_button;
GtkWidget *popover_menu;
+ GtkWidget *search_bar;
+ GtkWidget *search_button;
GActionGroup *action_group;
@@ -516,6 +519,26 @@ on_search_entry_changed (GtkSearchEntry *entry,
filter_now (self);
}
+static gboolean
+on_key_press_event (EphyHistoryDialog *self,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ GdkEventKey *key = (GdkEventKey *)event;
+ gint ret;
+
+ ret = gtk_search_bar_handle_event (GTK_SEARCH_BAR (self->search_bar), event);
+
+ if (ret != GDK_EVENT_STOP) {
+ if (key->keyval == GDK_KEY_Escape)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), FALSE);
+ else if (isprint (key->keyval))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), TRUE);
+ }
+
+ return ret;
+}
+
static void
update_selection_actions (GActionGroup *action_group,
gboolean has_selection)
@@ -741,11 +764,14 @@ ephy_history_dialog_class_init (EphyHistoryDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, listbox);
gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, forget_all_button);
gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, popover_menu);
+ gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_bar);
+ gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_button);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_selected);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_button_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_listbox_key_press_event);
+ gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
gtk_widget_class_bind_template_callback (widget_class, on_edge_reached);
}
diff --git a/src/resources/gtk/history-dialog.ui b/src/resources/gtk/history-dialog.ui
index 26f1cac25..9ff735c59 100644
--- a/src/resources/gtk/history-dialog.ui
+++ b/src/resources/gtk/history-dialog.ui
@@ -3,6 +3,11 @@
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">edit-find-symbolic</property>
+ </object>
<template class="EphyHistoryDialog" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="modal">True</property>
@@ -11,6 +16,7 @@
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
+ <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
@@ -31,6 +37,19 @@
</style>
</object>
</child>
+ <child>
+ <object class="GtkToggleButton" id="search_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">image1</property>
+ <property name="active" bind-source="search_bar" bind-property="search-mode-enabled"
bind-flags="sync-create|bidirectional"/>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
</child>
<child>
@@ -39,10 +58,10 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkSearchBar">
+ <object class="GtkSearchBar" id="search_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="search_mode_enabled">True</property>
+ <property name="search_mode_enabled">False</property>
<child>
<object class="GtkSearchEntry">
<property name="width_request">280</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]