DnD from treeview with multiple rows selected
- From: Colossus <colossus 3000 it>
- To: gtk-app-devel-list gnome org
- Subject: DnD from treeview with multiple rows selected
- Date: Tue, 27 Jun 2006 11:20:26 +0200
Hi,
I'm trying to implement XDS protocol to my app, xarchiver. I have two
rows selected in the treeview, when I drag these two rows and drop
them in Thunar file manager, everything goes wrong. When I drop only
one row it works. So my question is: how to retrieve the content of
the rows selected ? Here is some code:
static const GtkTargetEntry drag_targets[] =
{
{ "XdndDirectSave0", 0, 0 },
};
static const GtkTargetEntry drop_targets[] =
{
{ "text/uri-list", 0, 1 },
};
gtk_drag_dest_set
(MainWindow,GTK_DEST_DEFAULT_ALL,drop_targets,1,GDK_ACTION_COPY |
GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
gtk_drag_source_set (treeview1, GDK_BUTTON1_MASK, drag_targets,
1,GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
void drag_begin (GtkWidget *treeview1,GdkDragContext *context,
gpointer data)
{
GtkTreeSelection *selection;
GtkTreeIter iter;
gchar *name;
GList *row_list, *_row_list;
g_print ("Drag begin\n");
//gtk_drag_source_set_icon_name (treeview1,DATADIR
"/pixmaps/xarchiver.png" );
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1));
row_list = gtk_tree_selection_get_selected_rows (selection, NULL);
if ( row_list == NULL )
return;
while (row_list != NULL)
{
gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)(row_list->data));
gtk_tree_model_get (model, &iter, 0, &name, -1);
g_print ("%s\n",name);
gchar *no_slashes = StripPathFromFilename ( name, "/" );
no_slashes++;
gdk_property_change (context->source_window,
gdk_atom_intern ("XdndDirectSave0", FALSE),
gdk_atom_intern ("text/plain", FALSE), 8,
GDK_PROP_MODE_REPLACE, (guchar *)no_slashes, strlen
(no_slashes) );
row_list = row_list->next;
g_free (name);
}
g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (row_list);
}
void drag_data_get (GtkWidget *widget, GdkDragContext *dc,
GtkSelectionData *selection_data, guint info, guint t, gpointer data)
{
GtkTreeSelection *selection;
GtkTreeIter iter;
guchar *fm_path;
int fm_path_len;
gchar *command , *dummy_path , *name;
gchar *to_send = "E";
GList *row_list, *_row_list;
g_print ("Drag data get\n");
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1));
row_list = _row_list = gtk_tree_selection_get_selected_rows
(selection, NULL);
if ( row_list == NULL )
return;
while (_row_list != NULL)
{
gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)(_row_list->data));
gtk_tree_model_get (model, &iter, 0, &name, -1);
if ( gdk_property_get (dc->source_window,
gdk_atom_intern ("XdndDirectSave0", FALSE),
gdk_atom_intern ("text/plain", FALSE),
0, 1024, FALSE, NULL, NULL, &fm_path_len, &fm_path)
&& fm_path != NULL)
{
/* Zero-Terminate the string */
fm_path = g_realloc (fm_path, fm_path_len + 1);
fm_path[fm_path_len] = '\0';
//g_print ("fm_path = %s\n",fm_path);
dummy_path = g_filename_from_uri ( (gchar*)fm_path, NULL, NULL );
g_free ( fm_path );
//g_print ("%s - %s\n",dummy_path,name);
extract_path = extract_local_path ( dummy_path,name );
//g_message ("%s -- %s -- %s",dummy_path,name,extract_path);
g_free ( dummy_path );
if (extract_path != NULL)
to_send = "S";
names = g_string_new ("");
gtk_tree_selection_selected_foreach (selection,
(GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );
archive->full_path = 0;
archive->tar_strip_value = 0;
command = xa_extract_single_files ( archive , names, extract_path );
g_string_free (names, TRUE);
if ( command != NULL )
{
ExtractAddDelete ( command );
g_free (command);
}
//g_dataset_set_data (dc, "XDS-sent", to_send);
gtk_selection_data_set (selection_data,
selection_data->target, 8, (guchar*)to_send, 1);
}
if (extract_path != NULL)
g_free (extract_path);
extract_path = NULL;
g_free (name);
_row_list = _row_list->next;
}
g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (row_list);
}
The current code is on svn if someone wants to compile the entire app
(it is small):
$ svn co http://svn.xfce.org/svn/xfce/xarchiver/trunk
Any help is greatly appreciated !
Giuseppe Torelli
--
Xarchiver, a Linux GTK+2 only archive manager - http://xarchiver.xfce.org
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]