[Glade-users] GtkTreeView - row select event?
- From: Remi Cohen-Scali com (Rémi Cohen-Scali)
- Subject: [Glade-users] GtkTreeView - row select event?
- Date: Fri, 08 Aug 2003 11:34:25 +0200
Yes you can then test if there's a selection with 'get_selected'.
Another way exists by registering a select func.
here is an example of code (from gpdf):
static gboolean
gpdf_bookmarks_view_bookmark_select_func (GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer data)
{
GPdfBookmarksView *bookmarks_view;
GPdfBookmarksViewPrivate *priv;
GValue selection_item = {0,};
GtkTreeIter iterator;
OutlineItem *item;
gboolean ret = FALSE;
bookmarks_view = GPDF_BOOKMARKS_VIEW (data);
g_return_val_if_fail (GPDF_IS_NON_NULL_BOOKMARKS_VIEW (bookmarks_view),
FALSE);
do {
priv = bookmarks_view->priv;
gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->model),
&iterator,
path);
/* handle only if is about to be selected */
if (!gtk_tree_selection_get_selected (selection,
&model,
&iterator)) {
gtk_tree_model_get_value (GTK_TREE_MODEL (priv->model),
&iterator,
GPDF_BKVIEW_COLUMN4,
&selection_item);
item = (OutlineItem *)g_value_peek_pointer ((const GValue*)
&selection_item);
gpdf_bookmarks_view_emit_bookmark_selected (bookmarks_view,
item->getAction ());
}
ret = TRUE;
}
while (0);
return ret;
}
Note the 'if (!gtk_tree_selection_get_selected'. You may compare this
use with another that
update sensitivity of some buttons and using the "changed" signal.
static void
gpdf_bookmarks_view_update_popup_actions (GPdfBookmarksView *bookmarks_view)
{
GPdfBookmarksViewPrivate *priv;
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
G_List *selrows;
GtkTreePath *path;
GtkWidget *item;
gboolean is_expandable = FALSE, is_expanded = FALSE;
g_return_if_fail (GPDF_IS_NON_NULL_BOOKMARKS_VIEW (bookmarks_view));
priv = bookmarks_view->priv;
model = GTK_TREE_MODEL (priv->model);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW
(priv->treeview));
selrows = gtk_tree_selection_get_selected_rows (selection, &model);
g_message ("gpdf_bookmarks_view_update_popup_actions: %d rows selected",
g_list_length (selrows));
if (g_list_length (selrows) == 1) {
path = (GtkTreePath *)g_list_nth_data (selrows, 0);
g_message ("gpdf_bookmarks_view_update_popup_actions: selected
path = '%s'",
gtk_tree_path_to_string (path));
if (gtk_tree_model_get_iter (model, &iter, path)) {
g_message ("gpdf_bookmarks_view_update_popup_actions:
iterator = '%s'",
gtk_tree_model_get_string_from_iter(model, &iter));
is_expandable = gtk_tree_model_iter_has_child(GTK_TREE_MODEL
(priv->model),
&iter);
is_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW
(priv->treeview),
path);
}
}
item = gtk_item_factory_get_widget (priv->ifactory,
POPUP_MENU_EXPAND_ITEM_PATH);
gtk_widget_set_sensitive (item, is_expandable && !is_expanded);
item = gtk_item_factory_get_widget (priv->ifactory,
POPUP_MENU_COLLAPSE_ITEM_PATH);
gtk_widget_set_sensitive (item, is_expandable && is_expanded);
}
static void
gpdf_bookmarks_view_selection_changed_cb (GtkTreeSelection *selection,
gpointer data)
{
GPdfBookmarksView *bookmarks_view = GPDF_BOOKMARKS_VIEW (data);
g_return_if_fail (GPDF_IS_NON_NULL_BOOKMARKS_VIEW (bookmarks_view));
gpdf_bookmarks_view_update_popup_actions (bookmarks_view);
}
You can have full file access by checking out the
gpdf/xpdf/gpdf-bookmarks-view.c from
gpdf-outlines branch in gnome CVS repository.
cvs co -r gpdf-outlines gpdf/xpdf/gpdf-bookmarks-view.c
Hope it will help
John Coppens wrote:
On Thu, 07 Aug 2003 22:26:54 +0200
R�mi Cohen-Scali <Remi Cohen-Scali com> wrote:
Get the GtkTreeSelection object on your treeview
(gtk_tree_view_get_selection) then listen for
"changed" events
g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK
(selection_changed_cb), data)
Hello R�mi,
Thanks for the reply. I had noticed the 'changed event', but I read in the
GTK reference:
"Emitted whenever the selection has (possibly) changed. Please note that
this signal is mostly a hint. It may only be emitted once when a range of
rows are selected, and it may occasionally be emitted when nothing has
happened."
This didn't give me a very convincing impression... Is this wrong? Or is
is necessary to keep a copy of the selection and compare it each time an
event arrives?
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]