diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2023-02-11 23:51:32 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2023-02-12 09:22:09 +0000 |
commit | cf0987c7dab429c86f3295c440dbfd0ad957c406 (patch) | |
tree | 8b9948feb5c4edebb3a42449fcc68109d22b9b7b | |
parent | 34869e2f15844bee8938df2a4ccde14fbe662e2b (diff) | |
download | gnome-contacts-cf0987c7dab429c86f3295c440dbfd0ad957c406.tar.gz |
Add shortcuts for saving/canceling contact edit
Allow saving a contact by pressing `<Ctrl>Enter` or cancelling by
pressing `Escape`.
-rw-r--r-- | data/gtk/help-overlay.ui | 17 | ||||
-rw-r--r-- | data/ui/contacts-main-window.ui | 18 | ||||
-rw-r--r-- | src/contacts-main-window.vala | 30 |
3 files changed, 54 insertions, 11 deletions
diff --git a/data/gtk/help-overlay.ui b/data/gtk/help-overlay.ui index f847085..b7ab13a 100644 --- a/data/gtk/help-overlay.ui +++ b/data/gtk/help-overlay.ui @@ -49,6 +49,23 @@ </child> </object> </child> + <child> + <object class="GtkShortcutsGroup"> + <property name="title" translatable="yes" context="shortcut window">Editing or creating a contact</property> + <child> + <object class="GtkShortcutsShortcut"> + <property name="accelerator"><Control>Return</property> + <property name="title" translatable="yes" context="shortcut window">Save current changes to contact</property> + </object> + </child> + <child> + <object class="GtkShortcutsShortcut"> + <property name="accelerator">Escape</property> + <property name="title" translatable="yes" context="shortcut window">Cancel current changes for contact</property> + </object> + </child> + </object> + </child> </object> </child> </object> diff --git a/data/ui/contacts-main-window.ui b/data/ui/contacts-main-window.ui index d40f2f4..206d172 100644 --- a/data/ui/contacts-main-window.ui +++ b/data/ui/contacts-main-window.ui @@ -79,6 +79,18 @@ <property name="action">action(win.focus-search)</property> </object> </child> + <child> + <object class="GtkShortcut"> + <property name="trigger">Escape</property> + <property name="action">action(win.edit-contact-cancel)</property> + </object> + </child> + <child> + <object class="GtkShortcut"> + <property name="trigger"><Control>Return</property> + <property name="action">action(win.edit-contact-save)</property> + </object> + </child> </object> </child> @@ -270,8 +282,7 @@ <property name="label" translatable="yes">_Cancel</property> <property name="use_underline">True</property> <signal name="notify::visible" handler="on_cancel_visible" object="ContactsMainWindow" after="yes" swapped="no"/> - <property name="action-name">win.stop-editing-contact</property> - <property name="action-target">true</property> + <property name="action-name">win.edit-contact-cancel</property> </object> </child> <child type="end"> @@ -302,8 +313,7 @@ <property name="use_underline">True</property> <property name="label" translatable="yes">Done</property> <property name="valign">center</property> - <property name="action-name">win.stop-editing-contact</property> - <property name="action-target">false</property> + <property name="action-name">win.edit-contact-save</property> <style> <class name="suggested-action"/> </style> diff --git a/src/contacts-main-window.vala b/src/contacts-main-window.vala index 684d3bc..8d46b6b 100644 --- a/src/contacts-main-window.vala +++ b/src/contacts-main-window.vala @@ -24,7 +24,8 @@ public class Contacts.MainWindow : Adw.ApplicationWindow { private const GLib.ActionEntry[] ACTION_ENTRIES = { { "new-contact", new_contact }, { "edit-contact", edit_contact }, - { "stop-editing-contact", stop_editing_contact, "b" }, + { "edit-contact-cancel", edit_contact_cancel }, + { "edit-contact-save", edit_contact_save }, { "focus-search", focus_search }, { "toggle-favorite", toggle_favorite }, { "link-marked-contacts", link_marked_contacts }, @@ -347,19 +348,34 @@ public class Contacts.MainWindow : Adw.ApplicationWindow { }); } - private void stop_editing_contact (SimpleAction action, GLib.Variant? parameter) { - bool cancel = parameter.get_boolean (); + private void edit_contact_save (SimpleAction action, GLib.Variant? parameter) { + if (this.state != UiState.CREATING && this.state != UiState.UPDATING) + return; if (this.state == UiState.CREATING) { - if (cancel) { - show_list_pane (); - } this.state = UiState.NORMAL; } else { show_contact_pane (); this.state = UiState.SHOWING; } - this.contact_pane.stop_editing (cancel); + this.contact_pane.stop_editing (false); + this.contacts_list.scroll_to_selected (); + + this.right_header.title_widget = new Adw.WindowTitle ("", ""); + } + + private void edit_contact_cancel (SimpleAction action, GLib.Variant? parameter) { + if (this.state != UiState.CREATING && this.state != UiState.UPDATING) + return; + + if (this.state == UiState.CREATING) { + show_list_pane (); + this.state = UiState.NORMAL; + } else { + show_contact_pane (); + this.state = UiState.SHOWING; + } + this.contact_pane.stop_editing (true); this.contacts_list.scroll_to_selected (); this.right_header.title_widget = new Adw.WindowTitle ("", ""); |