summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2023-02-11 08:15:46 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2023-02-12 09:10:56 +0000
commit34869e2f15844bee8938df2a4ccde14fbe662e2b (patch)
tree1f2199a318009b480fe99cb7d68fdf80f1a7023f /src
parent7466463ee1b435d83c6f6d6aaa46029d2bba65a7 (diff)
downloadgnome-contacts-34869e2f15844bee8938df2a4ccde14fbe662e2b.tar.gz
editor: Allow removing a birthday
Add a little trash button at the end of the row so we can actually unset a birthday too. Fixes: https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/280
Diffstat (limited to 'src')
-rw-r--r--src/contacts-contact-editor.vala45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index 80b5d35..b90384d 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -462,30 +462,49 @@ public class Contacts.PersonaEditor : Gtk.Widget {
row.add_prefix (new Gtk.Image.from_icon_name ("birthday-symbolic"));
row.title = _("Birthday");
- Gtk.Button button;
- if (bd_chunk.birthday == null) {
- button = new Gtk.Button.with_label (_("Set Birthday"));
- } else {
- button = new Gtk.Button.with_label (bd_chunk.birthday.to_local ().format ("%x"));
- }
- button.valign = Gtk.Align.CENTER;
- button.clicked.connect (() => {
+ // Show a button to set the date (and show it if set)
+ var bd_button = new Gtk.Button ();
+ bd_button.valign = Gtk.Align.CENTER;
+ update_birthday_button (bd_button, bd_chunk);
+ bd_button.clicked.connect (() => {
unowned var parent_window = get_root () as Gtk.Window;
var dialog = new BirthdayEditor (parent_window, bd_chunk.birthday);
dialog.changed.connect (() => {
- if (dialog.is_set) {
+ if (dialog.is_set)
bd_chunk.birthday = dialog.get_birthday ();
- button.set_label (bd_chunk.birthday.to_local ().format ("%x"));
- }
});
dialog.present ();
});
- row.add_suffix (button);
- row.set_activatable_widget (button);
+ row.add_suffix (bd_button);
+ row.set_activatable_widget (bd_button);
+
+ // Add a remove button
+ var remove_button = new Gtk.Button ();
+ remove_button.icon_name = "user-trash-symbolic";
+ remove_button.tooltip_text = _("Remove birthday");
+ remove_button.valign = Gtk.Align.CENTER;
+ remove_button.add_css_class ("flat");
+ remove_button.sensitive = (bd_chunk.birthday != null);
+ remove_button.clicked.connect ((b) => { bd_chunk.birthday = null; });
+ row.add_suffix (remove_button);
+
+ // Update both buttons on any changes
+ bd_chunk.notify["birthday"].connect ((obj, pspec) => {
+ update_birthday_button (bd_button, bd_chunk);
+ remove_button.sensitive = (bd_chunk.birthday != null);
+ });
return new ContactEditorProperty (row);
}
+ private void update_birthday_button (Gtk.Button bd_button, BirthdayChunk bd_chunk) {
+ if (bd_chunk.birthday == null) {
+ bd_button.label = _("Set Birthday");
+ } else {
+ bd_button.label = bd_chunk.birthday.to_local ().format ("%x");
+ }
+ }
+
private Gtk.Widget create_widget_for_addresses (Chunk chunk)
requires (chunk is AddressesChunk) {
unowned var addresses_chunk = (AddressesChunk) chunk;