summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2018-03-25 20:58:36 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2018-03-25 22:54:06 +0200
commit456ccf698c6b8e76ad1732a5df3e71f3038c2289 (patch)
treede1f92fdda91feff2fffdeb547b9951bb45bf784
parent8f43f9136d84a7562a0f2094d44041ed0d6ea8ea (diff)
downloadgnome-contacts-456ccf698c6b8e76ad1732a5df3e71f3038c2289.tar.gz
ContactPane: clean up suggestion_grid handling.
* Extract a single function to remove the suggestion grid.
-rw-r--r--src/contacts-contact-pane.vala43
1 files 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;
+ }
}