Added ability for multiple selections from Simple Tables of Quick Views to be dropped on Clipboards
svn: r15665
This commit is contained in:
parent
2cabdbf0a3
commit
77e5629012
@ -127,6 +127,7 @@ class _DdTargets(object):
|
||||
self.PERSON_LINK = _DdType(self, 'person-link')
|
||||
self.LINK_LIST = _DdType(self, 'link-list')
|
||||
self.RAW_LIST = _DdType(self, 'raw-list')
|
||||
self.HANDLE_LIST = _DdType(self, 'handle-list')
|
||||
self.PERSONREF = _DdType(self, 'personref')
|
||||
self.SOURCEREF = _DdType(self, 'srcref')
|
||||
self.SOURCE_LINK = _DdType(self, 'source-link')
|
||||
@ -149,6 +150,7 @@ class _DdTargets(object):
|
||||
self.PERSON_LINK,
|
||||
self.LINK_LIST,
|
||||
self.RAW_LIST,
|
||||
self.HANDLE_LIST,
|
||||
self.PERSONREF,
|
||||
self.REPO_LINK,
|
||||
self.REPOREF,
|
||||
|
@ -920,6 +920,26 @@ class ScratchDropList(object):
|
||||
'note-link': ScratchPadNote,
|
||||
}[target]
|
||||
|
||||
def obj2class(self, target):
|
||||
return {"Person": ScratchPersonLink,
|
||||
'Source': ScratchSourceLink,
|
||||
'Repository': ScratchRepositoryLink,
|
||||
'Event': ScratchPadEvent,
|
||||
'Media': ScratchMediaObj,
|
||||
'Place': ScratchPadPlace,
|
||||
'Note': ScratchPadNote,
|
||||
}[target]
|
||||
|
||||
def obj2target(self, target):
|
||||
return {"Person": 'person-link',
|
||||
'Source': 'source-link',
|
||||
'Repository': 'repo-link',
|
||||
'Event': 'pevent',
|
||||
'Media': 'mediaobj',
|
||||
'Place': 'place-link',
|
||||
'Note': 'note-link',
|
||||
}[target]
|
||||
|
||||
def get_objects(self):
|
||||
list_type, id, handles, timestamp = self._obj_list
|
||||
retval = []
|
||||
@ -947,7 +967,30 @@ class ScratchDropRawList(ScratchDropList):
|
||||
retval.append(obj)
|
||||
return retval
|
||||
|
||||
# FIXME: add family, and all other object lists
|
||||
class ScratchDropHandleList(ScratchDropList):
|
||||
DROP_TARGETS = [DdTargets.HANDLE_LIST]
|
||||
DRAG_TARGET = None
|
||||
|
||||
def __init__(self, dbstate, obj_list):
|
||||
self._dbstate = dbstate
|
||||
# incoming:
|
||||
# ('handle-list', id, (('Person', '2763526751235'),
|
||||
# ('Source', '3786234743978'), ...), 0)
|
||||
self._obj_list = pickle.loads(obj_list)
|
||||
|
||||
def get_objects(self):
|
||||
retval = []
|
||||
for (objclass, handle) in self._obj_list:
|
||||
_class = self.obj2class(objclass)
|
||||
target = self.obj2target(objclass)
|
||||
# outgoing:
|
||||
# (drag_type, idval, self._handle, val) = pickle.loads(self._obj)
|
||||
data = (target, id(self), handle, 0)
|
||||
obj = _class(self._dbstate, pickle.dumps(data))
|
||||
retval.append(obj)
|
||||
return retval
|
||||
|
||||
# FIXME: add family
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -1023,9 +1066,8 @@ class ScratchPadListView(object):
|
||||
self._col3.set_cell_data_func(self._col3_cell, self.object_value)
|
||||
|
||||
# Set the column that inline searching will use.
|
||||
# The search does not appear to work properly so I am disabling it for now.
|
||||
self._widget.set_enable_search(False)
|
||||
#self._widget.set_search_column(1)
|
||||
self._widget.set_enable_search(True)
|
||||
#self._widget.set_search_column(3)
|
||||
|
||||
self._widget.drag_dest_set(gtk.DEST_DEFAULT_ALL,
|
||||
(ScratchPadListView.LOCAL_DRAG_TARGET,) + \
|
||||
@ -1141,6 +1183,7 @@ class ScratchPadListView(object):
|
||||
self.register_wrapper_class(ScratchPersonLink)
|
||||
self.register_wrapper_class(ScratchDropList)
|
||||
self.register_wrapper_class(ScratchDropRawList)
|
||||
self.register_wrapper_class(ScratchDropHandleList)
|
||||
self.register_wrapper_class(ScratchPadPersonRef)
|
||||
self.register_wrapper_class(ScratchPadText)
|
||||
self.register_wrapper_class(ScratchPadNote)
|
||||
@ -1184,7 +1227,8 @@ class ScratchPadListView(object):
|
||||
o = model.get_value(node,1)
|
||||
targets += [target.target() for target in o.__class__.DROP_TARGETS]
|
||||
|
||||
self._widget.enable_model_drag_source(BUTTON1_MASK, targets, ACTION_COPY | ACTION_MOVE)
|
||||
self._widget.enable_model_drag_source(BUTTON1_MASK, targets,
|
||||
ACTION_COPY | ACTION_MOVE)
|
||||
|
||||
def object_drag_begin(self, context, a):
|
||||
""" Handle the beginning of a drag operation. """
|
||||
|
@ -26,6 +26,7 @@ Provide a simplified table creation interface
|
||||
import cgi
|
||||
import copy
|
||||
from gen.ggettext import gettext as _
|
||||
import cPickle as pickle
|
||||
|
||||
import gen.lib
|
||||
import Errors
|
||||
@ -91,7 +92,9 @@ class SimpleTable(object):
|
||||
button_code = 3
|
||||
event_time = 0
|
||||
selection = treeview.get_selection()
|
||||
store, node = selection.get_selected()
|
||||
store, paths = selection.get_selected_rows()
|
||||
tpath = paths[0] if len(paths) > 0 else None
|
||||
node = store.get_iter(tpath)
|
||||
if node:
|
||||
treeview.grab_focus()
|
||||
index = store.get_value(node, 0)
|
||||
@ -111,7 +114,9 @@ class SimpleTable(object):
|
||||
if path_info is not None:
|
||||
path, col, cellx, celly = path_info
|
||||
selection = treeview.get_selection()
|
||||
store, node = selection.get_selected()
|
||||
store, paths = selection.get_selected_rows()
|
||||
tpath = paths[0] if len(paths) > 0 else None
|
||||
node = store.get_iter(tpath)
|
||||
if path:
|
||||
treeview.grab_focus()
|
||||
treeview.set_cursor(path, col, 0)
|
||||
@ -171,7 +176,9 @@ class SimpleTable(object):
|
||||
from gui.editors import (EditPerson, EditEvent, EditFamily, EditSource,
|
||||
EditPlace, EditRepository, EditNote, EditMedia)
|
||||
selection = obj.get_selection()
|
||||
store, node = selection.get_selected()
|
||||
store, paths = selection.get_selected_rows()
|
||||
tpath = paths[0] if len(paths) > 0 else None
|
||||
node = store.get_iter(tpath)
|
||||
if not node:
|
||||
return
|
||||
index = store.get_value(node, 0) # index
|
||||
@ -272,7 +279,9 @@ class SimpleTable(object):
|
||||
Handle events on tables. obj is a treeview
|
||||
"""
|
||||
selection = obj.get_selection()
|
||||
store, node = selection.get_selected()
|
||||
store, paths = selection.get_selected_rows()
|
||||
tpath = paths[0] if len(paths) > 0 else None
|
||||
node = store.get_iter(tpath)
|
||||
if not node:
|
||||
return
|
||||
index = store.get_value(node, 0) # index
|
||||
@ -462,6 +471,8 @@ class SimpleTable(object):
|
||||
doc.end_paragraph()
|
||||
elif self.simpledoc.doc.type == "gtk":
|
||||
import gtk
|
||||
from ScratchPad import ScratchPadListView, ACTION_COPY
|
||||
from DdTargets import DdTargets
|
||||
buffer = self.simpledoc.doc.buffer
|
||||
text_view = self.simpledoc.doc.text_view
|
||||
model_index = 1 # start after index
|
||||
@ -470,6 +481,12 @@ class SimpleTable(object):
|
||||
else:
|
||||
sort_index = 0
|
||||
treeview = gtk.TreeView()
|
||||
treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
|
||||
[(DdTargets.HANDLE_LIST.drag_type, gtk.TARGET_SAME_WIDGET, 0)],
|
||||
gtk.gdk.ACTION_COPY)
|
||||
#treeview.enable_model_drag_dest(DdTargets.all_targets(),
|
||||
# gtk.gdk.ACTION_DEFAULT)
|
||||
treeview.connect('drag_data_get', self.object_drag_data_get)
|
||||
treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
|
||||
#treeview.connect('row-activated', on_table_doubleclick, self)
|
||||
#treeview.connect('cursor-changed', on_table_click, self)
|
||||
@ -514,6 +531,7 @@ class SimpleTable(object):
|
||||
types += sort_data_types
|
||||
model = gtk.ListStore(*types)
|
||||
treeview.set_model(model)
|
||||
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
||||
iter = buffer.get_end_iter()
|
||||
anchor = buffer.create_child_anchor(iter)
|
||||
text_view.add_child_at_anchor(treeview, anchor)
|
||||
@ -534,6 +552,18 @@ class SimpleTable(object):
|
||||
self.simpledoc.paragraph("")
|
||||
self.simpledoc.paragraph("")
|
||||
|
||||
def object_drag_data_get(self, widget, context, sel_data, info, time):
|
||||
tree_selection = widget.get_selection()
|
||||
model, paths = tree_selection.get_selected_rows()
|
||||
retval = []
|
||||
for path in paths:
|
||||
node = model.get_iter(path)
|
||||
index = model.get_value(node,0)
|
||||
if (index is not None and self.__link[index]):
|
||||
retval.append(self.__link[index])
|
||||
sel_data.set(sel_data.target, 8, pickle.dumps(retval))
|
||||
return True
|
||||
|
||||
def get_cell_markup(self, x, y=None, data=None):
|
||||
"""
|
||||
See if a column has formatting (if x and y are supplied) or
|
||||
|
Loading…
Reference in New Issue
Block a user