summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2012-05-25 11:05:02 +0200
committerXan Lopez <xan@igalia.com>2012-08-31 14:49:18 +0200
commit0835601669710b63bb99e563567ce04720dc3f1f (patch)
tree15402f45c66ccc7bed3eba51f7e9fc39b1a72239
parente661e1552e58d5c67be65301bb0898541c143dee (diff)
downloadepiphany-0835601669710b63bb99e563567ce04720dc3f1f.tar.gz
gd-main-view: add a "item-deleted" signal to handle user-triggered item deletions
GdMainView connects to GdMainViewGeneric:delete-item-clicked and emits its :item-deleted signal which, if unhandled, simply removes the item in question from the underlying model. Users of GdMainView can handle this signal and stop the default handler from being invoked, thus avoiding removal of the item.
-rw-r--r--lib/widgets/gd-main-view.c56
-rw-r--r--lib/widgets/gd-main-view.h5
2 files changed, 61 insertions, 0 deletions
diff --git a/lib/widgets/gd-main-view.c b/lib/widgets/gd-main-view.c
index 8c3545e99..66984267f 100644
--- a/lib/widgets/gd-main-view.c
+++ b/lib/widgets/gd-main-view.c
@@ -47,6 +47,7 @@ enum {
enum {
ITEM_ACTIVATED = 1,
+ ITEM_DELETED,
SELECTION_MODE_REQUEST,
VIEW_SELECTION_CHANGED,
NUM_SIGNALS
@@ -148,6 +149,27 @@ gd_main_view_set_property (GObject *object,
}
}
+static gboolean
+gd_main_view_real_item_deleted (GdMainView *self,
+ const gchar *path)
+{
+#if 0
+ /* Handling this breaks the logic of the models used. I think
+ we shouldn't handle this at all. */
+ GtkTreePath *tree_path = gtk_tree_path_new_from_string (path);
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter (self->priv->model, &iter, tree_path)) {
+ gtk_tree_path_free (tree_path);
+ return FALSE;
+ }
+
+ gtk_list_store_remove (GTK_LIST_STORE (self->priv->model), &iter);
+ gtk_tree_path_free (tree_path);
+#endif
+ return TRUE;
+}
+
static void
gd_main_view_class_init (GdMainViewClass *klass)
{
@@ -158,6 +180,8 @@ gd_main_view_class_init (GdMainViewClass *klass)
oclass->dispose = gd_main_view_dispose;
oclass->finalize = gd_main_view_finalize;
+ klass->item_deleted = gd_main_view_real_item_deleted;
+
properties[PROP_VIEW_TYPE] =
g_param_spec_int ("view-type",
"View type",
@@ -195,6 +219,16 @@ gd_main_view_class_init (GdMainViewClass *klass)
G_TYPE_STRING,
GTK_TYPE_TREE_PATH);
+ signals[ITEM_DELETED] =
+ g_signal_new ("item-deleted",
+ GD_TYPE_MAIN_VIEW,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdMainViewClass, item_deleted),
+ g_signal_accumulator_true_handled, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
+
signals[SELECTION_MODE_REQUEST] =
g_signal_new ("selection-mode-request",
GD_TYPE_MAIN_VIEW,
@@ -527,6 +561,17 @@ on_drag_begin (GdMainViewGeneric *generic,
}
static void
+on_delete_item_clicked (GdMainViewGeneric *generic,
+ const gchar *path,
+ GdMainView *self)
+{
+ g_free (self->priv->button_press_item_path);
+ self->priv->button_press_item_path = NULL;
+
+ gd_main_view_item_deleted (self, path);
+}
+
+static void
gd_main_view_apply_model (GdMainView *self)
{
GdMainViewGeneric *generic = get_generic (self);
@@ -587,6 +632,8 @@ gd_main_view_rebuild (GdMainView *self)
G_CALLBACK (on_button_release_event), self);
g_signal_connect_after (self->priv->current_view, "drag-begin",
G_CALLBACK (on_drag_begin), self);
+ g_signal_connect (self->priv->current_view, "delete-item-clicked",
+ G_CALLBACK (on_delete_item_clicked), self);
gd_main_view_apply_selection_mode (self);
gd_main_view_apply_model (self);
@@ -723,3 +770,12 @@ gd_main_view_get_selection (GdMainView *self)
return g_list_reverse (retval);
}
+
+void
+gd_main_view_item_deleted (GdMainView *self,
+ const gchar *path)
+{
+ gboolean result;
+
+ g_signal_emit (self, signals [ITEM_DELETED], 0, path, &result);
+}
diff --git a/lib/widgets/gd-main-view.h b/lib/widgets/gd-main-view.h
index b6906a10f..7a082ad9f 100644
--- a/lib/widgets/gd-main-view.h
+++ b/lib/widgets/gd-main-view.h
@@ -77,6 +77,9 @@ struct _GdMainView {
struct _GdMainViewClass {
GtkScrolledWindowClass parent_class;
+
+ gboolean (* item_deleted) (GdMainView *self,
+ const gchar *path);
};
GType gd_main_view_get_type (void) G_GNUC_CONST;
@@ -98,6 +101,8 @@ void gd_main_view_set_model (GdMainView *self,
GtkWidget * gd_main_view_get_generic_view (GdMainView *self);
+void gd_main_view_item_deleted (GdMainView *self, const gchar *path);
+
G_END_DECLS
#endif /* __GD_MAIN_VIEW_H__ */