aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@svn.gnome.org>2007-09-11 06:46:48 +0800
committerCosimo Cecchi <cosimoc@src.gnome.org>2007-09-11 06:46:48 +0800
commit44a63e712da2b69162a0387ac05ee23a35aec479 (patch)
tree33d66a9ea5bf9c62bd42436b26d2beb017b109eb /src
parent5606ae245b489fed230a65cce0a46be5e15ea298 (diff)
downloadgsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar.gz
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar.bz2
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar.lz
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar.xz
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.tar.zst
gsoc2013-epiphany-44a63e712da2b69162a0387ac05ee23a35aec479.zip
Adds drag-and-drop of URLs onto "New Tab" and "New Window" buttons in the
2007-09-11 Cosimo Cecchi <cosimoc@svn.gnome.org> * src/ephy-home-action.c: (action_name_association), (ephy_home_action_activate), (home_action_drag_data_received_cb), (connect_proxy), (disconnect_proxy), (ephy_home_action_class_init): Adds drag-and-drop of URLs onto "New Tab" and "New Window" buttons in the toolbar. Fixes bug #382383. svn path=/trunk/; revision=7382
Diffstat (limited to 'src')
-rw-r--r--src/ephy-home-action.c161
1 files changed, 147 insertions, 14 deletions
diff --git a/src/ephy-home-action.c b/src/ephy-home-action.c
index b115c4982..2758a6e4c 100644
--- a/src/ephy-home-action.c
+++ b/src/ephy-home-action.c
@@ -24,17 +24,29 @@
#include "ephy-link.h"
#include "ephy-prefs.h"
#include "ephy-gui.h"
+#include "ephy-dnd.h"
#include "eel-gconf-extensions.h"
#include <string.h>
#include <gtk/gtkclipboard.h>
+#include <gtk/gtktoolitem.h>
+
+#define INSANE_NUMBER_OF_URLS 20
typedef struct
{
GObject *weak_ptr;
EphyLinkFlags flags;
} ClipboardCtx;
+
+static const GtkTargetEntry url_drag_types [] =
+{
+ { EPHY_DND_URI_LIST_TYPE, 0, 0 },
+ { EPHY_DND_URL_TYPE, 0, 1 }
+};
+
+static GObjectClass *parent_class = NULL;
static void
clipboard_text_received_cb (GtkClipboard *clipboard,
@@ -100,6 +112,51 @@ ephy_home_action_open (GtkAction *action,
}
static void
+action_name_association (GtkAction *action,
+ char *action_name,
+ char *address,
+ gboolean is_drag_action)
+{
+ if (strcmp (action_name, "FileNewTab") == 0)
+ {
+ if (is_drag_action)
+ {
+ ephy_link_open (EPHY_LINK (action),
+ address, NULL,
+ EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO);
+ }
+ else
+ {
+ ephy_home_action_open (action,
+ address,
+ EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO);
+ }
+ }
+ else if (strcmp (action_name, "FileNewWindow") == 0)
+ {
+ if (is_drag_action)
+ {
+ ephy_link_open (EPHY_LINK (action),
+ address, NULL,
+ EPHY_LINK_NEW_WINDOW);
+ }
+ else
+ {
+ ephy_home_action_open (action,
+ address,
+ EPHY_LINK_NEW_WINDOW);
+ }
+ }
+ else if (strcmp (action_name, "GoHome") == 0)
+ {
+ ephy_link_open (EPHY_LINK (action),
+ address != NULL && address[0] != '\0' ? address : "about:blank",
+ NULL,
+ ephy_link_flags_from_current_event ());
+ }
+}
+
+static void
ephy_home_action_activate (GtkAction *action)
{
char *action_name;
@@ -109,36 +166,112 @@ ephy_home_action_activate (GtkAction *action)
address = eel_gconf_get_string (CONF_GENERAL_HOMEPAGE);
- if (strcmp (action_name, "GoHome") == 0)
+ action_name_association (action, action_name, address, FALSE);
+
+ g_free (address);
+}
+
+static void
+home_action_drag_data_received_cb (GtkWidget* widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ EphyHomeAction *action)
+{
+ gchar *action_name;
+
+ g_object_get (action, "name", &action_name, NULL);
+
+ g_signal_stop_emission_by_name (widget, "drag_data_received");
+
+ if (selection_data->length <= 0 || selection_data->data == NULL) return;
+
+ if (selection_data->target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE))
{
+ char **split;
- ephy_link_open (EPHY_LINK (action),
- address != NULL && address[0] != '\0' ? address : "about:blank",
- NULL,
- ephy_link_flags_from_current_event ());
+ split = g_strsplit ((const gchar *)selection_data->data, "\n", 2);
+ if (split != NULL && split[0] != NULL && split[0][0] != '\0')
+ {
+ action_name_association (GTK_ACTION (action),
+ action_name, split[0], TRUE);
+ }
+ g_strfreev (split);
}
- else if (strcmp (action_name, "FileNewTab") == 0)
+ else if (selection_data->target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE))
{
- ephy_home_action_open (action,
- address,
- EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO);
+ char **uris;
+ int i;
+
+ uris = gtk_selection_data_get_uris (selection_data);
+ if (uris == NULL) return;
+
+ for (i = 0; uris[i] != NULL && i < INSANE_NUMBER_OF_URLS; i++)
+ {
+ action_name_association (GTK_ACTION (action),
+ action_name, uris[i], TRUE);
+ }
+
+ g_strfreev (uris);
}
- else if (strcmp (action_name, "FileNewWindow") == 0)
+ else
{
- ephy_home_action_open (action,
- address,
- EPHY_LINK_NEW_WINDOW);
+ char *text;
+
+ text = (char *) gtk_selection_data_get_text (selection_data);
+ if (text != NULL)
+ {
+ action_name_association (GTK_ACTION (action),
+ action_name, text, TRUE);
+ }
}
+}
- g_free (address);
+static void
+connect_proxy (GtkAction *action,
+ GtkWidget *proxy)
+{
+ gchar *action_name;
+
+ GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);
+
+ g_object_get (action, "name", &action_name, NULL);
+
+ if (GTK_IS_TOOL_ITEM (proxy) && (strcmp (action_name, "GoHome") != 0))
+ {
+ g_signal_connect (GTK_BIN (proxy)->child, "drag-data-received",
+ G_CALLBACK (home_action_drag_data_received_cb), action);
+ gtk_drag_dest_set (GTK_BIN (proxy)->child,
+ GTK_DEST_DEFAULT_ALL,
+ url_drag_types, G_N_ELEMENTS (url_drag_types),
+ GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ gtk_drag_dest_add_text_targets (GTK_BIN (proxy)->child);
+ }
+}
+
+static void
+disconnect_proxy (GtkAction *action,
+ GtkWidget *proxy)
+{
+ g_signal_handlers_disconnect_by_func
+ (proxy, G_CALLBACK (gtk_action_activate), action);
+
+ GTK_ACTION_CLASS (parent_class)->disconnect_proxy (action, proxy);
}
static void
ephy_home_action_class_init (EphyHomeActionClass *class)
{
GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+ parent_class = g_type_class_peek_parent (class);
action_class->activate = ephy_home_action_activate;
+ action_class->connect_proxy = connect_proxy;
+ action_class->disconnect_proxy = disconnect_proxy;
}
GType