aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks
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 /src/bookmarks
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 'src/bookmarks')
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c79
-rw-r--r--src/bookmarks/ephy-node-view.c157
-rw-r--r--src/bookmarks/ephy-node-view.h11
3 files changed, 211 insertions, 36 deletions
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index a10168987..7f9a983bd 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -41,6 +41,28 @@
#include "popup-commands.h"
#include "ephy-state.h"
+static GtkTargetEntry topic_drag_dest_types [] =
+{
+ { EPHY_DND_BOOKMARK_TYPE, 0, 0 }
+};
+
+static int n_topic_drag_dest_types = G_N_ELEMENTS (topic_drag_dest_types);
+
+static GtkTargetEntry bmk_drag_types [] =
+{
+ { EPHY_DND_URI_LIST_TYPE, 0, 0 },
+ { EPHY_DND_TEXT_TYPE, 0, 1 },
+ { EPHY_DND_URL_TYPE, 0, 2 },
+ { EPHY_DND_BOOKMARK_TYPE, 0, 3 }
+};
+static int n_bmk_drag_types = G_N_ELEMENTS (bmk_drag_types);
+
+static GtkTargetEntry topic_drag_types [] =
+{
+ { EPHY_DND_TOPIC_TYPE, 0, 0 }
+};
+static int n_topic_drag_types = G_N_ELEMENTS (topic_drag_types);
+
static void ephy_bookmarks_editor_class_init (EphyBookmarksEditorClass *klass);
static void ephy_bookmarks_editor_init (EphyBookmarksEditor *editor);
static void ephy_bookmarks_editor_finalize (GObject *object);
@@ -61,7 +83,7 @@ static void cmd_open_bookmarks_in_tabs (EggAction *action,
EphyBookmarksEditor *editor);
static void cmd_open_bookmarks_in_browser (EggAction *action,
EphyBookmarksEditor *editor);
-static void cmd_delete (EggAction *action,
+static void cmd_delete (EggAction *action,
EphyBookmarksEditor *editor);
static void cmd_bookmark_properties (EggAction *action,
EphyBookmarksEditor *editor);
@@ -99,12 +121,6 @@ enum
PROP_BOOKMARKS
};
-static GtkTargetEntry topic_drag_types [] =
-{
- { EPHY_DND_TOPIC_TYPE, 0, 0 }
-};
-static int n_topic_drag_types = G_N_ELEMENTS (topic_drag_types);
-
static GObjectClass *parent_class = NULL;
static EggActionGroupEntry ephy_bookmark_popup_entries [] = {
@@ -124,7 +140,7 @@ static EggActionGroupEntry ephy_bookmark_popup_entries [] = {
{ "Cut", N_("Cu_t"), GTK_STOCK_CUT, "<control>X",
NULL, G_CALLBACK (cmd_cut), NULL },
-
+
{ "Copy", N_("_Copy"), GTK_STOCK_COPY, "<control>C",
NULL, G_CALLBACK (cmd_copy), NULL },
@@ -170,7 +186,7 @@ cmd_close (EggAction *action,
static void
cmd_rename (EggAction *action,
EphyBookmarksEditor *editor)
-{
+{
if (ephy_node_view_has_focus (editor->priv->bm_view))
{
ephy_node_view_edit (editor->priv->bm_view);
@@ -335,7 +351,7 @@ cmd_select_all (EggAction *action,
{
gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
}
- else if (ephy_node_view_has_focus (editor->priv->bm_view))
+ else if (ephy_node_view_has_focus (editor->priv->bm_view))
{
ephy_node_view_select_all (editor->priv->bm_view);
}
@@ -470,12 +486,12 @@ ephy_bookmarks_editor_show_popup_cb (GtkWidget *view,
EphyBookmarksEditor *editor)
{
GtkWidget *widget;
-
+
widget = egg_menu_merge_get_widget (editor->priv->ui_merge,
"/popups/EphyBookmarkEditorPopup");
gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, 2,
gtk_get_current_event_time ());
-}
+}
static void
ephy_bookmarks_editor_node_activated_cb (GtkWidget *view,
@@ -559,7 +575,7 @@ keyword_node_show_popup_cb (GtkWidget *view, EphyBookmarksEditor *editor)
GtkWidget *widget;
widget = egg_menu_merge_get_widget (editor->priv->ui_merge,
- "/popups/EphyBookmarkKeywordPopup");
+ "/popups/EphyBookmarkKeywordPopup");
gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, 2,
gtk_get_current_event_time ());
}
@@ -639,6 +655,22 @@ delete_event_cb (EphyBookmarksEditor *editor)
}
static void
+node_dropped_cb (EphyNodeView *view, EphyNode *node,
+ GList *nodes, EphyBookmarksEditor *editor)
+{
+ GList *l;
+
+ g_return_if_fail (EPHY_IS_NODE (node));
+
+ for (l = nodes; l != NULL; l = l->next)
+ {
+ EphyNode *bmk = EPHY_NODE (l->data);
+
+ ephy_bookmarks_set_keyword (editor->priv->bookmarks, node, bmk);
+ }
+}
+
+static void
ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
{
GtkWidget *hbox, *vbox;
@@ -692,7 +724,7 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
gtk_container_add (GTK_CONTAINER (editor->priv->menu_dock), hbox);
gtk_widget_show (hbox);
-
+
g_assert (editor->priv->bookmarks);
node = ephy_bookmarks_get_keywords (editor->priv->bookmarks);
@@ -703,6 +735,9 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
topic_drag_types,
n_topic_drag_types,
-1);
+ ephy_node_view_enable_drag_dest (key_view,
+ topic_drag_dest_types,
+ n_topic_drag_dest_types);
ephy_node_view_set_browse_mode (key_view);
ephy_node_view_add_column (key_view, _("Topics"),
EPHY_TREE_MODEL_NODE_COL_KEYWORD, TRUE, TRUE);
@@ -722,7 +757,11 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
"show_popup",
G_CALLBACK (keyword_node_show_popup_cb),
editor);
-
+ g_signal_connect (G_OBJECT (key_view),
+ "node_dropped",
+ G_CALLBACK (node_dropped_cb),
+ editor);
+
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox),
vbox, TRUE, TRUE, 0);
@@ -738,7 +777,10 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
/* Bookmarks View */
bm_view = ephy_node_view_new (node, editor->priv->bookmarks_filter);
ephy_node_view_set_hinted (bm_view, TRUE);
- ephy_node_view_enable_drag_source (bm_view, NULL, 0, EPHY_NODE_BMK_PROP_LOCATION);
+ ephy_node_view_enable_drag_source (bm_view,
+ bmk_drag_types,
+ n_bmk_drag_types,
+ EPHY_NODE_BMK_PROP_LOCATION);
ephy_node_view_add_icon_column (bm_view, EPHY_TREE_MODEL_NODE_COL_ICON);
ephy_node_view_add_column (bm_view, _("Title"),
EPHY_TREE_MODEL_NODE_COL_BOOKMARK, TRUE, TRUE);
@@ -869,10 +911,10 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor,
EggAction *action;
EggActionGroup *action_group;
GList *selection;
-
+
g_return_if_fail (editor != NULL);
g_return_if_fail (node != NULL);
-
+
priority = ephy_node_get_property_int (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
if (priority == EPHY_BOOKMARKS_KEYWORD_ALL_PRIORITY ||
@@ -897,4 +939,3 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor,
action = egg_action_group_get_action (action_group, "Delete");
g_object_set (action, "sensitive", !delete, NULL);
}
-
diff --git a/src/bookmarks/ephy-node-view.c b/src/bookmarks/ephy-node-view.c
index 382daa045..62f44b7df 100644
--- a/src/bookmarks/ephy-node-view.c
+++ b/src/bookmarks/ephy-node-view.c
@@ -32,6 +32,7 @@
#include "ephy-tree-model-sort.h"
#include "eggtreemultidnd.h"
#include "ephy-dnd.h"
+#include "ephy-marshal.h"
#include "string.h"
static void ephy_node_view_class_init (EphyNodeViewClass *klass);
@@ -62,12 +63,15 @@ struct EphyNodeViewPrivate
GtkWidget *treeview;
EphyTreeModelNodeColumn default_sort_column_id;
+
+ GtkTargetList *drag_targets;
};
enum
{
NODE_ACTIVATED,
NODE_SELECTED,
+ NODE_DROPPED,
SHOW_POPUP,
LAST_SIGNAL
};
@@ -158,6 +162,17 @@ ephy_node_view_class_init (EphyNodeViewClass *klass)
G_TYPE_NONE,
1,
EPHY_TYPE_NODE);
+ ephy_node_view_signals[NODE_DROPPED] =
+ g_signal_new ("node_dropped",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyNodeViewClass, node_dropped),
+ NULL, NULL,
+ ephy_marshal_VOID__OBJECT_POINTER,
+ G_TYPE_NONE,
+ 2,
+ EPHY_TYPE_NODE,
+ G_TYPE_POINTER);
ephy_node_view_signals[SHOW_POPUP] =
g_signal_new ("show_popup",
G_OBJECT_CLASS_TYPE (object_class),
@@ -262,7 +277,7 @@ ephy_node_view_button_press_cb (GtkTreeView *treeview,
{
GtkTreePath *path;
GtkTreeSelection *selection;
-
+
if (event->button == 3)
{
g_signal_emit (G_OBJECT (view), ephy_node_view_signals[SHOW_POPUP], 0);
@@ -673,10 +688,10 @@ ephy_node_view_has_focus (EphyNodeView *view)
{
GtkWidget *window;
GtkWidget *focused_widget;
-
+
window = gtk_widget_get_toplevel (view->priv->treeview);
focused_widget = gtk_window_get_focus (GTK_WINDOW(window));
-
+
if (view->priv->treeview == focused_widget)
{
return TRUE;
@@ -742,6 +757,127 @@ ephy_node_view_select_node (EphyNodeView *view,
gtk_tree_path_free (path);
}
+static EphyNode *
+get_node_from_path (EphyNodeView *view, GtkTreePath *path)
+{
+ EphyNode *node;
+ GtkTreeIter iter, iter2;
+
+ gtk_tree_model_get_iter (view->priv->sortmodel, &iter, path);
+ gtk_tree_model_sort_convert_iter_to_child_iter
+ (GTK_TREE_MODEL_SORT (view->priv->sortmodel), &iter2, &iter);
+ egg_tree_model_filter_convert_iter_to_child_iter
+ (EGG_TREE_MODEL_FILTER (view->priv->filtermodel), &iter, &iter2);
+ node = ephy_tree_model_node_node_from_iter (view->priv->nodemodel, &iter);
+
+ return node;
+}
+
+static gboolean
+drag_motion_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time,
+ EphyNodeView *view)
+{
+ GtkTreePath *path = NULL;
+ GtkTreeViewDropPosition pos;
+
+ g_signal_stop_emission_by_name (widget, "drag_motion");
+
+ if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
+ x, y, &path, &pos))
+ {
+ gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), path,
+ GTK_TREE_VIEW_DROP_INTO_OR_AFTER);
+ gdk_drag_status (context, context->suggested_action, time);
+ }
+}
+
+static gboolean
+drag_drop_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time,
+ EphyNodeView *view)
+{
+ GdkAtom target;
+
+ target = gtk_drag_dest_find_target (widget, context,
+ view->priv->drag_targets);
+
+ if (target != GDK_NONE)
+ {
+ gtk_drag_get_data (widget, context, target, time);
+ }
+
+ g_signal_stop_emission_by_name (widget, "drag_drop");
+
+ return TRUE;
+}
+
+static gboolean
+drag_data_received_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ EphyNodeView *view)
+{
+ GtkTreePath *path = NULL;
+ GtkTreeViewDropPosition pos;
+
+ g_signal_stop_emission_by_name (widget, "drag_data_received");
+
+ if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
+ x, y, &path, &pos))
+ {
+ EphyNode *node;
+ GList *src_nodes;
+
+ node = get_node_from_path (view, path);
+
+ src_nodes = ephy_dnd_node_list_extract_nodes
+ (selection_data->data);
+
+ g_signal_emit (G_OBJECT (view),
+ ephy_node_view_signals[NODE_DROPPED], 0,
+ node, src_nodes);
+
+ g_list_free (src_nodes);
+ }
+
+ return TRUE;
+}
+
+void
+ephy_node_view_enable_drag_dest (EphyNodeView *view,
+ GtkTargetEntry *types,
+ int n_types)
+{
+ GtkWidget *treeview;
+
+ g_return_if_fail (view != NULL);
+
+ treeview = view->priv->treeview;
+
+ gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview),
+ types, n_types,
+ GDK_ACTION_COPY);
+ view->priv->drag_targets = gtk_target_list_new (types, n_types);
+
+ g_signal_connect (treeview, "drag_data_received",
+ G_CALLBACK (drag_data_received_cb), view);
+ g_signal_connect (treeview, "drag_drop",
+ G_CALLBACK (drag_drop_cb), view);
+ g_signal_connect (treeview, "drag_motion",
+ G_CALLBACK (drag_motion_cb), view);
+}
+
void
ephy_node_view_enable_drag_source (EphyNodeView *view,
GtkTargetEntry *types,
@@ -756,17 +892,10 @@ ephy_node_view_enable_drag_source (EphyNodeView *view,
egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (treeview));
- if (types == NULL)
- {
- ephy_dnd_enable_model_drag_source (GTK_WIDGET (treeview));
- }
- else
- {
- gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview),
- GDK_BUTTON1_MASK,
- types, n_types,
- GDK_ACTION_COPY);
- }
+ gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview),
+ GDK_BUTTON1_MASK,
+ types, n_types,
+ GDK_ACTION_COPY);
ephy_tree_model_sort_set_drag_property (EPHY_TREE_MODEL_SORT (view->priv->sortmodel),
prop_id);
diff --git a/src/bookmarks/ephy-node-view.h b/src/bookmarks/ephy-node-view.h
index ee404d159..08b5757e0 100644
--- a/src/bookmarks/ephy-node-view.h
+++ b/src/bookmarks/ephy-node-view.h
@@ -49,9 +49,10 @@ typedef struct
{
GtkScrolledWindowClass parent;
- void (*node_activated) (EphyNodeView *view, EphyNode *node);
- void (*node_selected) (EphyNodeView *view, EphyNode *node);
- void (*show_popup) (EphyNodeView *view);
+ void (*node_activated) (EphyNodeView *view, EphyNode *node);
+ void (*node_selected) (EphyNodeView *view, EphyNode *node);
+ void (*node_dropped) (EphyNodeView *view, EphyNode *node, GList *nodes);
+ void (*show_popup) (EphyNodeView *view);
} EphyNodeViewClass;
GType ephy_node_view_get_type (void);
@@ -88,6 +89,10 @@ void ephy_node_view_enable_drag_source (EphyNodeView *view,
int n_types,
guint prop_id);
+void ephy_node_view_enable_drag_dest (EphyNodeView *view,
+ GtkTargetEntry *types,
+ int n_types);
+
void ephy_node_view_set_hinted (EphyNodeView *view,
gboolean hinted);