[gnome-builder] gstyle: colors in palettes can be moved or copied
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gstyle: colors in palettes can be moved or copied
- Date: Mon, 18 Jul 2016 00:22:13 +0000 (UTC)
commit 4bc6bafa95552862719ef9f9a8b4588b068a1fd4
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Jul 16 13:38:12 2016 +0200
gstyle: colors in palettes can be moved or copied
The default action in a same palette is move,
you can force a copy holding control while moving.
contrib/gstyle/gstyle-color-widget.c | 39 ++++++++++++++++++++++++++++---
contrib/gstyle/gstyle-palette-widget.c | 32 ++++++++++++++++++--------
2 files changed, 57 insertions(+), 14 deletions(-)
---
diff --git a/contrib/gstyle/gstyle-color-widget.c b/contrib/gstyle/gstyle-color-widget.c
index 2ec9deb..864dca7 100644
--- a/contrib/gstyle/gstyle-color-widget.c
+++ b/contrib/gstyle/gstyle-color-widget.c
@@ -142,6 +142,8 @@ gstyle_color_widget_drag_gesture_update (GtkGestureDrag *gesture,
gdouble start_x, start_y;
GtkAllocation allocation;
GstylePaletteWidgetDndLockFlags dnd_lock;
+ GtkWidget *container;
+ GdkDragAction drag_action;
gint button;
g_assert (GTK_IS_GESTURE (gesture));
@@ -170,9 +172,16 @@ gstyle_color_widget_drag_gesture_update (GtkGestureDrag *gesture,
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
gtk_gesture_drag_get_start_point (GTK_GESTURE_DRAG (gesture), &start_x, &start_y);
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
+
+ container = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET);
+ if (container != NULL && GSTYLE_IS_PALETTE_WIDGET (container))
+ drag_action = (GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ else
+ drag_action = GDK_ACTION_COPY;
+
context = gtk_drag_begin_with_coordinates (GTK_WIDGET (self),
self->target_list,
- GDK_ACTION_COPY,
+ drag_action,
button,
(GdkEvent*)event,
start_x, start_y);
@@ -190,6 +199,7 @@ gstyle_color_widget_on_drag_motion (GtkWidget *widget,
GstyleColorWidget *self = (GstyleColorWidget *)widget;
GstylePaletteWidgetDndLockFlags dnd_lock;
GdkAtom target;
+ GdkDragAction drag_action;
g_assert (GSTYLE_IS_COLOR_WIDGET (self));
g_assert (GDK_IS_DRAG_CONTEXT (context));
@@ -209,8 +219,13 @@ gstyle_color_widget_on_drag_motion (GtkWidget *widget,
is_in_drop_zone (self, x, y))
{
gtk_drag_highlight (widget);
- gdk_drag_status (context, GDK_ACTION_COPY, time);
- return TRUE;
+
+ drag_action = gdk_drag_context_get_actions (context);
+ if (drag_action | GDK_ACTION_COPY)
+ {
+ gdk_drag_status (context, GDK_ACTION_COPY, time);
+ return TRUE;
+ }
}
gdk_drag_status (context, 0, time);
@@ -257,6 +272,21 @@ gstyle_color_widget_on_drag_drop (GtkWidget *widget,
}
static void
+gstyle_color_widget_on_drag_data_delete (GtkWidget *widget,
+ GdkDragContext *context)
+{
+ GstyleColorWidget *self = (GstyleColorWidget *)widget;
+ GActionGroup *group;
+
+ g_assert (GSTYLE_IS_COLOR_WIDGET (self));
+ g_assert (GDK_IS_DRAG_CONTEXT (context));
+
+ group = gtk_widget_get_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu");
+ if (group != NULL)
+ g_action_group_activate_action (group, "remove", NULL);
+}
+
+static void
dnd_color_fill (GstyleColorWidget *self,
GstyleColor *src_color,
GstyleColor *dst_color)
@@ -1265,6 +1295,7 @@ gstyle_color_widget_class_init (GstyleColorWidgetClass *klass)
widget_class->drag_end = gstyle_color_widget_on_drag_end;
widget_class->drag_failed = gstyle_color_widget_on_drag_failed;
widget_class->drag_data_get = gstyle_color_widget_on_drag_data_get;
+ widget_class->drag_data_delete = gstyle_color_widget_on_drag_data_delete;
widget_class->drag_motion = gstyle_color_widget_on_drag_motion;
widget_class->drag_leave = gstyle_color_widget_on_drag_leave;
@@ -1354,7 +1385,7 @@ gstyle_color_widget_init (GstyleColorWidget *self)
self->target_list = gtk_target_list_new (dnd_targets, G_N_ELEMENTS (dnd_targets));
gtk_target_list_add_text_targets (self->target_list, 0);
- gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY);
+ gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_MOVE);
gtk_drag_dest_set_target_list (widget, self->target_list);
gtk_drag_dest_set_track_motion (GTK_WIDGET (self), TRUE);
diff --git a/contrib/gstyle/gstyle-palette-widget.c b/contrib/gstyle/gstyle-palette-widget.c
index 2ceb09d..f2b4d9b 100644
--- a/contrib/gstyle/gstyle-palette-widget.c
+++ b/contrib/gstyle/gstyle-palette-widget.c
@@ -342,23 +342,33 @@ gstyle_palette_widget_on_drag_motion (GtkWidget *widget,
{
GstylePaletteWidget *self = GSTYLE_PALETTE_WIDGET (widget);
GdkAtom target;
+ GdkDragAction drag_action;
g_assert (GSTYLE_IS_PALETTE_WIDGET (self));
g_assert (GDK_IS_DRAG_CONTEXT (context));
target = gtk_drag_dest_find_target (widget, context, NULL);
- if (target != gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET") ||
- (self->dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DROP) != 0)
+ if (target == gdk_atom_intern_static_string ("GSTYLE_COLOR_WIDGET") &&
+ (self->dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DROP) == 0)
{
- dnd_highlight_set_from_cursor (self, -1, -1);
- gdk_drag_status (context, 0, time);
- return FALSE;
+ drag_action = gdk_drag_context_get_actions (context);
+ if (drag_action & GDK_ACTION_MOVE)
+ {
+ dnd_highlight_set_from_cursor (self, x, y);
+ gdk_drag_status (context, GDK_ACTION_MOVE, time);
+ return TRUE;
+ }
+ else if (drag_action & GDK_ACTION_COPY)
+ {
+ dnd_highlight_set_from_cursor (self, x, y);
+ gdk_drag_status (context, GDK_ACTION_COPY, time);
+ return TRUE;
+ }
}
- dnd_highlight_set_from_cursor (self, x, y);
- gdk_drag_status (context, GDK_ACTION_COPY, time);
-
- return TRUE;
+ dnd_highlight_set_from_cursor (self, -1, -1);
+ gdk_drag_status (context, 0, time);
+ return FALSE;
}
static void
@@ -416,6 +426,7 @@ gstyle_palette_widget_on_drag_data_received (GtkWidget *widget,
GstylePaletteWidget *self = GSTYLE_PALETTE_WIDGET (widget);
GstyleColor **src_color;
GstyleColor *color;
+ gboolean delete;
g_assert (GSTYLE_IS_PALETTE_WIDGET (self));
g_assert (GDK_IS_DRAG_CONTEXT (context));
@@ -431,7 +442,8 @@ gstyle_palette_widget_on_drag_data_received (GtkWidget *widget,
NULL);
g_object_unref (color);
- gtk_drag_finish (context, TRUE, FALSE, time);
+ delete = (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE);
+ gtk_drag_finish (context, TRUE, delete, time);
}
else
gtk_drag_finish (context, FALSE, FALSE, time);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]