Refactored copy/paste to PageView for general use

svn: r15788
This commit is contained in:
Doug Blank 2010-08-21 23:10:49 +00:00
parent db6f649969
commit 8e3aad341b
2 changed files with 70 additions and 55 deletions

View File

@ -504,70 +504,20 @@ class NavigationView(PageView):
event.state == gtk.gdk.CONTROL_MASK | gtk.gdk.MOD2_MASK): event.state == gtk.gdk.CONTROL_MASK | gtk.gdk.MOD2_MASK):
self.call_copy() self.call_copy()
return True return True
elif (event.keyval == gtk.keysyms.v and return super(NavigationView, self).key_press_handler(widget, event)
event.state == gtk.gdk.CONTROL_MASK | gtk.gdk.MOD2_MASK):
self.call_paste()
return True
return False
def call_copy(self): def call_copy(self):
""" """
This code is called on Control+C in a navigation view. If the Navigation specific copy (control+c) hander. If the
copy can be handled, it returns true, otherwise false. copy can be handled, it returns true, otherwise false.
The code brings up the Clipboard (if already exists) or The code brings up the Clipboard (if already exists) or
creates it. The copy is handled through the drag and drop creates it. The copy is handled through the drag and drop
system. system.
""" """
import cPickle as pickle nav_type = self.navigation_type()
from ScratchPad import ScratchPadWindow, obj2target handles = self.selected_handles()
nav_type, nav_group = self.navigation_type(), self.navigation_group() return self.copy_to_clipboard(nav_type, handles)
active_handle = self.uistate.get_active(nav_type, nav_group)
handled = False
for active_handle in self.selected_handles():
clipboard = None
for widget in self.uistate.gwm.window_tree:
if isinstance(widget, ScratchPadWindow):
clipboard = widget
if clipboard is None:
clipboard = ScratchPadWindow(self.dbstate, self.uistate)
# Construct a drop:
drag_type = obj2target(nav_type)
if drag_type:
class Selection(object):
def __init__(self, data):
self.data = data
class Context(object):
targets = [drag_type]
action = 1
# eg: ('person-link', 23767, '27365123671', 0)
data = (drag_type, id(self), active_handle, 0)
clipboard.object_list.object_drag_data_received(
clipboard.object_list._widget, # widget
Context(), # drag type and action
0, 0, # x, y
Selection(pickle.dumps(data)), # pickled data
None, # info (not used)
-1) # time
handled = True
return handled
def call_paste(self):
"""
This code is called on Control+V in a navigation view. If the
copy can be handled, it returns true, otherwise false.
The code creates the Clipboard if it does not already exist.
"""
from ScratchPad import ScratchPadWindow, obj2target
clipboard = None
for widget in self.uistate.gwm.window_tree:
if isinstance(widget, ScratchPadWindow):
clipboard = widget
if clipboard is None:
clipboard = ScratchPadWindow(self.dbstate, self.uistate)
return True
return False
def make_callback(func, handle): def make_callback(func, handle):
""" """

View File

@ -129,6 +129,71 @@ class PageView(DbGUIElement):
special control characters, like control+c (copy) or control+v special control characters, like control+c (copy) or control+v
(paste). (paste).
""" """
if self.active:
if event.type == gtk.gdk.KEY_PRESS:
if (event.keyval == gtk.keysyms.v and
event.state == gtk.gdk.CONTROL_MASK | gtk.gdk.MOD2_MASK):
self.call_paste()
return True
return False
def copy_to_clipboard(self, objclass, handles):
"""
This code is called on Control+C in a navigation view. If the
copy can be handled, it returns true, otherwise false.
The code brings up the Clipboard (if already exists) or
creates it. The copy is handled through the drag and drop
system.
"""
import cPickle as pickle
from ScratchPad import ScratchPadWindow, obj2target
handled = False
for handle in handles:
if handle is None:
continue
clipboard = None
for widget in self.uistate.gwm.window_tree:
if isinstance(widget, ScratchPadWindow):
clipboard = widget
if clipboard is None:
clipboard = ScratchPadWindow(self.dbstate, self.uistate)
# Construct a drop:
drag_type = obj2target(objclass)
if drag_type:
class Selection(object):
def __init__(self, data):
self.data = data
class Context(object):
targets = [drag_type]
action = 1
# eg: ('person-link', 23767, '27365123671', 0)
data = (drag_type, id(self), handle, 0)
clipboard.object_list.object_drag_data_received(
clipboard.object_list._widget, # widget
Context(), # drag type and action
0, 0, # x, y
Selection(pickle.dumps(data)), # pickled data
None, # info (not used)
-1) # time
handled = True
return handled
def call_paste(self):
"""
This code is called on Control+V in a navigation view. If the
copy can be handled, it returns true, otherwise false.
The code creates the Clipboard if it does not already exist.
"""
from ScratchPad import ScratchPadWindow, obj2target
clipboard = None
for widget in self.uistate.gwm.window_tree:
if isinstance(widget, ScratchPadWindow):
clipboard = widget
if clipboard is None:
clipboard = ScratchPadWindow(self.dbstate, self.uistate)
return True
return False return False
def call_function(self, key): def call_function(self, key):