Verified Commit 6f258d99 authored by Chigozirim Chukwu's avatar Chigozirim Chukwu
Browse files

create signals for search status

parent 5d366cfa
Pipeline #8787 passed with stages
in 3 minutes and 8 seconds
......@@ -127,6 +127,9 @@ enum
MOVE_CURSOR,
ACTIVATE_CURSOR_ITEM,
START_INTERACTIVE_SEARCH,
/* TODO: #32 iconview signals to emit when searching */
SEARCH_IN_PROGRESS,
SEARCH_CONCLUDED,
LAST_SIGNAL
};
......@@ -1188,6 +1191,42 @@ exo_icon_view_class_init (ExoIconViewClass *klass)
_exo_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN, 0);
/* TODO: #32 Create the signal for search-in-progress */
/**
* ExoIconView::search-in-progress:
* @icon_view: a #ExoIconView.
* @searching: Is search in progress (usually true)
*
* The ::search-in-progress signal is emitted the first time the search_entry
* is visible to the user.
* This usually occurs right after the start-interactive-search signal is emitted
* or typeahead search is activated
*/
icon_view_signals[SEARCH_IN_PROGRESS] =
g_signal_new (I_("search-in-progress"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
/* TODO: #32 Create the signal for search-concluded */
/**
* ExoIconView::search-concluded
* @icon_view: a #ExoIconView
* @searching: Is search in progress (usually false)
*
* The ::search-concluded signal is emitted the just after the search_entry
* is hidden, either due to a timeout or user intervention
*/
icon_view_signals[SEARCH_CONCLUDED] =
g_signal_new (I_("search-concluded"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
/**
* ExoIconView::move-cursor:
* @icon_view : a #ExoIconView.
......@@ -8305,6 +8344,9 @@ exo_icon_view_search_dialog_hide (GtkWidget *search_dialog,
{
g_signal_handler_disconnect (G_OBJECT (icon_view->priv->search_entry), icon_view->priv->search_entry_changed_id);
icon_view->priv->search_entry_changed_id = 0;
/* TODO: #32 - search has ended */
g_debug("Search has stopped");
g_signal_emit (icon_view, icon_view_signals[SEARCH_CONCLUDED], 0, FALSE);
}
/* disable the flush timeout */
......@@ -8387,7 +8429,6 @@ exo_icon_view_search_init (GtkWidget *search_entry,
GtkTreeModel *model;
GtkTreeIter iter;
const gchar *text;
gint length;
gint count = 0;
_exo_return_if_fail (GTK_IS_ENTRY (search_entry));
......@@ -8414,8 +8455,7 @@ exo_icon_view_search_init (GtkWidget *search_entry,
}
/* verify that we have a search text */
length = strlen (text);
if (length < 1)
if (strlen (text) != 0)
return;
/* verify that we have a valid model */
......@@ -8578,6 +8618,9 @@ exo_icon_view_search_start (ExoIconView *icon_view,
{
icon_view->priv->search_entry_changed_id = g_signal_connect (G_OBJECT (icon_view->priv->search_entry), "changed",
G_CALLBACK (exo_icon_view_search_init), icon_view);
/* TODO: #32 - search has started */
g_debug("Search is in progress");
g_signal_emit (icon_view, icon_view_signals[SEARCH_IN_PROGRESS], 0, TRUE);
}
/* start the search timeout */
......
......@@ -61,6 +61,15 @@ enum
PROP_SINGLE_CLICK_TIMEOUT,
};
/* Signal identifiers */
enum
{
/* TODO: #32 - treeview signals to emit when searching */
SEARCH_IN_PROGRESS,
SEARCH_CONCLUDED,
LAST_SIGNAL
};
static void exo_tree_view_finalize (GObject *object);
......@@ -88,6 +97,8 @@ static gboolean exo_tree_view_move_cursor (GtkTreeView *v
static gboolean exo_tree_view_single_click_timeout (gpointer user_data);
static void exo_tree_view_single_click_timeout_destroy (gpointer user_data);
static void exo_tree_view_emit_search_status (GtkWidget *widget,
GdkEventFocus *event);
struct _ExoTreeViewPrivate
......@@ -109,9 +120,13 @@ struct _ExoTreeViewPrivate
/* the path below the pointer or NULL */
GtkTreePath *hover_path;
/* a custom search entry */
GtkWidget *search_entry;
};
static guint tree_view_signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_PRIVATE (ExoTreeView, exo_tree_view, GTK_TYPE_TREE_VIEW)
......@@ -174,6 +189,38 @@ exo_tree_view_class_init (ExoTreeViewClass *klass)
_("The amount of time after which the item under the mouse cursor will be selected automatically in single click mode"),
0, G_MAXUINT, 0,
EXO_PARAM_READWRITE));
/* TODO: #32 Create the signal for search-in-progress */
/**
* ExoTreeView::search-in-progress:
* @tree_view: a #ExoTreeView.
* @searching: Is search in progress (usually true)
*
* The ::search-in-progress signal is emitted when the search_entry gains focus
*/
tree_view_signals[SEARCH_IN_PROGRESS] =
g_signal_new (I_("search-in-progress"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
/* TODO: #32 Create the signal for search-concluded */
/**
* ExoTreeView::search-concluded
* @tree_view: a #ExoTreeView
* @searching: Is search in progress (usually false)
*
* The ::search-concluded signal is emitted when the search_entry looses focus
*/
tree_view_signals[SEARCH_CONCLUDED] =
g_signal_new (I_("search-concluded"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}
......@@ -181,9 +228,20 @@ exo_tree_view_class_init (ExoTreeViewClass *klass)
static void
exo_tree_view_init (ExoTreeView *tree_view)
{
/* grab a pointer on the private data */
tree_view->priv = exo_tree_view_get_instance_private (tree_view);
tree_view->priv->single_click_timeout_id = -1;
tree_view->priv->search_entry = gtk_entry_new ();
g_signal_connect_swapped (G_OBJECT (tree_view->priv->search_entry),
"focus-in-event",
G_CALLBACK (exo_tree_view_emit_search_status), tree_view);
g_signal_connect_swapped (G_OBJECT (tree_view->priv->search_entry),
"focus-out-event",
G_CALLBACK (exo_tree_view_emit_search_status), tree_view);
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (tree_view->priv->search_entry));
}
......@@ -201,6 +259,14 @@ exo_tree_view_finalize (GObject *object)
if (G_UNLIKELY (tree_view->priv->hover_path == NULL))
gtk_tree_path_free (tree_view->priv->hover_path);
if (G_UNLIKELY (tree_view->priv->search_entry == NULL)) {
g_signal_handlers_disconnect_by_func (G_OBJECT (tree_view->priv->search_entry),
G_CALLBACK (exo_tree_view_emit_search_status),
tree_view);
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), NULL);
// TODO: #32 Do we free the entry??
}
(*G_OBJECT_CLASS (exo_tree_view_parent_class)->finalize) (object);
}
......@@ -718,8 +784,21 @@ exo_tree_view_single_click_timeout_destroy (gpointer user_data)
EXO_TREE_VIEW (user_data)->priv->single_click_timeout_id = -1;
}
static void
exo_tree_view_emit_search_status (GtkWidget *widget, GdkEventFocus *event)
{
ExoTreeView *tree_view = EXO_TREE_VIEW (widget);
if (event->in) {
/* TODO: #32 - search has started */
g_debug("Search is in progress");
g_signal_emit (tree_view, tree_view_signals[SEARCH_IN_PROGRESS], TRUE);
}
else {
/* TODO: #32 - search has ended */
g_debug("Search has stopped");
g_signal_emit (tree_view, tree_view_signals[SEARCH_CONCLUDED], FALSE);
}
}
/**
* exo_tree_view_new:
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment