aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-03-30 01:07:50 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-03-30 01:07:50 +0800
commitc1a38e77d25cde47f4cc33922f0ef8983e12ae17 (patch)
tree9e8ca41c5c1bec6f7d8cd59831dc68c15e6813f5 /lib
parentf1d834f969e790e26fe7a0bd2aa203977113bc88 (diff)
downloadgsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar.gz
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar.bz2
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar.lz
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar.xz
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.tar.zst
gsoc2013-epiphany-c1a38e77d25cde47f4cc33922f0ef8983e12ae17.zip
Make dnd code smarter, so it can support more than just urls types.
2003-03-29 Marco Pesenti Gritti <marco@it.gnome.org> * lib/ephy-dnd.c: (add_one_node), (ephy_dnd_drag_data_get), (ephy_dnd_node_list_extract_nodes): * lib/ephy-dnd.h: * lib/ephy-marshal.list: * lib/widgets/ephy-tree-model-sort.c: (each_node_get_data_binder), (ephy_tree_model_sort_multi_drag_data_get): * src/bookmarks/ephy-bookmarks-editor.c: (cmd_rename), (cmd_select_all), (ephy_bookmarks_editor_show_popup_cb), (keyword_node_show_popup_cb), (node_dropped_cb), (ephy_bookmarks_editor_construct), (ephy_bookmarks_editor_update_menu): * src/bookmarks/ephy-node-view.c: (ephy_node_view_class_init), (ephy_node_view_button_press_cb), (ephy_node_view_has_focus), (get_node_from_path), (drag_motion_cb), (drag_drop_cb), (drag_data_received_cb), (ephy_node_view_enable_drag_dest), (ephy_node_view_enable_drag_source): * src/bookmarks/ephy-node-view.h: * src/ephy-favicon-action.c: (connect_proxy): * src/history-dialog.c: (history_dialog_setup_view): * src/toolbar.c: (toolbar_get_action_name): Make dnd code smarter, so it can support more than just urls types. Implement drag of bookmarks on topics in bme. What a pain !
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-dnd.c95
-rw-r--r--lib/ephy-dnd.h7
-rw-r--r--lib/ephy-marshal.list1
-rw-r--r--lib/widgets/ephy-tree-model-sort.c59
4 files changed, 101 insertions, 61 deletions
diff --git a/lib/ephy-dnd.c b/lib/ephy-dnd.c
index 7dfd1f272..ef39f37f0 100644
--- a/lib/ephy-dnd.c
+++ b/lib/ephy-dnd.c
@@ -17,25 +17,13 @@
*/
#include "ephy-dnd.h"
+#include "ephy-string.h"
+#include "ephy-node.h"
#include <gtk/gtkselection.h>
#include <gtk/gtktreeview.h>
#include <string.h>
-typedef enum {
- EPHY_DND_URI_LIST,
- EPHY_DND_TEXT,
- EPHY_DND_URL
-} EphyIconDndTargetType;
-
-static GtkTargetEntry url_drag_types [] =
-{
- { EPHY_DND_URI_LIST_TYPE, 0, EPHY_DND_URI_LIST },
- { EPHY_DND_TEXT_TYPE, 0, EPHY_DND_TEXT },
- { EPHY_DND_URL_TYPE, 0, EPHY_DND_URL }
-};
-static int n_url_drag_types = G_N_ELEMENTS (url_drag_types);
-
/* Encode a "_NETSCAPE_URL_" selection.
* As far as I can tell, Netscape is expecting a single
* URL to be returned. I cannot discover a way to construct
@@ -64,6 +52,17 @@ add_one_uri (const char *uri, int x, int y, int w, int h, gpointer data)
g_string_append (result, "\r\n");
}
+static void
+add_one_node (const char *uri, int x, int y, int w, int h, gpointer data)
+{
+ GString *result;
+
+ result = (GString *) data;
+
+ g_string_append (result, uri);
+ g_string_append (result, ";");
+}
+
gboolean
ephy_dnd_drag_data_get (GtkWidget *widget,
GdkDragContext *context,
@@ -73,21 +72,32 @@ ephy_dnd_drag_data_get (GtkWidget *widget,
gpointer container_context,
EphyDragEachSelectedItemIterator each_selected_item_iterator)
{
- GString *result;
+ GString *result = NULL;
+ GdkAtom target;
+
+ target = selection_data->target;
- switch (info) {
- case EPHY_DND_URI_LIST:
- case EPHY_DND_TEXT:
+ if (target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE) ||
+ target == gdk_atom_intern (EPHY_DND_TEXT_TYPE, FALSE))
+ {
result = g_string_new (NULL);
(* each_selected_item_iterator) (add_one_uri, container_context, result);
- break;
- case EPHY_DND_URL:
+ }
+ else if (target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE))
+ {
result = g_string_new (NULL);
(* each_selected_item_iterator) (add_one_netscape_url, container_context, result);
- break;
- default:
- return FALSE;
- }
+ }
+ else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) ||
+ target == gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE))
+ {
+ result = g_string_new (NULL);
+ (* each_selected_item_iterator) (add_one_node, container_context, result);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
gtk_selection_data_set (selection_data,
selection_data->target,
@@ -96,23 +106,30 @@ ephy_dnd_drag_data_get (GtkWidget *widget,
return TRUE;
}
-void
-ephy_dnd_url_drag_source_set (GtkWidget *widget)
+GList *
+ephy_dnd_node_list_extract_nodes (const char *node_list)
{
- gtk_drag_source_set (widget,
- GDK_BUTTON1_MASK,
- url_drag_types,
- n_url_drag_types,
- GDK_ACTION_COPY);
-}
+ GList *result = NULL;
+ char **nodes;
+ int i;
-void
-ephy_dnd_enable_model_drag_source (GtkWidget *treeview)
-{
- gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview),
- GDK_BUTTON1_MASK,
- url_drag_types, n_url_drag_types,
- GDK_ACTION_COPY);
+ nodes = g_strsplit (node_list, ";", -1);
+
+ for (i = 0; nodes[i] != NULL; i++)
+ {
+ gulong id;
+
+ if (ephy_str_to_int (nodes[i], &id))
+ {
+ EphyNode *node;
+
+ node = ephy_node_get_from_id (id);
+ g_return_val_if_fail (node != NULL, NULL);
+ result = g_list_append (result, node);
+ }
+ }
+
+ return result;
}
GList *
diff --git a/lib/ephy-dnd.h b/lib/ephy-dnd.h
index c1756713f..afeb4704d 100644
--- a/lib/ephy-dnd.h
+++ b/lib/ephy-dnd.h
@@ -29,7 +29,8 @@ G_BEGIN_DECLS
#define EPHY_DND_URI_LIST_TYPE "text/uri-list"
#define EPHY_DND_TEXT_TYPE "text/plain"
#define EPHY_DND_URL_TYPE "_NETSCAPE_URL"
-#define EPHY_DND_TOPIC_TYPE "ephy_topic"
+#define EPHY_DND_TOPIC_TYPE "ephy_topic_node"
+#define EPHY_DND_BOOKMARK_TYPE "ephy_bookmark_node"
typedef void (* EphyDragEachSelectedItemDataGet) (const char *url,
int x, int y, int w, int h,
@@ -47,9 +48,7 @@ gboolean ephy_dnd_drag_data_get (GtkWidget *widget,
gpointer container_context,
EphyDragEachSelectedItemIterator each_selected_item_iterator);
-void ephy_dnd_url_drag_source_set (GtkWidget *widget);
-
-void ephy_dnd_enable_model_drag_source (GtkWidget *treeview);
+GList *ephy_dnd_node_list_extract_nodes (const char *node_list);
GList *ephy_dnd_uri_list_extract_uris (const char *uri_list);
diff --git a/lib/ephy-marshal.list b/lib/ephy-marshal.list
index 9082cae25..1d6c352cf 100644
--- a/lib/ephy-marshal.list
+++ b/lib/ephy-marshal.list
@@ -1,6 +1,7 @@
VOID:VOID
VOID:STRING
VOID:OBJECT
+VOID:OBJECT, POINTER
VOID:OBJECT,OBJECT,INT
VOID:OBJECT,STRING,INT
VOID:OBJECT,INT
diff --git a/lib/widgets/ephy-tree-model-sort.c b/lib/widgets/ephy-tree-model-sort.c
index 41369afd9..bc32131f3 100644
--- a/lib/widgets/ephy-tree-model-sort.c
+++ b/lib/widgets/ephy-tree-model-sort.c
@@ -19,6 +19,7 @@
*/
#include <gtk/gtkmarshal.h>
+#include <gtk/gtktreednd.h>
#include <string.h>
#include "ephy-node.h"
@@ -236,17 +237,47 @@ each_url_get_data_binder (EphyDragEachSelectedItemDataGet iteratee,
}
}
+static void
+each_node_get_data_binder (EphyDragEachSelectedItemDataGet iteratee,
+ gpointer iterator_context, gpointer data)
+{
+ gpointer *context = (gpointer *) iterator_context;
+ GList *path_list = (GList *) (context[0]);
+ GList *i;
+ GtkTreeModel *model = GTK_TREE_MODEL (context[1]);
+
+ for (i = path_list; i != NULL; i = i->next)
+ {
+ GtkTreeIter iter;
+ GtkTreePath *path = gtk_tree_row_reference_get_path (i->data);
+ EphyNode *node = NULL;
+ char *value;
+
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+ g_signal_emit (G_OBJECT (model),
+ ephy_tree_model_sort_signals[NODE_FROM_ITER],
+ 0, &iter, &node);
+ if (node == NULL)
+ return;
+
+ value = g_strdup_printf ("%ld", ephy_node_get_id (node));
+ iteratee (value, -1, -1, -1, -1, data);
+ g_free (value);
+ }
+}
+
static gboolean
ephy_tree_model_sort_multi_drag_data_get (EggTreeMultiDragSource *drag_source,
GList *path_list,
guint info,
GtkSelectionData *selection_data)
{
- EphyTreeModelSort *ms = EPHY_TREE_MODEL_SORT (drag_source);
+ GdkAtom target;
- /* FIXME use the target type here, not property_id */
+ target = selection_data->target;
- if (ms->priv->drag_property_id != -1)
+ if (target == gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE) ||
+ target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE))
{
gpointer icontext[2];
@@ -254,26 +285,18 @@ ephy_tree_model_sort_multi_drag_data_get (EggTreeMultiDragSource *drag_source,
icontext[1] = drag_source;
ephy_dnd_drag_data_get (NULL, NULL, selection_data,
- info, 0, &icontext, each_url_get_data_binder);
+ info, 0, &icontext, each_node_get_data_binder);
+
}
else
{
- GtkTreeIter iter;
- GtkTreePath *path = gtk_tree_row_reference_get_path (path_list->data);
- EphyNode *node = NULL;
- char *data;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path);
- g_signal_emit (G_OBJECT (drag_source),
- ephy_tree_model_sort_signals[NODE_FROM_ITER],
- 0, &iter, &node);
+ gpointer icontext[2];
- /* FIXME free */
- data = g_strdup_printf ("%ld", ephy_node_get_id (node));
+ icontext[0] = path_list;
+ icontext[1] = drag_source;
- gtk_selection_data_set (selection_data,
- selection_data->target,
- 8, data, strlen (data));
+ ephy_dnd_drag_data_get (NULL, NULL, selection_data,
+ info, 0, &icontext, each_url_get_data_binder);
}
return TRUE;