changeset 1393:79b32088ecc4

show a label instead of the default drag icon
author nadvornik
date Sun, 08 Mar 2009 10:25:24 +0000
parents d1b32a69b40a
children bec57fa486f4
files src/advanced_exif.c src/bar_exif.c src/bar_keywords.c src/dnd.c src/dnd.h
diffstat 5 files changed, 50 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/advanced_exif.c	Sun Mar 08 09:56:40 2009 +0000
+++ b/src/advanced_exif.c	Sun Mar 08 10:25:24 2009 +0000
@@ -250,11 +250,6 @@
 
 }
 
-static void advanced_exif_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
-{
-	GtkWidget *window = data;
-	gtk_widget_destroy(window);
-}
 
 static void advanced_exif_dnd_begin(GtkWidget *listview, GdkDragContext *context, gpointer data)
 {
@@ -266,21 +261,10 @@
 		{
 		GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview));
 		gchar *key;
-		GtkWidget *window;
-		GtkWidget *label;
 
 		gtk_tree_model_get(store, &iter, EXIF_ADVCOL_NAME, &key, -1);
 
-		window = gtk_window_new(GTK_WINDOW_POPUP);
-		gtk_widget_realize (window);
-
-		label = gtk_label_new(key);
-		gtk_container_add(GTK_CONTAINER (window), label);
-		gtk_widget_show(label);
-		gtk_drag_set_icon_widget(context, window, -15, 10);
-		g_signal_connect(G_OBJECT(listview), "drag_end",
-				 G_CALLBACK(advanced_exif_dnd_end), window);
-
+		dnd_set_drag_label(listview, context, key);
 		g_free(key);
 		}
 }
--- a/src/bar_exif.c	Sun Mar 08 09:56:40 2009 +0000
+++ b/src/bar_exif.c	Sun Mar 08 10:25:24 2009 +0000
@@ -320,9 +320,11 @@
 	gtk_box_reorder_child(GTK_BOX(ped->vbox), new_entry, pos);
 }
 
-static void bar_pane_exif_entry_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
+static void bar_pane_exif_entry_dnd_begin(GtkWidget *entry, GdkDragContext *context, gpointer data)
 {
-//	gtk_drag_set_icon_default(context);
+	ExifEntry *ee = g_object_get_data(G_OBJECT(entry), "entry_data");
+	if (!ee) return;
+	dnd_set_drag_label(entry, context, ee->key);
 }
 
 static void bar_pane_exif_entry_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
--- a/src/bar_keywords.c	Sun Mar 08 09:56:40 2009 +0000
+++ b/src/bar_keywords.c	Sun Mar 08 10:25:24 2009 +0000
@@ -490,15 +490,32 @@
 			{
 			gchar *name = keyword_get_name(keyword_tree, &child_iter);
 			gtk_selection_data_set_text(selection_data, name, -1);
-printf("name %s\n", name);
 			g_free(name);
 			}
 			break;
 		}
 }
 
-static void bar_pane_keywords_dnd_begin(GtkWidget *treeview, GdkDragContext *context, gpointer data)
+static void bar_pane_keywords_dnd_begin(GtkWidget *tree_view, GdkDragContext *context, gpointer data)
 {
+	GtkTreeIter iter;
+	GtkTreeModel *model;
+	GtkTreeIter child_iter;
+	GtkTreeModel *keyword_tree;
+	gchar *name;
+
+	GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); 
+
+        if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return;
+
+	keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));
+	gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter);
+
+	name = keyword_get_name(keyword_tree, &child_iter);
+
+	dnd_set_drag_label(tree_view, context, name);
+	g_free(name);
+
 }
 
 static void bar_pane_keywords_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
--- a/src/dnd.c	Sun Mar 08 09:56:40 2009 +0000
+++ b/src/dnd.c	Sun Mar 08 10:25:24 2009 +0000
@@ -167,4 +167,29 @@
 	g_object_unref(pixmap);
 	if (mask) g_object_unref(mask);
 }
+
+static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *context, gpointer data)
+{
+	GtkWidget *window = data;
+	g_signal_handlers_disconnect_by_func(widget, dnd_set_drag_label_end_cb, data);
+	gtk_widget_destroy(window);
+}
+
+void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
+{
+	GtkWidget *window;
+	GtkWidget *label;
+
+	window = gtk_window_new(GTK_WINDOW_POPUP);
+	gtk_widget_realize (window);
+
+	label = gtk_label_new(text);
+	gtk_container_add(GTK_CONTAINER (window), label);
+	gtk_widget_show(label);
+	gtk_drag_set_icon_widget(context, window, -15, 10);
+	g_signal_connect(G_OBJECT(widget), "drag_end",
+			 G_CALLBACK(dnd_set_drag_label_end_cb), window);
+}
+
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/dnd.h	Sun Mar 08 09:56:40 2009 +0000
+++ b/src/dnd.h	Sun Mar 08 10:25:24 2009 +0000
@@ -37,6 +37,7 @@
 /* sets a drag icon to pixbuf, if items is > 1, text is drawn onto icon to indicate value */
 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items);
 
+void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */