Merge pull request #696 from prculley/dnd2

This commit is contained in:
Nick Hall 2019-01-14 19:23:11 +00:00
commit 455cd151b7
15 changed files with 79 additions and 196 deletions

View File

@ -890,8 +890,8 @@ class ClipboardListModel(Gtk.ListStore):
class ClipboardListView:
LOCAL_DRAG_TYPE = 'MY_TREE_MODEL_ROW'
LOCAL_DRAG_ATOM_TYPE = Gdk.atom_intern(LOCAL_DRAG_TYPE, False)
LOCAL_DRAG_TARGET = (LOCAL_DRAG_ATOM_TYPE, Gtk.TargetFlags.SAME_WIDGET, 0)
LOCAL_DRAG_TARGET = Gtk.TargetEntry.new(LOCAL_DRAG_TYPE,
Gtk.TargetFlags.SAME_WIDGET, 0)
def __init__(self, dbstate, widget):
@ -948,19 +948,10 @@ class ClipboardListView:
self._widget.set_enable_search(True)
#self._widget.set_search_column(3)
targ_data = DdTargets.all_dtype()
tglist = Gtk.TargetList.new([])
tglist.add(ClipboardListView.LOCAL_DRAG_TARGET[0],
ClipboardListView.LOCAL_DRAG_TARGET[1],
ClipboardListView.LOCAL_DRAG_TARGET[2])
for _tg in targ_data:
tglist.add(_tg.atom_drag_type, _tg.target_flags, _tg.app_id)
self._widget.enable_model_drag_dest([], Gdk.DragAction.COPY)
#TODO GTK3: workaround here for bug
# https://bugzilla.gnome.org/show_bug.cgi?id=680638
self._widget.drag_dest_set_target_list(tglist)
#self._widget.drag_dest_set(Gtk.DestDefaults.ALL, targ_data,
# Gdk.DragAction.COPY)
targ_data = ((ClipboardListView.LOCAL_DRAG_TARGET,) +
DdTargets.all_targets())
self._widget.drag_dest_set(Gtk.DestDefaults.ALL, targ_data,
Gdk.DragAction.COPY)
self._widget.connect('drag-data-get', self.object_drag_data_get)
self._widget.connect('drag-begin', self.object_drag_begin)
@ -1129,8 +1120,7 @@ class ClipboardListView:
tree_selection = self._widget.get_selection()
model, paths = tree_selection.get_selected_rows()
if len(paths) > 1:
targets = [(DdTargets.RAW_LIST.atom_drag_type,
Gtk.TargetFlags.SAME_WIDGET, 0),
targets = [DdTargets.RAW_LIST.target(),
ClipboardListView.LOCAL_DRAG_TARGET]
else:
targets = [ClipboardListView.LOCAL_DRAG_TARGET]
@ -1138,18 +1128,12 @@ class ClipboardListView:
node = model.get_iter(path)
if node is not None:
_ob = model.get_value(node, 1)
targets += [target.target_data_atom()
targets += [target.target()
for target in _ob.__class__.DROP_TARGETS]
#TODO GTK3: workaround here for bug
# https://bugzilla.gnome.org/show_bug.cgi?id=680638
self._widget.enable_model_drag_source(
Gdk.ModifierType.BUTTON1_MASK, [],
Gdk.ModifierType.BUTTON1_MASK, targets,
Gdk.DragAction.COPY | Gdk.DragAction.MOVE)
tglist = Gtk.TargetList.new([])
for _tg in targets:
tglist.add(_tg[0], _tg[1], _tg[2])
self._widget.drag_source_set_target_list(tglist)
def object_drag_begin(self, widget, drag_context):
""" Handle the beginning of a drag operation. """
@ -1190,9 +1174,6 @@ class ClipboardListView:
def object_drag_data_get(self, widget, context, sel_data, info, time):
tree_selection = widget.get_selection()
model, paths = tree_selection.get_selected_rows()
if hasattr(context, "targets"):
tgs = context.targets
else:
tgs = context.list_targets()
if len(paths) == 1:
path = paths[0]
@ -1214,10 +1195,7 @@ class ClipboardListView:
time, title=None, value=None, dbid=None,
dbname=None):
model = widget.get_model()
if hasattr(selection, "data"):
sel_data = selection.data
else:
sel_data = selection.get_data() # GtkSelectionData
sel_data = selection.get_data()
# In Windows time is always zero. Until that is fixed, use the seconds
# of the local time to filter out double drops.
real_time = strftime("%S")
@ -1247,9 +1225,6 @@ class ClipboardListView:
dragtype = DdTargets.TEXT.drag_type
if dragtype in self._target_type_to_wrapper_class_map:
possible_wrappers = [dragtype]
else:
if hasattr(context, "targets"):
tgs = context.targets
else:
tgs = [atm.name() for atm in context.list_targets()]
possible_wrappers = [
@ -1293,9 +1268,8 @@ class ClipboardListView:
data = [_ob.__class__.DRAG_TARGET.drag_type, _ob, None,
_ob._type, _ob._value, _ob._dbid, _ob._dbname]
contains = model_contains(model, data)
if (contains and not
((context.action if hasattr(context, "action") else
context.get_actions()) & Gdk.DragAction.MOVE)):
if(contains and not
(context.get_actions() & Gdk.DragAction.MOVE)):
continue
drop_info = widget.get_dest_row_at_pos(x, y)
if drop_info:
@ -1313,8 +1287,7 @@ class ClipboardListView:
# FIXME: there is one bug here: if you multi-select and drop
# on self, then it moves the first, and copies the rest.
if ((context.action if hasattr(context, "action") else
context.get_actions()) & Gdk.DragAction.MOVE):
if context.get_actions() & Gdk.DragAction.MOVE:
context.finish(True, True, time)
# remember time for double drop workaround.

View File

@ -216,11 +216,9 @@ class DbManager(CLIDbManager, ManagedWindow):
Connects the signals to the buttons on the interface.
"""
ddtarget = DdTargets.URI_LIST
self.top.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(ddtarget.atom_drag_type, ddtarget.target_flags,
ddtarget.app_id)
self.top.drag_dest_set_target_list(tglist)
self.top.drag_dest_set(Gtk.DestDefaults.ALL,
[DdTargets.URI_LIST.target()],
Gdk.DragAction.COPY)
self.remove_btn.connect('clicked', self.__remove_db)
self.new_btn.connect('clicked', self.__new_db)

View File

@ -192,23 +192,15 @@ class EmbeddedList(ButtonTab):
"""
if self._DND_EXTRA:
dnd_types = [self._DND_TYPE,
self._DND_EXTRA]
dnd_types = [self._DND_TYPE.target(),
self._DND_EXTRA.target()]
else:
dnd_types = [self._DND_TYPE]
dnd_types = [self._DND_TYPE.target()]
#TODO GTK3: wourkaround here for bug https://bugzilla.gnome.org/show_bug.cgi?id=680638
self.tree.enable_model_drag_dest([], Gdk.DragAction.COPY)
self.tree.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [],
self.tree.enable_model_drag_dest(dnd_types, Gdk.DragAction.COPY)
self.tree.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[self._DND_TYPE.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
for tg in dnd_types:
tglist.add(tg.atom_drag_type, tg.target_flags, tg.app_id)
self.tree.drag_dest_set_target_list(tglist)
tglist = Gtk.TargetList.new([])
tglist.add(self._DND_TYPE.atom_drag_type, self._DND_TYPE.target_flags,
self._DND_TYPE.app_id)
self.tree.drag_source_set_target_list(tglist)
self.tree.connect('drag_data_get', self.drag_data_get)
self.tree.connect_after('drag-begin', self.after_drag_begin)

View File

@ -404,22 +404,14 @@ class GalleryTab(ButtonTab, DbGUIElement):
variable defined that points to an entry in DdTargets.
"""
dnd_types = [ self._DND_TYPE, self._DND_EXTRA, DdTargets.MEDIAOBJ]
dnd_types = [self._DND_TYPE.target(), self._DND_EXTRA.target(),
DdTargets.MEDIAOBJ.target()]
#TODO GTK3: wourkaround here for bug https://bugzilla.gnome.org/show_bug.cgi?id=680638
self.iconlist.enable_model_drag_dest([],
Gdk.DragAction.MOVE|Gdk.DragAction.COPY)
self.iconlist.enable_model_drag_dest(
dnd_types, Gdk.DragAction.MOVE | Gdk.DragAction.COPY)
self.iconlist.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[],
[self._DND_TYPE.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
for tg in dnd_types:
tglist.add(tg.atom_drag_type, tg.target_flags, tg.app_id)
self.iconlist.drag_dest_set_target_list(tglist)
tglist = Gtk.TargetList.new([])
tglist.add(self._DND_TYPE.atom_drag_type, self._DND_TYPE.target_flags,
self._DND_TYPE.app_id)
self.iconlist.drag_source_set_target_list(tglist)
self.iconlist.connect('drag_data_get', self.drag_data_get)
if not self.dbstate.db.readonly:
self.iconlist.connect('drag_data_received', self.drag_data_received)

View File

@ -107,13 +107,8 @@ class EditChildRef(EditSecondary):
# Set the drag action from the label
self.label_event_box = self.top.get_object('name_event_box')
self.label_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
self.label_event_box.drag_source_set_target_list(tglist)
self.label_event_box.drag_source_set_icon_name('gramps-person')
self.label_event_box.connect('drag_data_get', self.drag_data_get)

View File

@ -563,12 +563,8 @@ class EditFamily(EditPrimary):
self.set_contexteventbox(self.top.get_object("eventboxtop"))
#allow for drag of the family object from eventboxtop
self.contexteventbox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.FAMILY_LINK.atom_drag_type,
DdTargets.FAMILY_LINK.target_flags,
DdTargets.FAMILY_LINK.app_id)
self.contexteventbox.drag_source_set_target_list(tglist)
[DdTargets.FAMILY_LINK.target()],
Gdk.DragAction.COPY)
self.contexteventbox.drag_source_set_icon_name('gramps-family')
self.contexteventbox.connect('drag_data_get', self.on_drag_data_get_family)
@ -585,13 +581,8 @@ class EditFamily(EditPrimary):
# Allow drag
if not event_box.drag_source_get_target_list():
event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
event_box.drag_source_set_target_list(tglist)
event_box.drag_source_set_icon_name('gramps-person')
event_box.connect('drag_data_get', on_drag_data_get)
#Disallow drop:
@ -605,13 +596,8 @@ class EditFamily(EditPrimary):
if not event_box.drag_dest_get_target_list():
event_box.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.DROP,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
event_box.drag_dest_set_target_list(tglist)
event_box.connect('drag_data_received', on_drag_data_received)
def on_drag_fatherdata_get(self, widget, context, sel_data, info, time):

View File

@ -252,14 +252,9 @@ class EditPerson(EditPrimary):
# allow to initiate a drag-and-drop with this person if it has a handle
if self.added:
return # Avoid HandleError if dragging an objet not in db yet
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
self.contexteventbox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
self.contexteventbox.drag_source_set_target_list(tglist)
self.contexteventbox.drag_source_set_icon_name('gramps-person')
self.contexteventbox.connect('drag_data_get', self._top_drag_data_get)

View File

@ -98,13 +98,8 @@ class EditPersonRef(EditSecondary):
#allow for drop:
self.person_label.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.DROP,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
self.person_label.drag_dest_set_target_list(tglist)
self.person_label.connect('drag_data_received', self.on_drag_persondata_received)
self._update_dnd_capability()
@ -112,13 +107,9 @@ class EditPersonRef(EditSecondary):
self.label_event_box = self.top.get_object('person_event_box')
# Set the drag action from the label
if self.obj.ref:
self.label_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
self.label_event_box.drag_source_set_target_list(tglist)
self.label_event_box.drag_source_set(
Gdk.ModifierType.BUTTON1_MASK,
[DdTargets.PERSON_LINK.target()], Gdk.DragAction.COPY)
self.label_event_box.drag_source_set_icon_name('gramps-person')
self.label_event_box.connect('drag_data_get', self.drag_data_get)
else:

View File

@ -148,27 +148,24 @@ class ObjEntry:
Drop is always allowed
Drag only allowed when object is set
"""
if self._DND_TYPE:
if not self._DND_TYPE:
return
if not self.label.drag_dest_get_target_list():
self.label.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(self._DND_TYPE.atom_drag_type, self._DND_TYPE.target_flags,
self._DND_TYPE.app_id)
self.label.drag_dest_set_target_list(tglist)
self.label.drag_dest_set(Gtk.DestDefaults.ALL,
[self._DND_TYPE.target()],
Gdk.DragAction.COPY)
self.label.connect('drag_data_received', self.drag_data_received)
# Set the drag action from this box
if self._DND_TYPE:
if self.get_val():
if not self.label.drag_source_get_target_list():
self.label_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(self._DND_TYPE.atom_drag_type, self._DND_TYPE.target_flags,
self._DND_TYPE.app_id)
self.label_event_box.drag_source_set_target_list(tglist)
self.label_event_box.drag_source_set(
Gdk.ModifierType.BUTTON1_MASK,
[self._DND_TYPE.target()], Gdk.DragAction.COPY)
if self._DND_ICON:
self.label_event_box.drag_source_set_icon_name(self._DND_ICON)
self.label_event_box.connect('drag_data_get', self.drag_data_get)
self.label_event_box.drag_source_set_icon_name(
self._DND_ICON)
self.label_event_box.connect('drag_data_get',
self.drag_data_get)
else:
if self.label.drag_source_get_target_list():
self.label_event_box.drag_source_unset()

View File

@ -352,12 +352,8 @@ class QuickTable(SimpleTable):
sort_index = 0
treeview = MultiTreeView()
treeview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[],
[DdTargets.HANDLE_LIST.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.HANDLE_LIST.atom_drag_type, Gtk.TargetFlags.SAME_WIDGET,
0)
treeview.drag_source_set_target_list(tglist)
#treeview.enable_model_drag_dest(DdTargets.all_targets(),
# Gdk.DragAction.DEFAULT)
treeview.connect('drag_data_get', self.object_drag_data_get)

View File

@ -172,11 +172,6 @@ class ListView(NavigationView):
[self.drag_dest_info().target()],
Gdk.DragAction.MOVE |
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(self.drag_dest_info().atom_drag_type,
self.drag_dest_info().target_flags,
self.drag_dest_info().app_id)
self.list.drag_dest_set_target_list(tglist)
scrollwindow = Gtk.ScrolledWindow()
scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
@ -729,23 +724,13 @@ class ListView(NavigationView):
if len(selected_ids) == 1:
if self.drag_info():
self.list.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[self.drag_info().target()],
Gdk.DragAction.COPY)
#TODO GTK3: wourkaround here for bug https://bugzilla.gnome.org/show_bug.cgi?id=680638
tglist = Gtk.TargetList.new([])
dtype = self.drag_info()
tglist.add(dtype.atom_drag_type, dtype.target_flags, dtype.app_id)
self.list.drag_source_set_target_list(tglist)
elif len(selected_ids) > 1:
if self.drag_list_info():
self.list.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[self.drag_list_info().target()],
Gdk.DragAction.COPY)
#TODO GTK3: wourkaround here for bug https://bugzilla.gnome.org/show_bug.cgi?id=680638
tglist = Gtk.TargetList.new([])
dtype = self.drag_list_info()
tglist.add(dtype.atom_drag_type, dtype.target_flags, dtype.app_id)
self.list.drag_source_set_target_list(tglist)
self.uistate.modify_statusbar(self.dbstate)

View File

@ -276,7 +276,7 @@ class PageView(DbGUIElement, metaclass=ABCMeta):
def get_data(self):
return self.data
class Context:
targets = [drag_type.name()]
targets = [Gdk.atom_intern(drag_type.name(), False)]
action = 1
def list_targets(self):
return Context.targets

View File

@ -162,13 +162,8 @@ class FanChartBaseWidget(Gtk.DrawingArea):
# Enable drop
self.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.DROP,
[],
[DdTargets.PERSON_LINK.target()],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
DdTargets.PERSON_LINK.target_flags,
DdTargets.PERSON_LINK.app_id)
self.drag_dest_set_target_list(tglist)
self.connect('drag_data_received', self.on_drag_data_received)
self._mouse_click = False

View File

@ -760,7 +760,8 @@ class GridGramplet(GuiGramplet):
"""
TARGET_TYPE_FRAME = 80
LOCAL_DRAG_TYPE = 'GRAMPLET'
LOCAL_DRAG_TARGET = (Gdk.atom_intern(LOCAL_DRAG_TYPE, False), 0, TARGET_TYPE_FRAME)
LOCAL_DRAG_TARGET = Gtk.TargetEntry.new(LOCAL_DRAG_TYPE, 0,
TARGET_TYPE_FRAME)
def __init__(self, pane, dbstate, uistate, title, **kwargs):
"""
@ -806,12 +807,8 @@ class GridGramplet(GuiGramplet):
# source:
drag = self.gvproperties
drag.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[],
[GridGramplet.LOCAL_DRAG_TARGET],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tg = GridGramplet.LOCAL_DRAG_TARGET
tglist.add(tg[0], tg[1], tg[2])
drag.drag_source_set_target_list(tglist)
# default tooltip
msg = _("Drag Properties Button to move and click it for setup")
@ -1025,12 +1022,8 @@ class GrampletPane(Gtk.ScrolledWindow):
self.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.HIGHLIGHT |
Gtk.DestDefaults.DROP,
[],
[GridGramplet.LOCAL_DRAG_TARGET],
Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tg = GridGramplet.LOCAL_DRAG_TARGET
tglist.add(tg[0], tg[1], tg[2])
self.drag_dest_set_target_list(tglist)
self.connect('drag_drop', self.drop_widget)
self.eventb.connect('button-press-event', self._button_press)

View File

@ -1182,12 +1182,7 @@ class RelationshipView(NavigationView):
Register the given eventbox as a drag_source with given object_h
"""
eventbox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
[], Gdk.DragAction.COPY)
tglist = Gtk.TargetList.new([])
tglist.add(dnd_type.atom_drag_type,
dnd_type.target_flags,
dnd_type.app_id)
eventbox.drag_source_set_target_list(tglist)
[dnd_type.target()], Gdk.DragAction.COPY)
eventbox.drag_source_set_icon_name(stock_icon)
eventbox.connect('drag_data_get',
self._make_drag_data_get_func(object_h, dnd_type))