From 8b7a35d4587cbd28c7c7bebabddb8a27c9f12bc9 Mon Sep 17 00:00:00 2001 From: Peter Harvey Date: Mon, 16 Jan 2006 22:50:01 +0000 Subject: src/bookmarks/ephy-topic-action.c 2006-01-17 Peter Harvey * src/bookmarks/ephy-topic-action.c Handle DnD to topics on the toolbar. --- src/bookmarks/ephy-topic-action.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src') diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index dd3844af4..0bac49b06 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -28,8 +28,10 @@ #include "ephy-bookmarks.h" #include "ephy-bookmarks-ui.h" #include "ephy-bookmarks-menu.h" +#include "ephy-shell.h" #include "ephy-gui.h" #include "ephy-debug.h" +#include "ephy-dnd.h" #include #include @@ -47,6 +49,10 @@ #include #include +static const GtkTargetEntry dest_drag_types[] = { + {EPHY_DND_URL_TYPE, 0, 0}, +}; + #define TOOLITEM_WIDTH_CHARS 24 #define MENUITEM_WIDTH_CHARS 32 #define LABEL_WIDTH_CHARS 32 @@ -100,6 +106,53 @@ ephy_topic_action_get_type (void) return type; } +static void +drag_data_received_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint time, + GtkAction *action) +{ + const char *data; + EphyBookmarks *bookmarks; + EphyNode *bookmark, *topic; + gchar **netscape_url; + + topic = ephy_topic_action_get_topic (EPHY_TOPIC_ACTION (action)); + + data = (char *)selection_data->data; + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + + netscape_url = g_strsplit (data, "\n", 2); + if (!netscape_url || !netscape_url[0]) + { + g_strfreev (netscape_url); + gtk_drag_finish (context, FALSE, FALSE, time); + return; + } + + bookmark = ephy_bookmarks_find_bookmark (bookmarks, netscape_url[0]); + if (bookmark == NULL) + { + bookmark = ephy_bookmarks_add (bookmarks, netscape_url[1], netscape_url[0]); + } + + g_strfreev (netscape_url); + + if (bookmark != NULL) + { + ephy_bookmarks_set_keyword (bookmarks, topic, bookmark); + gtk_drag_finish (context, TRUE, FALSE, time); + } + else + { + gtk_drag_finish (context, FALSE, FALSE, time); + } +} + static GtkWidget * create_tool_item (GtkAction *action) { @@ -320,6 +373,11 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) G_CALLBACK (button_press_cb), action); g_signal_connect (button, "button-release-event", G_CALLBACK (button_release_cb), action); + + g_signal_connect (button, "drag_data_received", + G_CALLBACK (drag_data_received_cb), action); + gtk_drag_dest_set (button, GTK_DEST_DEFAULT_ALL, dest_drag_types, + G_N_ELEMENTS (dest_drag_types), GDK_ACTION_COPY); } else if (GTK_IS_MENU_ITEM (proxy)) { -- cgit v1.2.3