Added copy and paste to all views; gramplet view needs work

svn: r15697
This commit is contained in:
Doug Blank
2010-08-09 20:51:54 +00:00
parent 981cda7c19
commit e3cd87484c
14 changed files with 130 additions and 34 deletions

@@ -110,6 +110,10 @@ UIDEFAULT = '''<ui>
<menuitem action="Quit"/> <menuitem action="Quit"/>
</menu> </menu>
<menu action="EditMenu"> <menu action="EditMenu">
<menuitem action="Copy"/>
<menuitem action="Paste"/>
<menuitem action="Cut"/>
<separator/>
<menuitem action="Undo"/> <menuitem action="Undo"/>
<menuitem action="Redo"/> <menuitem action="Redo"/>
<menuitem action="UndoHistory"/> <menuitem action="UndoHistory"/>
@@ -509,6 +513,12 @@ class ViewManager(CLIManager):
('ConfigView', 'gramps-config', _('_Configure View...'), ('ConfigView', 'gramps-config', _('_Configure View...'),
'<shift><control>c', _('Configure the active view'), '<shift><control>c', _('Configure the active view'),
self.config_view), self.config_view),
('Copy', gtk.STOCK_COPY, _('Copy'), "<control>c",
_(""), self.__keypress),
('Paste', gtk.STOCK_PASTE, _('Paste'), "<control>v",
_(""), self.__keypress),
('Cut', gtk.STOCK_CUT, _('Cut'), "<control>x",
_(""), self.__keypress),
] ]
self._file_toggle_action_list = [ self._file_toggle_action_list = [

@@ -484,6 +484,70 @@ class NavigationView(PageView):
""" """
raise NotImplementedError raise NotImplementedError
def call_copy(self):
"""
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
nav_type, nav_group = self.navigation_type(), self.navigation_group()
active_handle = self.uistate.get_active(nav_type, nav_group)
if active_handle:
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
return True
return False
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 call_cut(self):
"""
This method would be great to move items between databases.
"""
return False
def make_callback(func, handle): def make_callback(func, handle):
""" """
Generates a callback function based off the passed arguments Generates a callback function based off the passed arguments

@@ -105,7 +105,11 @@ class PageView(DbGUIElement):
self.dirty = True self.dirty = True
self.active = False self.active = False
self._dirty_on_change_inactive = True self._dirty_on_change_inactive = True
self.func_list = {} self.func_list = {
"Copy": self.call_copy,
"Paste": self.call_paste,
"Cut": self.call_cut,
}
self.category = "Miscellaneous" self.category = "Miscellaneous"
self.ident = None self.ident = None
self.translated_category = _("Miscellaneous") self.translated_category = _("Miscellaneous")
@@ -128,6 +132,15 @@ class PageView(DbGUIElement):
""" """
self.func_list.get(key)() self.func_list.get(key)()
def call_copy(self):
return False
def call_paste(self):
return False
def call_cut(self):
return False
def post(self): def post(self):
""" """
Called after a page is created. Called after a page is created.

@@ -1425,6 +1425,15 @@ class GrampletPane(gtk.ScrolledWindow):
return gramplet.title, table return gramplet.title, table
return gramplet_panel return gramplet_panel
def call_copy(self):
return False
def call_paste(self):
return False
def call_cut(self):
return False
class Configuration(object): class Configuration(object):
""" """
A config wrapper to redirect set/get to GrampletPane. A config wrapper to redirect set/get to GrampletPane.

@@ -132,10 +132,10 @@ class BasePersonView(ListView):
filter_class=PersonSidebarFilter, filter_class=PersonSidebarFilter,
markup=BasePersonView.MARKUP_COLS) markup=BasePersonView.MARKUP_COLS)
self.func_list = { self.func_list.update({
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete, '<CONTROL>BackSpace' : self.key_delete,
} })
config.connect("interface.filter", self.filter_toggle) config.connect("interface.filter", self.filter_toggle)
uistate.connect('nameformat-changed', self.build_tree) uistate.connect('nameformat-changed', self.build_tree)

@@ -127,11 +127,6 @@ class PlaceBaseView(ListView):
'place-rebuild' : self.object_build, 'place-rebuild' : self.object_build,
} }
self.func_list = {
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
}
self.mapservice = config.get('interface.mapservice') self.mapservice = config.get('interface.mapservice')
self.mapservicedata = {} self.mapservicedata = {}
@@ -144,6 +139,11 @@ class PlaceBaseView(ListView):
multiple=True, multiple=True,
filter_class=PlaceSidebarFilter, markup=markup) filter_class=PlaceSidebarFilter, markup=markup)
self.func_list.update({
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
})
config.connect("interface.filter", config.connect("interface.filter",
self.filter_toggle) self.filter_toggle)

@@ -121,10 +121,10 @@ class EventView(ListView):
filter_class=EventSidebarFilter, filter_class=EventSidebarFilter,
markup = EventView.MARKUP_COLS) markup = EventView.MARKUP_COLS)
self.func_list = { self.func_list.update({
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete, '<CONTROL>BackSpace' : self.key_delete,
} })
config.connect("interface.filter", self.filter_toggle) config.connect("interface.filter", self.filter_toggle)
uistate.connect('nameformat-changed', self.build_tree) uistate.connect('nameformat-changed', self.build_tree)

@@ -112,10 +112,10 @@ class FamilyView(ListView):
multiple=True, multiple=True,
filter_class=FamilySidebarFilter) filter_class=FamilySidebarFilter)
self.func_list = { self.func_list.update({
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete, '<CONTROL>BackSpace' : self.key_delete,
} })
config.connect("interface.filter", self.filter_toggle) config.connect("interface.filter", self.filter_toggle)
uistate.connect('nameformat-changed', self.build_tree) uistate.connect('nameformat-changed', self.build_tree)

@@ -128,10 +128,10 @@ class MediaView(ListView):
filter_class=MediaSidebarFilter, filter_class=MediaSidebarFilter,
multiple=True) multiple=True)
self.func_list = { self.func_list.update({
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete, '<CONTROL>BackSpace' : self.key_delete,
} })
config.connect("interface.filter", config.connect("interface.filter",
self.filter_toggle) self.filter_toggle)

@@ -101,11 +101,6 @@ class NoteView(ListView):
'note-rebuild' : self.object_build, 'note-rebuild' : self.object_build,
} }
self.func_list = {
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
}
ListView.__init__( ListView.__init__(
self, _('Notes'), dbstate, uistate, NoteView.COLUMN_NAMES, self, _('Notes'), dbstate, uistate, NoteView.COLUMN_NAMES,
len(NoteView.COLUMN_NAMES), NoteModel, signal_map, len(NoteView.COLUMN_NAMES), NoteModel, signal_map,
@@ -114,6 +109,11 @@ class NoteView(ListView):
filter_class=NoteSidebarFilter, filter_class=NoteSidebarFilter,
multiple=True) multiple=True)
self.func_list.update({
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
})
config.connect("interface.filter", config.connect("interface.filter",
self.filter_toggle) self.filter_toggle)

@@ -670,10 +670,10 @@ class PedigreeView(NavigationView):
Bookmarks.PersonBookmarks, Bookmarks.PersonBookmarks,
nav_group) nav_group)
self.func_list = { self.func_list.update({
'F2' : self.kb_goto_home, 'F2' : self.kb_goto_home,
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
} })
self.dbstate = dbstate self.dbstate = dbstate
self.dbstate.connect('database-changed', self.change_db) self.dbstate.connect('database-changed', self.change_db)

@@ -136,9 +136,9 @@ class RelationshipView(NavigationView):
Bookmarks.PersonBookmarks, Bookmarks.PersonBookmarks,
nav_group) nav_group)
self.func_list = { self.func_list.update({
'<CONTROL>J' : self.jump, '<CONTROL>J' : self.jump,
} })
dbstate.connect('database-changed', self.change_db) dbstate.connect('database-changed', self.change_db)
uistate.connect('nameformat-changed', self.build_tree) uistate.connect('nameformat-changed', self.build_tree)

@@ -119,11 +119,6 @@ class RepositoryView(ListView):
'repository-rebuild' : self.object_build, 'repository-rebuild' : self.object_build,
} }
self.func_list = {
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
}
ListView.__init__( ListView.__init__(
self, _('Repositories'), dbstate, uistate, self, _('Repositories'), dbstate, uistate,
RepositoryView.COLUMN_NAMES, len(RepositoryView.COLUMN_NAMES), RepositoryView.COLUMN_NAMES, len(RepositoryView.COLUMN_NAMES),
@@ -133,6 +128,11 @@ class RepositoryView(ListView):
multiple=True, multiple=True,
filter_class=RepoSidebarFilter) filter_class=RepoSidebarFilter)
self.func_list.update({
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
})
config.connect("interface.filter", config.connect("interface.filter",
self.filter_toggle) self.filter_toggle)

@@ -102,11 +102,6 @@ class SourceView(ListView):
'source-rebuild' : self.object_build, 'source-rebuild' : self.object_build,
} }
self.func_list = {
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
}
ListView.__init__( ListView.__init__(
self, _('Sources'), dbstate, uistate, self, _('Sources'), dbstate, uistate,
SourceView.COLUMN_NAMES, len(SourceView.COLUMN_NAMES), SourceView.COLUMN_NAMES, len(SourceView.COLUMN_NAMES),
@@ -116,6 +111,11 @@ class SourceView(ListView):
multiple=True, multiple=True,
filter_class=SourceSidebarFilter) filter_class=SourceSidebarFilter)
self.func_list.update({
'<CONTROL>J' : self.jump,
'<CONTROL>BackSpace' : self.key_delete,
})
config.connect("interface.filter", config.connect("interface.filter",
self.filter_toggle) self.filter_toggle)