From 8c35277267e98ab9271f179c54564f957dd2d3a4 Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Wed, 28 Nov 2018 12:58:46 +0100 Subject: [PATCH] Fix Adding "ToDo" note crash when no active object (#685) * Fix Adding "ToDo" note crash when no active object Fixes #10795 * Better message when no active object. * resolve conflict: Fixes #10795 --- gramps/plugins/gramplet/todo.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/gramps/plugins/gramplet/todo.py b/gramps/plugins/gramplet/todo.py index 2ee801980..783bd5a7a 100644 --- a/gramps/plugins/gramplet/todo.py +++ b/gramps/plugins/gramplet/todo.py @@ -32,6 +32,7 @@ from gi.repository import Gtk from gramps.gen.plug import Gramplet from gramps.gui.widgets.styledtexteditor import StyledTextEditor from gramps.gui.widgets import SimpleButton +from gramps.gui.dialog import WarningDialog from gramps.gen.lib import StyledText, Note, NoteType from gramps.gen.db import DbTxn from gramps.gen.errors import WindowActiveError @@ -185,13 +186,21 @@ class ToDo(Gramplet): """ Create a new To Do note. """ - from gramps.gui.editors import EditNote - note = Note() - note.set_type(NoteType.TODO) - try: - EditNote(self.gui.dbstate, self.gui.uistate, [], note, self.created) - except WindowActiveError: - pass + nav_type = self.uistate.viewmanager.active_page.navigation_type() + active_handle = self.get_active(nav_type) + if active_handle: + from gramps.gui.editors import EditNote + note = Note() + note.set_type(NoteType.TODO) + try: + EditNote(self.gui.dbstate, self.gui.uistate, [], note, self.created) + except WindowActiveError: + pass + else: + WarningDialog(_("No active object"), + _("First select the object to which you want to attach a note") + + _(":") + _(nav_type), + parent=self.uistate.window) class PersonToDo(ToDo): """