Commit 7e8e6b0c authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

implement the gtk_tree_drag_source interface for gth_file_store

parent bacfb449
......@@ -2294,42 +2294,6 @@ gth_file_view_item_activated_cb (GtkIconView *iconview,
}
static void
gth_file_list_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint time,
gpointer extra_data)
{
GthBrowser *browser = extra_data;
GList *items;
GList *file_list;
int n_uris;
char **uris;
int i;
GList *scan;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
n_uris = g_list_length (file_list);
uris = g_new (char *, n_uris + 1);
for (i = 0, scan = file_list; scan; scan = scan->next, i++) {
GthFileData *file_data = scan->data;
uris[i] = g_file_get_uri (file_data->file);
g_print ("==> %s\n", uris[i]);
}
uris[i] = NULL;
gtk_selection_data_set_uris (selection_data, uris);
g_strfreev (uris);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
static void
add_browser_toolbar_menu_buttons (GthBrowser *browser)
{
......@@ -2812,11 +2776,6 @@ _gth_browser_construct (GthBrowser *browser)
G_CALLBACK (gth_file_view_item_activated_cb),
browser);
g_signal_connect (gth_file_list_get_view (GTH_FILE_LIST (browser->priv->file_list)),
"drag_data_get",
G_CALLBACK (gth_file_list_drag_data_get),
browser);
browser->priv->file_list_popup = gtk_ui_manager_get_widget (browser->priv->ui, "/FileListPopup");
/* the filter bar */
......
......@@ -467,8 +467,90 @@ gth_file_store_iter_parent (GtkTreeModel *tree_model,
}
static gboolean
gth_file_store_row_draggable (GtkTreeDragSource *drag_source,
GtkTreePath *path)
{
return TRUE;
}
static gboolean
gth_file_store_drag_data_get (GtkTreeDragSource *drag_source,
GtkTreePath *path,
GtkSelectionData *selection_data)
{
gboolean retval = FALSE;
GthFileStore *file_store;
int *indices, n;
GthFileRow *row;
g_return_val_if_fail (path != NULL, FALSE);
file_store = GTH_FILE_STORE (drag_source);
indices = gtk_tree_path_get_indices (path);
n = indices[0];
if ((n < 0) || (n >= file_store->priv->num_rows))
return FALSE;
row = file_store->priv->rows[n];
g_return_val_if_fail (row != NULL, FALSE);
g_return_val_if_fail (row->pos == n, FALSE);
if (gtk_selection_data_targets_include_uri (selection_data)) {
char **uris;
uris = g_new (char *, 2);
uris[0] = g_file_get_uri (row->file->file);
uris[1] = NULL;
gtk_selection_data_set_uris (selection_data, uris);
retval = TRUE;
g_strfreev (uris);
}
else if (gtk_selection_data_targets_include_text (selection_data)) {
char *parse_name;
parse_name = g_file_get_parse_name (row->file->file);
gtk_selection_data_set_text (selection_data, parse_name, -1);
retval = TRUE;
g_free (parse_name);
}
return retval;
}
static gboolean
gth_file_store_drag_data_delete (GtkTreeDragSource *drag_source,
GtkTreePath *path)
{
GthFileStore *file_store;
int *indices, n;
GthFileRow *row;
g_return_val_if_fail (path != NULL, FALSE);
file_store = GTH_FILE_STORE (drag_source);
indices = gtk_tree_path_get_indices (path);
n = indices[0];
if ((n < 0) || (n >= file_store->priv->num_rows))
return FALSE;
row = file_store->priv->rows[n];
g_return_val_if_fail (row != NULL, FALSE);
g_return_val_if_fail (row->pos == n, FALSE);
gth_file_store_remove (file_store, row->abs_pos);
return TRUE;
}
static void
tree_model_iface_init (GtkTreeModelIface *iface)
gtk_tree_model_iface_init (GtkTreeModelIface *iface)
{
iface->get_flags = gth_file_store_get_flags;
iface->get_n_columns = gth_file_store_get_n_columns;
......@@ -485,6 +567,15 @@ tree_model_iface_init (GtkTreeModelIface *iface)
}
static void
gtk_tree_drag_source_iface_init (GtkTreeDragSourceIface *iface)
{
iface->row_draggable = gth_file_store_row_draggable;
iface->drag_data_get = gth_file_store_drag_data_get;
iface->drag_data_delete = gth_file_store_drag_data_delete;
}
GType
gth_file_store_get_type (void)
{
......@@ -502,18 +593,20 @@ gth_file_store_get_type (void)
0,
(GInstanceInitFunc) gth_file_store_init
};
static const GInterfaceInfo tree_model_info = {
(GInterfaceInitFunc) tree_model_iface_init,
static const GInterfaceInfo gtk_tree_model_info = {
(GInterfaceInitFunc) gtk_tree_model_iface_init,
NULL,
NULL
};
static const GInterfaceInfo gtk_tree_drag_source_info = {
(GInterfaceInitFunc) gtk_tree_drag_source_iface_init,
NULL,
NULL
};
type = g_type_register_static (G_TYPE_OBJECT,
"GthFileStore",
&type_info,
0);
g_type_add_interface_static (type, GTK_TYPE_TREE_MODEL, &tree_model_info);
type = g_type_register_static (G_TYPE_OBJECT, "GthFileStore", &type_info, 0);
g_type_add_interface_static (type, GTK_TYPE_TREE_MODEL, &gtk_tree_model_info);
g_type_add_interface_static (type, GTK_TYPE_TREE_DRAG_SOURCE, &gtk_tree_drag_source_info);
}
return type;
......
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