diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2022-09-29 18:41:21 +0200 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2022-10-09 21:01:58 +0000 |
commit | e515d79d4f9440534cf64f1b893f96c2022d6502 (patch) | |
tree | 6816d22b737e426f07398ee409471d2dba5ddf8b /src | |
parent | 41356dc94bdb019fb9d7add3a608e655a97065d2 (diff) | |
download | gnome-contacts-e515d79d4f9440534cf64f1b893f96c2022d6502.tar.gz |
pane: Select the new individual after saving changes
Fixes: https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/271
Diffstat (limited to 'src')
-rw-r--r-- | src/contacts-contact-pane.vala | 16 | ||||
-rw-r--r-- | src/core/contacts-contact.vala | 14 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala index ffdcbf3..ee9ee6c 100644 --- a/src/contacts-contact-pane.vala +++ b/src/contacts-contact-pane.vala @@ -176,12 +176,24 @@ public class Contacts.ContactPane : Adw.Bin { } try { - yield contact.apply_changes (this.store.aggregator.primary_store); + // The new individual. Even when editing an exisiting contact, it might + // be a different Individual than before, so make sure to adjust our + // selected contact afterwards + unowned var individual = + yield contact.apply_changes (this.store.aggregator.primary_store); + debug ("Applied changes resulted in individual (%s)", + (individual != null)? individual.id : "null"); + + if (individual != null) { + var pos = yield this.store.find_individual_for_id (individual.id); + if (pos != Gtk.INVALID_LIST_POSITION) + this.store.selection.selected = pos; + } } catch (Error err) { warning ("Couldn't save changes: %s", err.message); + show_contact (null); // XXX do something better here } - show_contact_sheet (contact); } public void edit_contact () { diff --git a/src/core/contacts-contact.vala b/src/core/contacts-contact.vala index 866ec18..5fcc742 100644 --- a/src/core/contacts-contact.vala +++ b/src/core/contacts-contact.vala @@ -258,14 +258,21 @@ public class Contacts.Contact : GLib.Object, GLib.ListModel { * Applies any pending changes to all chunks. This can mean either a new * persona is made, or it is saved in the chunk's referenced persona. * When a new persona is made, it will be added to @store. + * + * Returns the Individual that was created from applying the changes */ - public async void apply_changes (PersonaStore store) throws GLib.Error { + public async unowned Individual? apply_changes (PersonaStore store) throws GLib.Error { + unowned Individual? individual = null; + // For those that were a persona: save the properties using the API for (uint i = 0; i < this.chunks.length; i++) { unowned var chunk = this.chunks[i]; if (chunk.persona == null) continue; + if (individual == null) + individual = chunk.persona.individual; + if (!(chunk.property_name in chunk.persona.writeable_properties)) { warning ("Can't save to unwriteable property '%s' to persona %s", chunk.property_name, chunk.persona.uid); @@ -303,6 +310,11 @@ public class Contacts.Contact : GLib.Object, GLib.ListModel { var persona = yield store.add_persona_from_details (new_details); debug ("Successfully created new persona %p", persona); // FIXME: should we set the persona for these chunks? + + if (individual == null && persona != null) + individual = persona.individual; } + + return individual; } } |