From 4032075425d7251642e3f81b9c4732e9a2a23e85 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 13 Aug 2010 08:09:37 -0400 Subject: Bug 624913 - Disallow drag-and-drop within the same attachment bar Adds a boolean "dragging" property to the EAttachmentView interface, which becomes TRUE when the user start a drag from the attachment view. e_attachment_view_drag_motion() and e_attachment_view_drag_drop() both return FALSE when this property is set. Also, do not register the entire EMsgComposer window as a drag destination. Just intercept drag signals from the GtkHTML widget. Requires gtkhtml commit 344eb5e to fully work correctly. --- widgets/misc/e-attachment-view.c | 55 ++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'widgets/misc/e-attachment-view.c') diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c index 60ce09860d..cc587bf80b 100644 --- a/widgets/misc/e-attachment-view.c +++ b/widgets/misc/e-attachment-view.c @@ -821,6 +821,15 @@ attachment_view_class_init (EAttachmentViewIface *iface) { iface->update_actions = attachment_view_update_actions; + g_object_interface_install_property ( + iface, + g_param_spec_boolean ( + "dragging", + "Dragging", + NULL, + FALSE, + G_PARAM_READWRITE)); + g_object_interface_install_property ( iface, g_param_spec_boolean ( @@ -1025,6 +1034,7 @@ e_attachment_view_set_editable (EAttachmentView *view, g_return_if_fail (E_IS_ATTACHMENT_VIEW (view)); priv = e_attachment_view_get_private (view); + priv->editable = editable; if (editable) @@ -1035,6 +1045,33 @@ e_attachment_view_set_editable (EAttachmentView *view, g_object_notify (G_OBJECT (view), "editable"); } +gboolean +e_attachment_view_get_dragging (EAttachmentView *view) +{ + EAttachmentViewPrivate *priv; + + g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), FALSE); + + priv = e_attachment_view_get_private (view); + + return priv->dragging; +} + +void +e_attachment_view_set_dragging (EAttachmentView *view, + gboolean dragging) +{ + EAttachmentViewPrivate *priv; + + g_return_if_fail (E_IS_ATTACHMENT_VIEW (view)); + + priv = e_attachment_view_get_private (view); + + priv->dragging = dragging; + + g_object_notify (G_OBJECT (view), "dragging"); +} + GtkTargetList * e_attachment_view_get_target_list (EAttachmentView *view) { @@ -1507,10 +1544,7 @@ e_attachment_view_drag_begin (EAttachmentView *view, priv = e_attachment_view_get_private (view); - /* Prevent the user from dragging and dropping to - * the same attachment view, which would duplicate - * the attachment. */ - e_attachment_view_drag_dest_unset (view); + e_attachment_view_set_dragging (view, TRUE); g_warn_if_fail (priv->selected == NULL); priv->selected = e_attachment_view_get_selected_attachments (view); @@ -1569,9 +1603,7 @@ e_attachment_view_drag_end (EAttachmentView *view, priv = e_attachment_view_get_private (view); - /* Restore the previous drag destination state. */ - if (e_attachment_view_get_editable (view)) - e_attachment_view_drag_dest_set (view); + e_attachment_view_set_dragging (view, FALSE); g_list_foreach (priv->selected, (GFunc) g_object_unref, NULL); g_list_free (priv->selected); @@ -1698,6 +1730,11 @@ e_attachment_view_drag_motion (EAttachmentView *view, if (!e_attachment_view_get_editable (view)) return FALSE; + /* Disallow drops if we initiated the drag. + * This helps prevent duplicate attachments. */ + if (e_attachment_view_get_dragging (view)) + return FALSE; + actions = gdk_drag_context_get_actions (context); actions &= priv->drag_actions; chosen_action = gdk_drag_context_get_suggested_action (context); @@ -1725,7 +1762,9 @@ e_attachment_view_drag_drop (EAttachmentView *view, g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), FALSE); g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE); - return TRUE; + /* Disallow drops if we initiated the drag. + * This helps prevent duplicate attachments. */ + return !e_attachment_view_get_dragging (view); } void -- cgit v1.2.3