diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-dnd.c | 6 | ||||
-rw-r--r-- | lib/ephy-dnd.h | 10 | ||||
-rwxr-xr-x | lib/widgets/ephy-editable-toolbar.c | 77 | ||||
-rwxr-xr-x | lib/widgets/ephy-editable-toolbar.h | 25 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.c | 54 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-sort.h | 6 |
6 files changed, 124 insertions, 54 deletions
diff --git a/lib/ephy-dnd.c b/lib/ephy-dnd.c index 99438495c..7dfd1f272 100644 --- a/lib/ephy-dnd.c +++ b/lib/ephy-dnd.c @@ -22,6 +22,12 @@ #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 }, diff --git a/lib/ephy-dnd.h b/lib/ephy-dnd.h index e888977a8..c1756713f 100644 --- a/lib/ephy-dnd.h +++ b/lib/ephy-dnd.h @@ -25,19 +25,11 @@ G_BEGIN_DECLS -#define EPHY_DND_NODE_PROPERTY 3 - /* Drag & Drop target names. */ #define EPHY_DND_URI_LIST_TYPE "text/uri-list" #define EPHY_DND_TEXT_TYPE "text/plain" #define EPHY_DND_URL_TYPE "_NETSCAPE_URL" - -/* Standard Drag & Drop types. */ -typedef enum { - EPHY_DND_URI_LIST, - EPHY_DND_TEXT, - EPHY_DND_URL -} EphyIconDndTargetType; +#define EPHY_DND_TOPIC_TYPE "ephy_topic" typedef void (* EphyDragEachSelectedItemDataGet) (const char *url, int x, int y, int w, int h, diff --git a/lib/widgets/ephy-editable-toolbar.c b/lib/widgets/ephy-editable-toolbar.c index 7307140c8..2af974a87 100755 --- a/lib/widgets/ephy-editable-toolbar.c +++ b/lib/widgets/ephy-editable-toolbar.c @@ -29,18 +29,12 @@ #include <libgnome/gnome-i18n.h> #include <string.h> -/* This is copied from gtkscrollbarwindow.c */ -#define DEFAULT_SCROLLBAR_SPACING 3 - -#define SCROLLBAR_SPACING(w) \ - (GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing >= 0 ? \ - GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing : DEFAULT_SCROLLBAR_SPACING) - static GtkTargetEntry dest_drag_types [] = { { "EPHY_TOOLBAR_BUTTON", 0, 0 }, /* FIXME generic way to add types */ - { EPHY_DND_URL_TYPE, 0, EPHY_DND_URL } + { EPHY_DND_URL_TYPE, 0, 1 }, + { EPHY_DND_TOPIC_TYPE, 0, 2 } }; static GtkTargetEntry source_drag_types [] = @@ -180,23 +174,23 @@ find_action (EphyEditableToolbar *t, const char *name) return action; } +static char * +impl_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data) +{ + return NULL; +} + static EggAction * impl_get_action (EphyEditableToolbar *etoolbar, - const char *type, const char *name) { EggAction *action; g_return_val_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar), NULL); - if (type == NULL) - { - action = find_action (etoolbar, name); - } - else - { - action = NULL; - } + action = find_action (etoolbar, name); return action; } @@ -248,10 +242,12 @@ drag_data_received_cb (GtkWidget *widget, EphyToolbarsItem *sibling; const char *type = NULL; GdkAtom target; - EggAction *action; + EggAction *action = NULL; g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar)); + LOG ("Drag data received") + toolbar = (EphyToolbarsToolbar *)g_object_get_data (G_OBJECT (widget), "toolbar_data"); if (!toolbar) @@ -273,8 +269,28 @@ drag_data_received_cb (GtkWidget *widget, { type = EPHY_DND_URL_TYPE; } + else if (target == gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE)) + { + type = EPHY_DND_TOPIC_TYPE; + } + + if (type) + { + char *name; + + name = ephy_editable_toolbar_get_action_name + (etoolbar, type, selection_data->data); + if (name != NULL) + { + action = ephy_editable_toolbar_get_action (etoolbar, name); + g_free (name); + } + } + else + { + action = ephy_editable_toolbar_get_action (etoolbar, selection_data->data); + } - action = ephy_editable_toolbar_get_action (etoolbar, type, selection_data->data); if (action) { ephy_toolbars_group_add_item (etoolbar->priv->group, parent, sibling, @@ -540,7 +556,7 @@ setup_toolbar (EphyToolbarsToolbar *toolbar, EphyEditableToolbar *etoolbar) g_object_set_data (G_OBJECT (widget), "drag_dest_set", GINT_TO_POINTER (TRUE)); gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, + dest_drag_types, 3, GDK_ACTION_MOVE | GDK_ACTION_COPY); g_signal_connect (widget, "drag_data_received", G_CALLBACK (drag_data_received_cb), @@ -587,7 +603,7 @@ setup_item (EphyToolbarsItem *item, EphyEditableToolbar *etoolbar) g_object_set_data (G_OBJECT (toolitem), "drag_dest_set", GINT_TO_POINTER (TRUE)); gtk_drag_dest_set (toolitem, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, + dest_drag_types, 3, GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect (toolitem, "drag_data_received", G_CALLBACK (drag_data_received_cb), @@ -676,7 +692,7 @@ ensure_action (EphyToolbarsItem *item, EphyEditableToolbar *t) g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (t)); g_return_if_fail (item != NULL); - ephy_editable_toolbar_get_action (t, NULL, item->action); + ephy_editable_toolbar_get_action (t, item->action); } static void @@ -774,6 +790,7 @@ ephy_editable_toolbar_class_init (EphyEditableToolbarClass *klass) object_class->get_property = ephy_editable_toolbar_get_property; klass->get_action = impl_get_action; + klass->get_action_name = impl_get_action_name; g_object_class_install_property (object_class, PROP_MENU_MERGE, @@ -1033,7 +1050,7 @@ update_editor_sheet (EphyEditableToolbar *etoolbar) gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (etoolbar->priv->scrolled_window), table); gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, - dest_drag_types, 2, GDK_ACTION_MOVE); + dest_drag_types, 3, GDK_ACTION_MOVE); g_signal_connect (table, "drag_data_received", G_CALLBACK (editor_drag_data_received_cb), etoolbar); @@ -1057,7 +1074,7 @@ update_editor_sheet (EphyEditableToolbar *etoolbar) EggAction *action; action = ephy_editable_toolbar_get_action - (etoolbar, NULL, node->action); + (etoolbar, node->action); g_return_if_fail (action != NULL); event_box = gtk_event_box_new (); @@ -1202,11 +1219,19 @@ ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, GtkWidget *window) show_editor (etoolbar); } +char * +ephy_editable_toolbar_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data) +{ + EphyEditableToolbarClass *klass = EPHY_EDITABLE_TOOLBAR_GET_CLASS (etoolbar); + return klass->get_action_name (etoolbar, drag_type, data); +} + EggAction * ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, - const char *type, const char *name) { EphyEditableToolbarClass *klass = EPHY_EDITABLE_TOOLBAR_GET_CLASS (etoolbar); - return klass->get_action (etoolbar, type, name); + return klass->get_action (etoolbar, name); } diff --git a/lib/widgets/ephy-editable-toolbar.h b/lib/widgets/ephy-editable-toolbar.h index 8c5f93932..68e6f39b5 100755 --- a/lib/widgets/ephy-editable-toolbar.h +++ b/lib/widgets/ephy-editable-toolbar.h @@ -48,21 +48,26 @@ struct EphyEditableToolbarClass { GObjectClass parent_class; - EggAction * (* get_action) (EphyEditableToolbar *etoolbar, - const char *type, - const char *name); + char * (* get_action_name) (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data); + EggAction * (* get_action) (EphyEditableToolbar *etoolbar, + const char *name); }; -GType ephy_editable_toolbar_get_type (void); +GType ephy_editable_toolbar_get_type (void); -EphyEditableToolbar *ephy_editable_toolbar_new (EggMenuMerge *merge); +EphyEditableToolbar *ephy_editable_toolbar_new (EggMenuMerge *merge); -void ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, - GtkWidget *window); +void ephy_editable_toolbar_edit (EphyEditableToolbar *etoolbar, + GtkWidget *window); -EggAction *ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, - const char *type, - const char *name); +char *ephy_editable_toolbar_get_action_name (EphyEditableToolbar *etoolbar, + const char *drag_type, + const char *data); + +EggAction *ephy_editable_toolbar_get_action (EphyEditableToolbar *etoolbar, + const char *name); G_END_DECLS diff --git a/lib/widgets/ephy-tree-model-sort.c b/lib/widgets/ephy-tree-model-sort.c index 3c2377cf0..41369afd9 100644 --- a/lib/widgets/ephy-tree-model-sort.c +++ b/lib/widgets/ephy-tree-model-sort.c @@ -26,6 +26,7 @@ #include "eggtreemultidnd.h" #include "ephy-dnd.h" #include "ephy-marshal.h" +#include "ephy-debug.h" static void ephy_tree_model_sort_class_init (EphyTreeModelSortClass *klass); static void ephy_tree_model_sort_init (EphyTreeModelSort *ma); @@ -43,6 +44,7 @@ static gboolean ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSou struct EphyTreeModelSortPrivate { char *str_list; + guint drag_property_id; }; enum @@ -119,6 +121,8 @@ static void ephy_tree_model_sort_init (EphyTreeModelSort *ma) { ma->priv = g_new0 (EphyTreeModelSortPrivate, 1); + + ma->priv->drag_property_id = -1; } static void @@ -185,6 +189,13 @@ ephy_tree_model_sort_multi_row_draggable (EggTreeMultiDragSource *drag_source, G return TRUE; } +void +ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, + guint id) +{ + ms->priv->drag_property_id = id; +} + static gboolean ephy_tree_model_sort_multi_drag_data_delete (EggTreeMultiDragSource *drag_source, GList *path_list) @@ -216,8 +227,10 @@ each_url_get_data_binder (EphyDragEachSelectedItemDataGet iteratee, if (node == NULL) return; - value = ephy_node_get_property_string (node, - EPHY_DND_NODE_PROPERTY); + value = ephy_node_get_property_string + (node, EPHY_TREE_MODEL_SORT (model)->priv->drag_property_id); + + LOG ("Data get %s", value) iteratee (value, -1, -1, -1, -1, data); } @@ -228,13 +241,40 @@ ephy_tree_model_sort_multi_drag_data_get (EggTreeMultiDragSource *drag_source, GList *path_list, guint info, GtkSelectionData *selection_data) -{ gpointer icontext[2]; +{ + EphyTreeModelSort *ms = EPHY_TREE_MODEL_SORT (drag_source); - icontext[0] = path_list; - icontext[1] = drag_source; + /* FIXME use the target type here, not property_id */ - ephy_dnd_drag_data_get (NULL, NULL, selection_data, - info, 0, &icontext, each_url_get_data_binder); + if (ms->priv->drag_property_id != -1) + { + gpointer icontext[2]; + + icontext[0] = path_list; + icontext[1] = drag_source; + + ephy_dnd_drag_data_get (NULL, NULL, selection_data, + info, 0, &icontext, each_url_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); + + /* FIXME free */ + data = g_strdup_printf ("%ld", ephy_node_get_id (node)); + + gtk_selection_data_set (selection_data, + selection_data->target, + 8, data, strlen (data)); + } return TRUE; } diff --git a/lib/widgets/ephy-tree-model-sort.h b/lib/widgets/ephy-tree-model-sort.h index f8cb9fb68..2b8b38be9 100644 --- a/lib/widgets/ephy-tree-model-sort.h +++ b/lib/widgets/ephy-tree-model-sort.h @@ -49,10 +49,12 @@ typedef struct void (*node_from_iter) (EphyTreeModelSort *model, GtkTreeIter *iter, void **node); } EphyTreeModelSortClass; -GType ephy_tree_model_sort_get_type (void); +GType ephy_tree_model_sort_get_type (void); -GtkTreeModel *ephy_tree_model_sort_new (GtkTreeModel *child_model); +GtkTreeModel *ephy_tree_model_sort_new (GtkTreeModel *child_model); +void ephy_tree_model_sort_set_drag_property (EphyTreeModelSort *ms, + guint id); G_END_DECLS |