2007-02-13 23:26:31 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2001-2006 Donald N. Allingham
|
2008-07-26 14:04:09 +05:30
|
|
|
# Copyright (C) 2008 Gary Burton
|
2010-10-23 04:52:33 +05:30
|
|
|
# Copyright (C) 2010 Nick Hall
|
2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2007-03-27 23:58:26 +05:30
|
|
|
# $Id$
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
"""
|
2009-11-08 22:11:49 +05:30
|
|
|
Note View.
|
2007-02-13 23:26:31 +05:30
|
|
|
"""
|
2009-11-08 22:11:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2009-11-08 22:11:49 +05:30
|
|
|
import logging
|
|
|
|
_LOG = logging.getLogger(".plugins.noteview")
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-10-08 02:21:12 +05:30
|
|
|
from gui.views.listview import ListView
|
2009-11-08 22:11:49 +05:30
|
|
|
from gui.views.treemodels import NoteModel
|
2007-02-13 23:26:31 +05:30
|
|
|
import Utils
|
|
|
|
import Errors
|
|
|
|
import Bookmarks
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2007-10-08 22:11:39 +05:30
|
|
|
from gen.lib import Note
|
2007-03-28 21:57:45 +05:30
|
|
|
from DdTargets import DdTargets
|
2010-07-22 07:46:32 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2007-02-25 00:46:50 +05:30
|
|
|
from Filters.SideBar import NoteSidebarFilter
|
2009-12-15 11:26:12 +05:30
|
|
|
from gui.editors import EditNote, DeleteNoteQuery
|
2009-12-31 20:29:44 +05:30
|
|
|
from gen.plug import CATEGORY_QR_NOTE
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# NoteView
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-10-08 02:21:12 +05:30
|
|
|
class NoteView(ListView):
|
2010-02-01 12:31:45 +05:30
|
|
|
"""
|
|
|
|
Noteview, a normal flat listview for the notes
|
|
|
|
"""
|
|
|
|
COL_PREVIEW = 0
|
|
|
|
COL_ID = 1
|
|
|
|
COL_TYPE = 2
|
2010-10-23 04:52:33 +05:30
|
|
|
COL_TAGS = 3
|
2010-02-01 12:31:45 +05:30
|
|
|
COL_CHAN = 4
|
2007-09-25 17:39:25 +05:30
|
|
|
|
|
|
|
COLUMN_NAMES = [
|
2008-01-10 02:45:28 +05:30
|
|
|
_('Preview'),
|
2007-09-25 17:39:25 +05:30
|
|
|
_('ID'),
|
|
|
|
_('Type'),
|
2010-10-23 04:52:33 +05:30
|
|
|
_('Tags'),
|
2010-02-01 12:31:45 +05:30
|
|
|
_('Last Changed')
|
2007-09-25 17:39:25 +05:30
|
|
|
]
|
2010-02-01 12:31:45 +05:30
|
|
|
# default setting with visible columns, order of the col, and their size
|
|
|
|
CONFIGSETTINGS = (
|
2010-10-23 04:52:33 +05:30
|
|
|
('columns.visible', [COL_PREVIEW, COL_ID, COL_TYPE]),
|
|
|
|
('columns.rank', [COL_PREVIEW, COL_ID, COL_TYPE, COL_TAGS, COL_CHAN]),
|
2010-03-28 04:30:41 +05:30
|
|
|
('columns.size', [350, 75, 100, 100, 100]))
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
ADD_MSG = _("Add a new note")
|
|
|
|
EDIT_MSG = _("Edit the selected note")
|
|
|
|
DEL_MSG = _("Delete the selected note")
|
2011-03-09 21:37:34 +05:30
|
|
|
MERGE_MSG = _("Merge the selected notes")
|
2007-02-13 23:26:31 +05:30
|
|
|
FILTER_TYPE = "Note"
|
2009-12-31 20:29:44 +05:30
|
|
|
QR_CATEGORY = CATEGORY_QR_NOTE
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2010-12-28 22:34:41 +05:30
|
|
|
def __init__(self, pdata, dbstate, uistate, nav_group=0):
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
signal_map = {
|
2007-02-20 10:05:34 +05:30
|
|
|
'note-add' : self.row_add,
|
|
|
|
'note-update' : self.row_update,
|
|
|
|
'note-delete' : self.row_delete,
|
2007-10-03 22:04:51 +05:30
|
|
|
'note-rebuild' : self.object_build,
|
2010-10-23 04:52:33 +05:30
|
|
|
'tag-update' : self.tag_updated
|
2007-03-28 21:57:45 +05:30
|
|
|
}
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2009-10-08 02:21:12 +05:30
|
|
|
ListView.__init__(
|
2010-12-28 22:34:41 +05:30
|
|
|
self, _('Notes'), pdata, dbstate, uistate, NoteView.COLUMN_NAMES,
|
2009-11-08 22:11:49 +05:30
|
|
|
len(NoteView.COLUMN_NAMES), NoteModel, signal_map,
|
2007-03-27 23:58:26 +05:30
|
|
|
dbstate.db.get_note_bookmarks(),
|
2010-01-11 00:49:33 +05:30
|
|
|
Bookmarks.NoteBookmarks, nav_group,
|
2007-02-25 00:46:50 +05:30
|
|
|
filter_class=NoteSidebarFilter,
|
2008-07-26 14:04:09 +05:30
|
|
|
multiple=True)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2010-08-10 02:21:54 +05:30
|
|
|
self.func_list.update({
|
|
|
|
'<CONTROL>J' : self.jump,
|
|
|
|
'<CONTROL>BackSpace' : self.key_delete,
|
|
|
|
})
|
|
|
|
|
2010-12-28 22:34:41 +05:30
|
|
|
self.additional_uis.append(self.additional_ui())
|
|
|
|
|
2010-01-02 01:25:09 +05:30
|
|
|
def navigation_type(self):
|
2010-01-11 00:49:33 +05:30
|
|
|
return 'Note'
|
2010-01-02 01:25:09 +05:30
|
|
|
|
2007-02-13 23:26:31 +05:30
|
|
|
def get_bookmarks(self):
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the bookmark object
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
2007-03-27 23:58:26 +05:30
|
|
|
return self.dbstate.db.get_note_bookmarks()
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2007-03-28 21:57:45 +05:30
|
|
|
def drag_info(self):
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Indicate that the drag type is an EVENT
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
2007-03-28 21:57:45 +05:30
|
|
|
return DdTargets.NOTE_LINK
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
def get_stock(self):
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
|
|
|
Use the gramps-event stock icon
|
|
|
|
"""
|
2007-02-13 23:26:31 +05:30
|
|
|
return 'gramps-notes'
|
|
|
|
|
2010-12-28 22:34:41 +05:30
|
|
|
def additional_ui(self):
|
2007-07-08 08:57:06 +05:30
|
|
|
"""
|
|
|
|
Defines the UI string for UIManager
|
|
|
|
"""
|
2007-02-13 23:26:31 +05:30
|
|
|
return '''<ui>
|
|
|
|
<menubar name="MenuBar">
|
2009-01-11 17:13:59 +05:30
|
|
|
<menu action="FileMenu">
|
|
|
|
<placeholder name="LocalExport">
|
|
|
|
<menuitem action="ExportTab"/>
|
|
|
|
</placeholder>
|
|
|
|
</menu>
|
2007-02-13 23:26:31 +05:30
|
|
|
<menu action="BookMenu">
|
|
|
|
<placeholder name="AddEditBook">
|
|
|
|
<menuitem action="AddBook"/>
|
|
|
|
<menuitem action="EditBook"/>
|
|
|
|
</placeholder>
|
|
|
|
</menu>
|
2010-01-11 00:49:33 +05:30
|
|
|
<menu action="GoMenu">
|
|
|
|
<placeholder name="CommonGo">
|
|
|
|
<menuitem action="Back"/>
|
|
|
|
<menuitem action="Forward"/>
|
2010-01-13 21:29:36 +05:30
|
|
|
<separator/>
|
2010-01-11 00:49:33 +05:30
|
|
|
</placeholder>
|
|
|
|
</menu>
|
2007-02-13 23:26:31 +05:30
|
|
|
<menu action="EditMenu">
|
|
|
|
<placeholder name="CommonEdit">
|
|
|
|
<menuitem action="Add"/>
|
|
|
|
<menuitem action="Edit"/>
|
|
|
|
<menuitem action="Remove"/>
|
2010-07-22 07:46:32 +05:30
|
|
|
<menuitem action="Merge"/>
|
2007-02-13 23:26:31 +05:30
|
|
|
</placeholder>
|
2007-02-25 17:49:47 +05:30
|
|
|
<menuitem action="FilterEdit"/>
|
2007-02-13 23:26:31 +05:30
|
|
|
</menu>
|
|
|
|
</menubar>
|
|
|
|
<toolbar name="ToolBar">
|
2010-01-11 00:49:33 +05:30
|
|
|
<placeholder name="CommonNavigation">
|
|
|
|
<toolitem action="Back"/>
|
|
|
|
<toolitem action="Forward"/>
|
|
|
|
</placeholder>
|
2007-02-13 23:26:31 +05:30
|
|
|
<placeholder name="CommonEdit">
|
|
|
|
<toolitem action="Add"/>
|
|
|
|
<toolitem action="Edit"/>
|
|
|
|
<toolitem action="Remove"/>
|
2010-07-22 07:46:32 +05:30
|
|
|
<toolitem action="Merge"/>
|
2007-02-13 23:26:31 +05:30
|
|
|
</placeholder>
|
|
|
|
</toolbar>
|
|
|
|
<popup name="Popup">
|
2010-01-11 00:49:33 +05:30
|
|
|
<menuitem action="Back"/>
|
|
|
|
<menuitem action="Forward"/>
|
|
|
|
<separator/>
|
2007-02-13 23:26:31 +05:30
|
|
|
<menuitem action="Add"/>
|
|
|
|
<menuitem action="Edit"/>
|
|
|
|
<menuitem action="Remove"/>
|
2010-07-22 07:46:32 +05:30
|
|
|
<menuitem action="Merge"/>
|
2009-12-31 20:29:44 +05:30
|
|
|
<separator/>
|
|
|
|
<menu name="QuickReport" action="QuickReport">
|
|
|
|
<menuitem action="Dummy"/>
|
|
|
|
</menu>
|
2007-02-13 23:26:31 +05:30
|
|
|
</popup>
|
|
|
|
</ui>'''
|
|
|
|
|
2009-12-31 20:29:44 +05:30
|
|
|
def dummy_report(self, obj):
|
|
|
|
""" For the xml UI definition of popup to work, the submenu
|
|
|
|
Quick Report must have an entry in the xml
|
|
|
|
As this submenu will be dynamically built, we offer a dummy action
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2007-07-08 08:57:06 +05:30
|
|
|
def define_actions(self):
|
2009-10-08 02:21:12 +05:30
|
|
|
ListView.define_actions(self)
|
2007-09-13 09:50:24 +05:30
|
|
|
self._add_action('FilterEdit', None, _('Note Filter Editor'),
|
|
|
|
callback=self.filter_editor,)
|
2009-12-31 20:29:44 +05:30
|
|
|
self._add_action('QuickReport', None, _("Quick View"), None, None, None)
|
|
|
|
self._add_action('Dummy', None, ' ', None, None, self.dummy_report)
|
2007-07-08 08:57:06 +05:30
|
|
|
|
2010-10-23 04:52:33 +05:30
|
|
|
def set_active(self):
|
|
|
|
"""
|
|
|
|
Called when the page is displayed.
|
|
|
|
"""
|
|
|
|
ListView.set_active(self)
|
|
|
|
self.uistate.viewmanager.tags.tag_enable()
|
|
|
|
|
|
|
|
def set_inactive(self):
|
|
|
|
"""
|
|
|
|
Called when the page is no longer displayed.
|
|
|
|
"""
|
|
|
|
ListView.set_inactive(self)
|
|
|
|
self.uistate.viewmanager.tags.tag_disable()
|
|
|
|
|
2007-07-08 08:57:06 +05:30
|
|
|
def get_handle_from_gramps_id(self, gid):
|
|
|
|
obj = self.dbstate.db.get_note_from_gramps_id(gid)
|
|
|
|
if obj:
|
|
|
|
return obj.get_handle()
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2007-02-13 23:26:31 +05:30
|
|
|
def add(self, obj):
|
|
|
|
try:
|
2007-03-27 23:58:26 +05:30
|
|
|
EditNote(self.dbstate, self.uistate, [], Note())
|
2007-02-13 23:26:31 +05:30
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def remove(self, obj):
|
2008-07-26 14:04:09 +05:30
|
|
|
self.remove_selected_objects()
|
|
|
|
|
|
|
|
def remove_object_from_handle(self, handle):
|
|
|
|
the_lists = Utils.get_note_referents(handle, self.dbstate.db)
|
|
|
|
object = self.dbstate.db.get_note_from_handle(handle)
|
|
|
|
query = DeleteNoteQuery(self.dbstate, self.uistate, object, the_lists)
|
|
|
|
is_used = any(the_lists)
|
|
|
|
return (query, is_used, object)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
def edit(self, obj):
|
2008-07-26 17:29:37 +05:30
|
|
|
for handle in self.selected_handles():
|
2007-02-20 10:05:34 +05:30
|
|
|
note = self.dbstate.db.get_note_from_handle(handle)
|
2007-02-13 23:26:31 +05:30
|
|
|
try:
|
2007-02-26 07:09:16 +05:30
|
|
|
EditNote(self.dbstate, self.uistate, [], note)
|
2007-02-13 23:26:31 +05:30
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2010-07-22 07:46:32 +05:30
|
|
|
|
|
|
|
def merge(self, obj):
|
|
|
|
"""
|
|
|
|
Merge the selected notes.
|
|
|
|
"""
|
|
|
|
mlist = self.selected_handles()
|
|
|
|
|
|
|
|
if len(mlist) != 2:
|
|
|
|
msg = _("Cannot merge notes.")
|
|
|
|
msg2 = _("Exactly two notes must be selected to perform a merge. "
|
|
|
|
"A second note can be selected by holding down the "
|
|
|
|
"control key while clicking on the desired note.")
|
|
|
|
ErrorDialog(msg, msg2)
|
|
|
|
else:
|
|
|
|
import Merge
|
|
|
|
Merge.MergeNotes(self.dbstate, self.uistate, mlist[0], mlist[1])
|
2010-10-23 04:52:33 +05:30
|
|
|
|
|
|
|
def tag_updated(self, handle_list):
|
|
|
|
"""
|
|
|
|
Update tagged rows when a tag color changes.
|
|
|
|
"""
|
|
|
|
all_links = set([])
|
|
|
|
for tag_handle in handle_list:
|
|
|
|
links = set([link[1] for link in
|
|
|
|
self.dbstate.db.find_backlink_handles(tag_handle,
|
|
|
|
include_classes='Note')])
|
|
|
|
all_links = all_links.union(links)
|
|
|
|
self.row_update(list(all_links))
|
|
|
|
|
|
|
|
def add_tag(self, transaction, note_handle, tag_handle):
|
|
|
|
"""
|
|
|
|
Add the given tag to the given note.
|
|
|
|
"""
|
|
|
|
note = self.dbstate.db.get_note_from_handle(note_handle)
|
|
|
|
note.add_tag(tag_handle)
|
|
|
|
self.dbstate.db.commit_note(note, transaction)
|
2011-01-30 08:32:38 +05:30
|
|
|
|
|
|
|
def get_default_gramplets(self):
|
|
|
|
"""
|
|
|
|
Define the default gramplets for the sidebar and bottombar.
|
|
|
|
"""
|
|
|
|
return (("Note Filter Gramplet",),
|
|
|
|
())
|