From 0cc78b2e8926485f4c301cfa4f96057d61321032 Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Wed, 28 Mar 2007 16:27:45 +0000 Subject: [PATCH] * src/DataViews/_NoteView.py: enable shortcuts and drag-and-drop. * src/Bookmarks.py (NoteBookmarks.make_label): better note label. * src/DisplayTabs/_NoteModel.py: better note label for preview. * src/DisplayTabs/_NoteTab.py: enable accepting drag-and-drop notes. * src/ScratchPad.py: ScratchPadNote added. * src/DdTargets.py: NOTE_LINK added. 2007-03-28 Zsolt Foldvari svn: r8334 --- ChangeLog | 8 ++++++++ src/Bookmarks.py | 4 +++- src/DataViews/_NoteView.py | 17 +++++++++------- src/DdTargets.py | 38 +++++++++++++++++++---------------- src/DisplayTabs/_NoteModel.py | 5 ++++- src/DisplayTabs/_NoteTab.py | 21 +++++++++++++++++++ src/ScratchPad.py | 34 +++++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9b484db5..a3e18b3bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-03-28 Zsolt Foldvari + * src/DataViews/_NoteView.py: enable shortcuts and drag-and-drop. + * src/Bookmarks.py (NoteBookmarks.make_label): better note label. + * src/DisplayTabs/_NoteModel.py: better note label for preview. + * src/DisplayTabs/_NoteTab.py: enable accepting drag-and-drop notes. + * src/ScratchPad.py: ScratchPadNote added. + * src/DdTargets.py: NOTE_LINK added. + 2007-03-28 Zsolt Foldvari * src/DataViews/_NoteView.py: put back column editor support. * src/GrampsDb/_GrampsDbBase.py (get_note_column_order): fix default diff --git a/src/Bookmarks.py b/src/Bookmarks.py index c09ae91da..f493dde21 100644 --- a/src/Bookmarks.py +++ b/src/Bookmarks.py @@ -391,7 +391,9 @@ class NoteBookmarks(ListBookmarks) : def make_label(self,handle): obj = self.dbstate.db.get_note_from_handle(handle) - name = obj.get().replace('\n', ' ')[:80] + name = obj.get().replace('\n', ' ') + if len(name) > 40: + name = name[:40]+"..." return ("%s [%s]" % (name, obj.gramps_id), obj) def connect_signals(self): diff --git a/src/DataViews/_NoteView.py b/src/DataViews/_NoteView.py index 83ca87710..9917b58ca 100644 --- a/src/DataViews/_NoteView.py +++ b/src/DataViews/_NoteView.py @@ -38,13 +38,15 @@ import gtk # gramps modules # #------------------------------------------------------------------------- -from RelLib import Note import PageView import DisplayModels import Utils import Errors import Bookmarks import Config +import ColumnOrder +from RelLib import Note +from DdTargets import DdTargets from QuestionDialog import QuestionDialog, ErrorDialog from Filters.SideBar import NoteSidebarFilter from Editors import EditNote, DeleteNoteQuery @@ -82,12 +84,12 @@ class NoteView(PageView.ListView): 'note-update' : self.row_update, 'note-delete' : self.row_delete, 'note-rebuild' : self.build_tree, - } + } self.func_list = { -# 'J' : self.jump, -# 'BackSpace' : self.key_delete, - } + 'J' : self.jump, + 'BackSpace' : self.key_delete, + } PageView.ListView.__init__( self, _('Notes'), dbstate, uistate, column_names, @@ -110,9 +112,10 @@ class NoteView(PageView.ListView): self.add_action('FilterEdit', None, _('Note Filter Editor'), callback=self.filter_editor,) - def column_editor(self, obj): - import ColumnOrder + def drag_info(self): + return DdTargets.NOTE_LINK + def column_editor(self, obj): ColumnOrder.ColumnOrder( _('Select Note Columns'), self.uistate, diff --git a/src/DdTargets.py b/src/DdTargets.py index 4cb140441..ce8ec2b04 100644 --- a/src/DdTargets.py +++ b/src/DdTargets.py @@ -120,6 +120,7 @@ class _DdTargets(object): self.MEDIAOBJ = _DdType(self,'mediaobj') self.MEDIAREF = _DdType(self,'mediaref') self.DATA = _DdType(self,'data_tuple') + self.NOTE_LINK = _DdType(self,'note-link') self.PERSON_LINK = _DdType(self,'person-link') self.PERSON_LINK_LIST = _DdType(self,'person-link-list') @@ -133,23 +134,26 @@ class _DdTargets(object): # List of all types that are used between # gramps widgets but should not be exported # to non gramps widgets. - self._all_gramps_types = [self.URL, - self.EVENT, - self.ATTRIBUTE, - self.ADDRESS, - self.LOCATION, - self.SOURCEREF, - self.EVENTREF, - self.NAME, - self.REPOREF, - self.MEDIAOBJ, - self.MEDIAREF, - self.REPO_LINK, - self.PLACE_LINK, - self.SOURCE_LINK, - self.PERSON_LINK, - self.PERSON_LINK_LIST, - self.PERSONREF] + self._all_gramps_types = [ + self.URL, + self.EVENT, + self.ATTRIBUTE, + self.ADDRESS, + self.LOCATION, + self.SOURCEREF, + self.EVENTREF, + self.NAME, + self.REPOREF, + self.MEDIAOBJ, + self.MEDIAREF, + self.REPO_LINK, + self.PLACE_LINK, + self.SOURCE_LINK, + self.PERSON_LINK, + self.PERSON_LINK_LIST, + self.PERSONREF, + self.NOTE_LINK, + ] self.CHILD = _DdType(self,'child') self.SPOUSE = _DdType(self,'spouse') diff --git a/src/DisplayTabs/_NoteModel.py b/src/DisplayTabs/_NoteModel.py index f4a128c5e..f93d30e3b 100644 --- a/src/DisplayTabs/_NoteModel.py +++ b/src/DisplayTabs/_NoteModel.py @@ -39,8 +39,11 @@ class NoteModel(gtk.ListStore): self.db = db for handle in note_list: note = self.db.get_note_from_handle(handle) + text = note.get().replace('\n', ' ') + if len(text) > 80: + text = text[:80]+"..." self.append(row=[ str(note.get_type()), - note.get().replace('\n', ' ')[:80], + text, handle, ]) diff --git a/src/DisplayTabs/_NoteTab.py b/src/DisplayTabs/_NoteTab.py index 64d0d2890..95e338511 100644 --- a/src/DisplayTabs/_NoteTab.py +++ b/src/DisplayTabs/_NoteTab.py @@ -26,6 +26,14 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import cPickle as pickle + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +import gtk #------------------------------------------------------------------------- # @@ -39,6 +47,7 @@ from DisplayTabs import log from _NoteModel import NoteModel from _EmbeddedList import EmbeddedList from Editors import EditNote +from DdTargets import DdTargets #------------------------------------------------------------------------- # @@ -64,6 +73,18 @@ class NoteTab(EmbeddedList): self.data = data EmbeddedList.__init__(self, dbstate, uistate, track, _("Notes"), NoteModel) + + self.tree.drag_dest_set(gtk.DEST_DEFAULT_ALL, + [DdTargets.NOTE_LINK.target()], + gtk.gdk.ACTION_COPY) + self.tree.connect('drag_data_received', self.on_drag_data_received) + + def on_drag_data_received(self, widget, context, x, y, + selection, info, time): + """Insert the received note to the note list of current object. + """ + (drag_type, idval, obj, val) = pickle.loads(selection.data) + self.add_callback(obj) def get_editor(self): pass diff --git a/src/ScratchPad.py b/src/ScratchPad.py index 40f8f046c..6c93e59cf 100644 --- a/src/ScratchPad.py +++ b/src/ScratchPad.py @@ -281,6 +281,39 @@ class ScratchPadPlace(ScratchPadWrapper): return True return False +class ScratchPadNote(ScratchPadWrapper): + + DROP_TARGETS = [DdTargets.NOTE_LINK] + DRAG_TARGET = DdTargets.NOTE_LINK + ICON = LINK_PIC + + def __init__(self,dbstate,obj): + ScratchPadWrapper.__init__(self,dbstate,obj) + self._type = _("Note") + + (drag_type, idval, handle, val) = pickle.loads(obj) + + value = self._db.get_note_from_handle(handle) + + self._title = value.get_gramps_id() + note = value.get().replace('\n', ' ') + if len(note) > 80: + self._value = note[:80]+"..." + else: + self._value = note + + def tooltip(self): + global escape + return "" + + def is_valid(self): + data = pickle.loads(self._obj) + handle = data[2] + obj = self._db.get_note_from_handle(handle) + if obj: + return True + return False + class ScratchPadFamilyEvent(ScratchPadGrampsTypeWrapper): DROP_TARGETS = [DdTargets.FAMILY_EVENT] @@ -958,6 +991,7 @@ class ScratchPadListView: self.register_wrapper_class(ScratchPersonLinkList) self.register_wrapper_class(ScratchPadPersonRef) self.register_wrapper_class(ScratchPadText) + self.register_wrapper_class(ScratchPadNote) def register_wrapper_class(self,wrapper_class): for drop_target in wrapper_class.DROP_TARGETS: