From 456ccf698c6b8e76ad1732a5df3e71f3038c2289 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sun, 25 Mar 2018 20:58:36 +0200 Subject: ContactPane: clean up suggestion_grid handling. * Extract a single function to remove the suggestion grid. --- src/contacts-contact-pane.vala | 43 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala index 4ea0583..f7885dc 100644 --- a/src/contacts-contact-pane.vala +++ b/src/contacts-contact-pane.vala @@ -64,7 +64,7 @@ public class Contacts.ContactPane : Stack { }; public bool on_edit_mode; - private LinkSuggestionGrid suggestion_grid; + private LinkSuggestionGrid? suggestion_grid = null; /* Signals */ public signal void contacts_linked (string? main_contact, string linked_contact, LinkOperation operation); @@ -78,11 +78,7 @@ public class Contacts.ContactPane : Stack { public void add_suggestion (Contact c) { var parent_overlay = this.get_parent () as Overlay; - if (suggestion_grid != null) { - suggestion_grid.destroy (); - suggestion_grid = null; - } - + remove_suggestion_grid (); this.suggestion_grid = new LinkSuggestionGrid (c); parent_overlay.add_overlay (this.suggestion_grid); @@ -92,13 +88,13 @@ public class Contacts.ContactPane : Stack { var operation = link_contacts.end (result); this.contacts_linked (null, linked_contact, operation); }); - this.suggestion_grid.destroy (); + remove_suggestion_grid (); }); this.suggestion_grid.suggestion_rejected.connect ( () => { - store.add_no_suggest_link (contact, c); /* TODO: Add undo */ - this.suggestion_grid.destroy (); + store.add_no_suggest_link (contact, c); + remove_suggestion_grid (); }); } @@ -106,12 +102,8 @@ public class Contacts.ContactPane : Stack { if (this.contact == contact) return; - if (this.suggestion_grid != null) { - this.suggestion_grid.destroy (); - this.suggestion_grid = null; - } - this.contact = contact; + if (this.contact != null) { show_contact_sheet (); } else { @@ -127,8 +119,6 @@ public class Contacts.ContactPane : Stack { this.edit_contact_actions = new SimpleActionGroup (); this.edit_contact_actions.add_action_entries (action_entries, this); - this.suggestion_grid = null; - /* edit mode widgetry, third page */ this.on_edit_mode = false; this.editor = new ContactEditor (this.edit_contact_actions); @@ -172,6 +162,9 @@ public class Contacts.ContactPane : Stack { if (this.sheet == null) return; + // Remove the suggestion grid that goes along with it. + remove_suggestion_grid (); + this.contact_sheet_container.remove (this.sheet); this.sheet.destroy(); this.sheet = null; @@ -218,11 +211,6 @@ public class Contacts.ContactPane : Stack { remove_contact_sheet (); - if (suggestion_grid != null) { - suggestion_grid.destroy (); - suggestion_grid = null; - } - editor.clear (); editor.edit (contact); editor.show_all (); @@ -286,11 +274,6 @@ public class Contacts.ContactPane : Stack { remove_contact_sheet (); - if (suggestion_grid != null) { - suggestion_grid.destroy (); - suggestion_grid = null; - } - editor.set_new_contact (); set_visible_child (this.contact_editor_page); @@ -357,4 +340,12 @@ public class Contacts.ContactPane : Stack { notification.show (); this.parent_window.add_notification (notification); } + + private void remove_suggestion_grid () { + if (this.suggestion_grid == null) + return; + + this.suggestion_grid.destroy (); + this.suggestion_grid = null; + } } -- cgit v1.2.1