[Epiphany] toolbar removal with dnd



Marco,

Here's a patch adding the ability to remove toolbars with dnd.  Ok to
commit?

Thanks,
James

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/epiphany/ChangeLog,v
retrieving revision 1.163
diff -u -r1.163 ChangeLog
--- ChangeLog	7 Mar 2003 21:48:02 -0000	1.163
+++ ChangeLog	7 Mar 2003 22:12:05 -0000
@@ -1,3 +1,13 @@
+2003-03-07  James Willcox  <jwillcox@gnome.org>
+
+	* lib/widgets/ephy-editable-toolbar.c:
+	(toolbar_drag_data_delete_cb), (toolbar_drag_data_get_cb),
+	(connect_toolbar_drag_source), (disconnect_toolbar_drag_source),
+	(do_merge), (editor_close), (button_press_cb),
+	(ephy_editable_toolbar_edit):
+
+	Enable using dnd for removing toolbars.
+
 2003-03-07  David Bordoley <bordoley@msu.edu>
 
 	* lib/ephy-stock-icons.h:
Index: lib/widgets/ephy-editable-toolbar.c
===================================================================
RCS file: /cvs/gnome/epiphany/lib/widgets/ephy-editable-toolbar.c,v
retrieving revision 1.21
diff -u -r1.21 ephy-editable-toolbar.c
--- lib/widgets/ephy-editable-toolbar.c	7 Mar 2003 00:39:47 -0000	1.21
+++ lib/widgets/ephy-editable-toolbar.c	7 Mar 2003 22:12:06 -0000
@@ -309,6 +309,49 @@
 }
 
 static void
+toolbar_drag_data_delete_cb (GtkWidget *widget,
+			     GdkDragContext *context,
+			     EphyEditableToolbar *etoolbar)
+{
+	EphyToolbarsToolbar *t;
+
+	g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar));
+
+	t = (EphyToolbarsToolbar *)g_object_get_data (G_OBJECT (widget),
+						      "toolbar_drag_data");
+	g_return_if_fail (t != NULL);
+
+	ephy_toolbars_group_remove_toolbar (etoolbar->priv->group, t);
+
+	etoolbar->priv->toolbars_dirty = TRUE;
+	queue_ui_update (etoolbar);
+}
+
+static void
+toolbar_drag_data_get_cb (GtkWidget *widget,
+			  GdkDragContext *context,
+			  GtkSelectionData *selection_data,
+			  guint info,
+			  guint32 time,
+			  EphyEditableToolbar *etoolbar)
+{
+	EphyToolbarsToolbar *t;
+	char *target;
+
+	g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar));
+
+	t = (EphyToolbarsToolbar *)g_object_get_data (G_OBJECT (widget),
+						      "toolbar_drag_data");
+
+	target = t->id;
+	LOG ("Drag data get %s", t->id);
+
+	gtk_selection_data_set (selection_data,
+				selection_data->target,
+				8, target, strlen (target));
+}
+
+static void
 ephy_editable_toolbar_remove_cb  (EggAction *action,
 				  EphyEditableToolbar *etoolbar)
 {
@@ -390,6 +433,62 @@
 }
 
 static void
+connect_toolbar_drag_source (EphyToolbarsToolbar *t,
+			     EphyEditableToolbar *etoolbar)
+{
+	GtkWidget *tb;
+
+	g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar));
+	g_return_if_fail (t != NULL);
+
+	tb = get_item_widget (etoolbar, t);
+
+	g_return_if_fail (tb != NULL);
+
+	if (!g_object_get_data (G_OBJECT (tb), "drag_source_set"))
+	{
+		g_object_set_data (G_OBJECT (tb), "drag_source_set",
+				   GINT_TO_POINTER (TRUE));
+
+		g_object_set_data (G_OBJECT (tb), "toolbar_drag_data", t);
+
+		g_signal_connect (tb, "drag_data_get",
+				  G_CALLBACK (toolbar_drag_data_get_cb),
+				  etoolbar);
+		g_signal_connect (tb, "drag_data_delete",
+				  G_CALLBACK (toolbar_drag_data_delete_cb),
+				  etoolbar);
+	}
+}
+
+static void
+disconnect_toolbar_drag_source (EphyToolbarsToolbar *t,
+				EphyEditableToolbar *etoolbar)
+{
+	GtkWidget *tb;
+
+	g_return_if_fail (IS_EPHY_EDITABLE_TOOLBAR (etoolbar));
+	g_return_if_fail (t != NULL);
+
+	tb = get_item_widget (etoolbar, t);
+
+	g_return_if_fail (tb != NULL);
+
+	if (g_object_get_data (G_OBJECT (tb), "drag_source_set"))
+	{
+		g_object_set_data (G_OBJECT (tb), "drag_source_set",
+				   GINT_TO_POINTER (FALSE));
+
+		g_signal_handlers_disconnect_by_func (tb,
+						      G_CALLBACK (toolbar_drag_data_get_cb),
+						      etoolbar);
+		g_signal_handlers_disconnect_by_func (tb,
+						      G_CALLBACK (toolbar_drag_data_delete_cb),
+						      etoolbar);
+	}
+}
+
+static void
 popup_toolbar_context_menu (EggToolbar *toolbar, ContextMenuData *data)
 {
 	GtkWidget *widget;
@@ -542,6 +641,10 @@
 		ephy_toolbars_group_foreach_item (t->priv->group,
 						  (EphyToolbarsGroupForeachItemFunc)
 					          connect_item_drag_source, t);
+
+		ephy_toolbars_group_foreach_toolbar (t->priv->group,
+						  (EphyToolbarsGroupForeachToolbarFunc)
+					          connect_toolbar_drag_source, t);
 	}
 
 	ephy_toolbars_group_foreach_toolbar (t->priv->group,
@@ -790,6 +893,10 @@
 					  (EphyToolbarsGroupForeachItemFunc)
 				          disconnect_item_drag_source,
 					  etoolbar);
+	ephy_toolbars_group_foreach_toolbar (etoolbar->priv->group,
+					  (EphyToolbarsGroupForeachToolbarFunc)
+				          disconnect_toolbar_drag_source,
+					  etoolbar);
 	hide_editor (etoolbar);
 }
 
@@ -993,8 +1100,18 @@
 	    event->type == GDK_BUTTON_PRESS &&
 	    EGG_IS_TOOLBAR (widget))
 	{
-		gtk_widget_event (widget, event);
-		return FALSE;
+		if (event->button.button == 3)
+		{
+			gtk_widget_event (widget, event);
+			return FALSE;
+		}
+		else
+		{
+			gtk_drag_begin (widget,
+					gtk_target_list_new (source_drag_types, 1),
+					GDK_ACTION_MOVE, 1, event);
+			return TRUE;
+		}
 	}
 	else if (toolitem == NULL) return FALSE;
 
@@ -1055,6 +1172,10 @@
 	ephy_toolbars_group_foreach_item (etoolbar->priv->group,
 					  (EphyToolbarsGroupForeachItemFunc)
 				          set_action_sensitive, etoolbar);
+	ephy_toolbars_group_foreach_toolbar (etoolbar->priv->group,
+					  (EphyToolbarsGroupForeachToolbarFunc)
+				          connect_toolbar_drag_source, etoolbar);
+
 	setup_editor (etoolbar, window);
 	show_editor (etoolbar);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]