Hi again,

one more small patch on the way, this time it's taken from bug
tracker, wish #15353 - I found myself trying to do same thing when
wanted to build "favourites" brushes and wondered why it wasn't
working - soon to find that it wasn't meant to in current version :)

About behaviour - it is quite obvious, dragging brush to group label
that do not have given brush adds it at end of list - in case brush is
there already it's removed from source group (to make it similar to
behaviour when dragging between groups list).

Implementation is mostly based on what is already there, I wasn't sure
about checking if drop event comes from BrushList the way I did this
in this patch (isinstance), but it might get messy if someone would
drag something from something else that uses PixbufList (if there is
or is planned anything that do) - this check there might require some
tweaks so I'm open for hints how you solve such situation so I can
move along same style

cheers,
Andrzej.
From ce97e88bd3b59a0d1d0aee1887eb4d2385d10022 Mon Sep 17 00:00:00 2001
From: Andrzej Giniewicz <[email protected]>
Date: Sat, 15 May 2010 16:15:34 +0200
Subject: [PATCH] brushdialog: Dragging brushes onto group labels

Simple implementation of wish #15353, dragging brush to group label that do not
have given brush adds it at end of list, in case brush is there already it's
removed from source group (to make it similar to behaviour when dragging between
groups list).
---
 gui/brushselectionwindow.py |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/gui/brushselectionwindow.py b/gui/brushselectionwindow.py
index f05436f..9c342f9 100644
--- a/gui/brushselectionwindow.py
+++ b/gui/brushselectionwindow.py
@@ -149,6 +149,12 @@ class GroupSelector(gtk.DrawingArea):
         self.bm = app.brushmanager
         self.bm.groups_observers.append(self.active_groups_changed_cb)
 
+        self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
+                [('LIST_ITEM', gtk.TARGET_SAME_APP, pixbuflist.DRAG_ITEM_NAME)],
+                gdk.ACTION_COPY)
+        self.connect('drag-motion', self.drag_motion_cb)
+        self.connect('drag-data-received', self.drag_data_received_cb)
+
         self.connect("expose-event", self.expose_cb)
         self.connect("button-press-event", self.button_press_cb)
         self.connect("motion-notify-event", self.motion_notify_cb)
@@ -325,3 +331,28 @@ class GroupSelector(gtk.DrawingArea):
             self.bm.delete_group(group)
             if group in self.bm.groups:
                 dialogs.error(self, _('This group can not be deleted (try to make it empty first).'))
+
+    def drag_data_received_cb(self, widget, context, x, y, selection, targetType, time):
+        group = self.group_at(x,y)
+        source = context.get_source_widget()
+        # ensure, that drop comes from BrushList and targets some group
+        if not group or not isinstance(source, BrushList):
+            context.finish(False, False, time)
+            return
+        target = self.bm.groups[group]
+        brush = self.bm.get_brush_by_name(selection.data)
+        if brush in target:
+            source.brushes.remove(brush)
+            changed = source.brushes
+        else:
+            target.append(brush)
+            changed = target
+        for f in self.bm.brushes_observers: f(changed)
+        context.finish(True, False, time)
+
+    def drag_motion_cb(self, widget, context, x, y, time):
+        context.drag_status(gdk.ACTION_COPY, time)
+        old_prelight_group = self.gtkstate_prelight_group
+        self.gtkstate_prelight_group = self.group_at(x,y)
+        if self.gtkstate_prelight_group != old_prelight_group:
+            self.queue_draw()
-- 
1.7.1

_______________________________________________
Mypaint-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/mypaint-discuss

Reply via email to