dnd: simplify code

The old code did mimetype checks everywhere when type compatibility has
since been moved to the GtkDropTarget::accept signal.

So the code can now just assume a compatible mime type exists.
This commit is contained in:
Benjamin Otte 2020-02-16 18:32:42 +01:00
parent da83457a60
commit e1f8c1430f
3 changed files with 13 additions and 47 deletions

View File

@ -6229,21 +6229,14 @@ gtk_text_drag_accept (GtkDropTarget *dest,
GtkText *self)
{
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
GdkDragAction suggested_action;
if (priv->editable &&
gtk_drop_target_find_mimetype (dest) != NULL)
{
suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
}
else
{
/* Entry not editable, or no text */
suggested_action = 0;
}
if (!priv->editable)
return FALSE;
gdk_drop_status (drop, suggested_action);
return suggested_action != 0;
if ((gdk_drop_get_actions (drop) & gtk_drop_target_get_actions (dest)) == 0)
return FALSE;
return gdk_content_formats_match (gtk_drop_target_get_formats (dest), gdk_drop_get_formats (drop));
}
static void
@ -6259,8 +6252,7 @@ gtk_text_drag_motion (GtkDropTarget *dest,
old_position = priv->dnd_position;
new_position = gtk_text_find_position (self, x + priv->scroll_offset);
if (priv->editable &&
gtk_drop_target_find_mimetype (dest) != NULL)
if (priv->editable)
{
if (priv->selection_bound == priv->current_pos ||
new_position < priv->selection_bound ||

View File

@ -7781,7 +7781,6 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
GtkTextIter end;
GdkRectangle target_rect;
gint bx, by;
GdkAtom target;
gboolean can_accept = FALSE;
target_rect = priv->text_window->allocation;
@ -7801,16 +7800,10 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
&newplace,
bx, by);
target = gtk_drop_target_find_mimetype (dest);
if (target == NULL)
{
/* can't accept any of the offered targets */
}
else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
&start, &end) &&
gtk_text_iter_compare (&newplace, &start) >= 0 &&
gtk_text_iter_compare (&newplace, &end) <= 0)
if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
&start, &end) &&
gtk_text_iter_compare (&newplace, &start) >= 0 &&
gtk_text_iter_compare (&newplace, &end) <= 0)
{
/* We're inside the selection. */
}

View File

@ -213,26 +213,8 @@ item_drag_drop (GtkDropTarget *dest,
int x,
int y)
{
if (gtk_drop_target_find_mimetype (dest))
{
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
return TRUE;
}
return FALSE;
}
static gboolean
item_drag_motion (GtkDropTarget *dest,
GdkDrop *drop)
{
if (gtk_drop_target_find_mimetype (dest) != NULL)
{
gdk_drop_status (drop, GDK_ACTION_COPY);
return TRUE;
}
return FALSE;
gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
return TRUE;
}
static void
@ -307,7 +289,6 @@ canvas_item_new (int i,
formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
g_signal_connect (dest, "drag-drop", G_CALLBACK (item_drag_drop), NULL);
g_signal_connect (dest, "accept", G_CALLBACK (item_drag_motion), NULL);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
gdk_content_formats_unref (formats);