aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXan Lopez <xan@src.gnome.org>2003-07-13 00:26:19 +0800
committerXan Lopez <xan@src.gnome.org>2003-07-13 00:26:19 +0800
commitc16f33a0183bf8da7c13eea9f85472d1ef807be0 (patch)
treeaa9425b2280c3d4780e24671bcb04f72e7396d02
parent61f1dcadb9567d95440a6b0f4ea0863401c2934e (diff)
downloadgsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar.gz
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar.bz2
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar.lz
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar.xz
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.tar.zst
gsoc2013-epiphany-c16f33a0183bf8da7c13eea9f85472d1ef807be0.zip
A "fast search" implementation for all node views. Pressing any valid
A "fast search" implementation for all node views. Pressing any valid unicode character will make ephy select the first entry begining with that key, or the nearest match (with previous or posterior letters). Fixes bug #116744 (http://bugzilla.gnome.org/show_bug.cgi?id=116744).
-rw-r--r--ChangeLog17
-rw-r--r--lib/widgets/ephy-node-view.c69
-rw-r--r--lib/widgets/ephy-node-view.h3
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c15
-rw-r--r--src/ephy-history-window.c6
5 files changed, 95 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d1295d0f..fd343568b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2003-07-12 Xan Lopez <xan@masilla.org>
+
+ * lib/widgets/ephy-node-view.c:
+ (ephy_node_view_select_node_by_key), (ephy_node_view_key_press_cb),
+ (ephy_node_view_construct), (ephy_node_view_add_column),
+ (ephy_node_view_init):
+ * lib/widgets/ephy-node-view.h:
+ * src/bookmarks/ephy-bookmarks-editor.c: (key_pressed_cb),
+ (ephy_bookmarks_editor_construct):
+ * src/ephy-history-window.c: (ephy_history_window_construct):
+
+ A "fast search" implementation for all node views. Pressing any valid
+ unicode character will make ephy select the first entry begining with
+ that key, or the nearest match (with previous or posterior letters).
+ Fixes bug #116744 (http://bugzilla.gnome.org/show_bug.cgi?id=116744).
+
+
2003-07-12 Marco Pesenti Gritti <marco@it.gnome.org>
* configure.in:
diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c
index 3ec8867db..a69907916 100644
--- a/lib/widgets/ephy-node-view.c
+++ b/lib/widgets/ephy-node-view.c
@@ -15,6 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
+ * $Id$
*/
#include <gtk/gtktreeselection.h>
@@ -66,6 +67,8 @@ struct EphyNodeViewPrivate
gboolean editing;
int editable_property;
+
+ int searchable_data_column;
};
enum
@@ -414,6 +417,54 @@ ephy_node_view_row_activated_cb (GtkTreeView *treeview,
g_signal_emit (G_OBJECT (view), ephy_node_view_signals[NODE_ACTIVATED], 0, node);
}
+
+static gboolean
+ephy_node_view_select_node_by_key (EphyNodeView *view, GdkEventKey *event)
+{
+ GtkTreeIter iter, last_iter;
+ GtkTreePath *path;
+ GValue value = {0, };
+ gchar *string;
+ gchar *event_string;
+ gboolean found = FALSE;
+
+ event_string = g_utf8_casefold (event->string, -1);
+
+ if (!gtk_tree_model_get_iter_first (view->priv->sortmodel, &iter))
+ {
+ g_free (event_string);
+ return FALSE;
+ }
+
+ do
+ {
+ last_iter = iter;
+ gtk_tree_model_get_value (view->priv->sortmodel, &iter,
+ view->priv->searchable_data_column,
+ &value);
+
+ string = g_utf8_casefold (g_value_get_string (&value), -1);
+ g_utf8_strncpy (string, string, 1);
+ found = (g_utf8_collate (string, event_string) >= 0);
+
+ g_free (string);
+ g_value_unset (&value);
+ }
+ while (!found && gtk_tree_model_iter_next (view->priv->sortmodel, &iter));
+
+ if (!found)
+ {
+ iter = last_iter;
+ }
+
+ path = gtk_tree_model_get_path (view->priv->sortmodel, &iter);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
+ gtk_tree_path_free (path);
+ g_free (event_string);
+
+ return TRUE;
+}
+
static gboolean
ephy_node_view_key_press_cb (GtkTreeView *treeview,
GdkEventKey *event,
@@ -426,6 +477,11 @@ ephy_node_view_key_press_cb (GtkTreeView *treeview,
return TRUE;
}
+ else if (view->priv->searchable_data_column != -1 &&
+ gdk_keyval_to_unicode (event->keyval))
+ {
+ return ephy_node_view_select_node_by_key (view, event);
+ }
return FALSE;
}
@@ -563,11 +619,10 @@ ephy_node_view_construct (EphyNodeView *view)
G_CALLBACK (ephy_node_view_button_press_cb),
view,
0);
- g_signal_connect_object (G_OBJECT (view),
+ g_signal_connect_after (G_OBJECT (view),
"key_press_event",
G_CALLBACK (ephy_node_view_key_press_cb),
- view,
- 0);
+ view);
g_signal_connect_object (G_OBJECT (view),
"row_activated",
G_CALLBACK (ephy_node_view_row_activated_cb),
@@ -778,6 +833,12 @@ ephy_node_view_add_column (EphyNodeView *view,
g_signal_connect (renderer, "edited", G_CALLBACK (cell_renderer_edited), view);
}
+ if ((flags & EPHY_NODE_VIEW_SEARCHABLE) &&
+ (view->priv->searchable_data_column == -1))
+ {
+ view->priv->searchable_data_column = column;
+ }
+
gtk_tree_view_column_pack_start (gcolumn, renderer, TRUE);
gtk_tree_view_column_set_attributes (gcolumn, renderer,
"text", column,
@@ -847,6 +908,7 @@ ephy_node_view_init (EphyNodeView *view)
view->priv->editable_renderer = NULL;
view->priv->editing = TRUE;
view->priv->selected_node = NULL;
+ view->priv->searchable_data_column = -1;
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE);
}
@@ -1070,3 +1132,4 @@ ephy_node_view_has_selection (EphyNodeView *view, gboolean *multiple)
return rows > 0;
}
+
diff --git a/lib/widgets/ephy-node-view.h b/lib/widgets/ephy-node-view.h
index 100f8fc25..1ccc6cda4 100644
--- a/lib/widgets/ephy-node-view.h
+++ b/lib/widgets/ephy-node-view.h
@@ -56,7 +56,8 @@ typedef enum
{
EPHY_NODE_VIEW_AUTO_SORT = 1,
EPHY_NODE_VIEW_USER_SORT = 2,
- EPHY_NODE_VIEW_EDITABLE = 4
+ EPHY_NODE_VIEW_EDITABLE = 4,
+ EPHY_NODE_VIEW_SEARCHABLE = 8
} EphyNodeViewFlags;
typedef struct
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 789239ad7..d7a8b0939 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -1011,16 +1011,11 @@ key_pressed_cb (EphyNodeView *view,
GdkEventKey *event,
EphyBookmarksEditor *editor)
{
- switch (event->keyval)
+ if (event->keyval == GDK_Delete || event->keyval == GDK_KP_Delete)
{
- case GDK_Delete:
- case GDK_KP_Delete:
cmd_delete (NULL, editor);
return TRUE;
-
- default:
- break;
- }
+ }
return FALSE;
}
@@ -1280,7 +1275,8 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
EPHY_NODE_KEYWORD_PROP_NAME,
EPHY_NODE_KEYWORD_PROP_PRIORITY,
EPHY_NODE_VIEW_AUTO_SORT |
- EPHY_NODE_VIEW_EDITABLE, NULL);
+ EPHY_NODE_VIEW_EDITABLE |
+ EPHY_NODE_VIEW_SEARCHABLE, NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), key_view);
gtk_widget_set_size_request (key_view, 130, -1);
gtk_widget_show (key_view);
@@ -1334,7 +1330,8 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
ephy_node_view_add_column (EPHY_NODE_VIEW (bm_view), _("Title"),
G_TYPE_STRING, EPHY_NODE_BMK_PROP_TITLE, -1,
EPHY_NODE_VIEW_AUTO_SORT |
- EPHY_NODE_VIEW_EDITABLE,
+ EPHY_NODE_VIEW_EDITABLE |
+ EPHY_NODE_VIEW_SEARCHABLE,
provide_favicon);
gtk_container_add (GTK_CONTAINER (scrolled_window), bm_view);
gtk_widget_show (bm_view);
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index 060cde755..8636557c9 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -1025,7 +1025,8 @@ ephy_history_window_construct (EphyHistoryWindow *editor)
G_TYPE_STRING,
EPHY_NODE_PAGE_PROP_TITLE,
EPHY_NODE_PAGE_PROP_PRIORITY,
- EPHY_NODE_VIEW_AUTO_SORT,
+ EPHY_NODE_VIEW_AUTO_SORT |
+ EPHY_NODE_VIEW_SEARCHABLE,
provide_favicon);
gtk_container_add (GTK_CONTAINER (scrolled_window), sites_view);
gtk_widget_show (sites_view);
@@ -1069,7 +1070,8 @@ ephy_history_window_construct (EphyHistoryWindow *editor)
EPHY_NODE_PAGE_PROP_LOCATION);
col = ephy_node_view_add_column (EPHY_NODE_VIEW (pages_view), _("Title"),
G_TYPE_STRING, EPHY_NODE_PAGE_PROP_TITLE,
- -1, EPHY_NODE_VIEW_USER_SORT, NULL);
+ -1, EPHY_NODE_VIEW_USER_SORT |
+ EPHY_NODE_VIEW_SEARCHABLE, NULL);
gtk_tree_view_column_set_max_width (col, 250);
col = ephy_node_view_add_column (EPHY_NODE_VIEW (pages_view), _("Address"),
G_TYPE_STRING, EPHY_NODE_PAGE_PROP_LOCATION,