From 78e5ed05fcaabc514de2adae55645b6ad5959ab3 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Wed, 16 Jul 2014 00:18:00 +0100 Subject: [PATCH] 7856: Fix error when no place is selected Check that a place has been selected when saving. Use the standard place selection widget to be consistent. This also implements feature request #7893. --- gramps/gui/editors/editplaceref.py | 43 +++++++++++++--------------- gramps/gui/editors/objectentries.py | 12 ++++++-- gramps/gui/glade/editplaceref.glade | 44 ++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/gramps/gui/editors/editplaceref.py b/gramps/gui/editors/editplaceref.py index 03aeeb92f..5dc7f3be2 100644 --- a/gramps/gui/editors/editplaceref.py +++ b/gramps/gui/editors/editplaceref.py @@ -27,13 +27,11 @@ from .editsecondary import EditSecondary from ..glade import Glade from ..widgets import MonitoredDate -from ..selectors import SelectorFactory +from .objectentries import PlaceEntry from ..dialog import ErrorDialog from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -SelectPlace = SelectorFactory('Place') - #------------------------------------------------------------------------- # # EditPlaceRef class @@ -52,6 +50,9 @@ class EditPlaceRef(EditSecondary): self.top = Glade() self.set_window(self.top.toplevel, None, _('Place Reference Editor')) + self.share_btn = self.top.get_object('select_place') + self.add_del_btn = self.top.get_object('add_del_place') + def _setup_fields(self): self.date_field = MonitoredDate(self.top.get_object("date_entry"), @@ -60,14 +61,12 @@ class EditPlaceRef(EditSecondary): self.uistate, self.track, self.db.readonly) - self.parent = self.top.get_object('place_label') - if self.obj.ref is not None: - place = self.db.get_place_from_handle(self.obj.ref) - self.parent.set_text(place.get_name()) - else: - self.parent.set_text(_('Top level place')) - button = self.top.get_object('place_button') - button.connect('clicked', self.select_parent) + self.place_field = PlaceEntry(self.dbstate, self.uistate, self.track, + self.top.get_object("place"), + self.obj.set_reference_handle, + self.obj.get_reference_handle, + self.add_del_btn, self.share_btn, + skip=self.get_skip_list(self.handle)) def get_skip_list(self, handle): todo = [handle] @@ -80,23 +79,21 @@ class EditPlaceRef(EditSecondary): skip.append(child[1]) return skip - def select_parent(self, button): - if self.handle: - skip = self.get_skip_list(self.handle) - else: - skip = [] - sel = SelectPlace(self.dbstate, self.uistate, self.track, skip=skip) - parent = sel.run() - if parent: - self.parent.set_text(parent.get_name()) - self.obj.ref = parent.get_handle() - def _connect_signals(self): self.define_cancel_button(self.top.get_object('cancel_button')) - self.define_ok_button(self.top.get_object('ok_button'), self.save) + self.ok_button = self.top.get_object('ok_button') + self.define_ok_button(self.ok_button, self.save) self.define_help_button(self.top.get_object('help_button')) def save(self, *obj): + self.ok_button.set_sensitive(False) + if not self.obj.ref: + ErrorDialog(_("Cannot save place reference"), + _("No place selected. Please select a place " + " or cancel the edit.")) + self.ok_button.set_sensitive(True) + return + if self.callback: self.callback(self.obj) self.close() diff --git a/gramps/gui/editors/objectentries.py b/gramps/gui/editors/objectentries.py index f05816e00..85ce59376 100644 --- a/gramps/gui/editors/objectentries.py +++ b/gramps/gui/editors/objectentries.py @@ -269,9 +269,10 @@ class PlaceEntry(ObjEntry): DEL_STR = _('Remove place') def __init__(self, dbstate, uistate, track, label, set_val, - get_val, add_edt, share): + get_val, add_edt, share, skip=[]): ObjEntry.__init__(self, dbstate, uistate, track, label, set_val, get_val, add_edt, share) + self.skip = skip def _init_dnd(self): """connect drag and drop of places @@ -283,6 +284,13 @@ class PlaceEntry(ObjEntry): self.label.drag_dest_set_target_list(tglist) self.label.connect('drag_data_received', self.drag_data_received) + def drag_data_received(self, widget, context, x, y, selection, info, time): + (drag_type, idval, obj, val) = pickle.loads(selection.get_data()) + + if obj not in self.skip: + data = self.get_from_handle(obj) + self.obj_added(data) + def get_from_handle(self, handle): """ return the object given the hande """ @@ -306,7 +314,7 @@ class PlaceEntry(ObjEntry): def call_selector(self): cls = SelectorFactory('Place') - return cls(self.dbstate, self.uistate, self.track) + return cls(self.dbstate, self.uistate, self.track, skip=self.skip) class SourceEntry(ObjEntry): """ diff --git a/gramps/gui/glade/editplaceref.glade b/gramps/gui/glade/editplaceref.glade index 77a6c4f79..cfa4098e9 100644 --- a/gramps/gui/glade/editplaceref.glade +++ b/gramps/gui/glade/editplaceref.glade @@ -1,6 +1,8 @@ + - + + False 550 @@ -78,7 +80,7 @@ False 12 2 - 3 + 4 12 6 @@ -111,11 +113,11 @@ - - ... + True False True + none 2 @@ -132,12 +134,6 @@ True Invoke date editor none - - - - Date - - True @@ -152,10 +148,16 @@ + + + Date + + + - 2 - 3 + 3 + 4 1 2 GTK_FILL @@ -163,7 +165,7 @@ - + True False 0 @@ -184,12 +186,26 @@ 1 - 2 + 3 1 2 + + + True + True + True + none + + + 3 + 4 + GTK_FILL + + + True