Clean up the application's GActions. Bug 775573.

* Use valid names for GActions: replace underscores with dashes in
    'new_contact' and 'change_book'. See GAction.parse_detailed_name ()
    for more info. Removes some Gtk-Warnings on startup.
* Use Gtk.Application.set_accels_for_action() instead of the deprecated
    Gtk.Application.add_accelerator_for_action().
* Use GLib.ActionEntries for clarity.
This commit is contained in:
Niels De Graef 2016-12-03 19:22:22 +01:00
parent 93302b4a44
commit 9910fe5d83
2 changed files with 12 additions and 21 deletions

View file

@ -2,7 +2,7 @@
<menu id="app-menu">
<section>
<item>
<attribute name="action">app.change_book</attribute>
<attribute name="action">app.change-book</attribute>
<attribute name="label" translatable="yes">_Change Address Book…</attribute>
</item>
</section>

View file

@ -31,6 +31,14 @@ public class Contacts.App : Gtk.Application {
private bool is_prepare_scheluded = false;
private bool is_quiescent_scheduled = false;
private const GLib.ActionEntry[] action_entries = {
{ "quit", quit },
{ "help", show_help },
{ "about", show_about },
{ "change-book", change_address_book },
{ "new-contact", new_contact }
};
public void show_contact (Contact? contact) {
window.set_shown_contact (contact);
}
@ -165,27 +173,10 @@ public class Contacts.App : Gtk.Application {
}
private void create_app_menu () {
var action = new GLib.SimpleAction ("quit", null);
action.activate.connect (() => { this.quit (); });
this.add_action (action);
this.add_action_entries (this.action_entries, this);
action = new GLib.SimpleAction ("help", null);
action.activate.connect (() => { show_help (); });
this.add_action (action);
this.add_accelerator ("F1", "app.help", null);
action = new GLib.SimpleAction ("about", null);
action.activate.connect (() => { show_about (); });
this.add_action (action);
action = new GLib.SimpleAction ("change_book", null);
action.activate.connect (() => { change_address_book (); });
this.add_action (action);
action = new GLib.SimpleAction ("new_contact", null);
action.activate.connect (() => { new_contact (); });
this.add_action (action);
this.add_accelerator ("<Primary>n", "app.new_contact", null);
this.set_accels_for_action ("app.help", {"F1"});
this.set_accels_for_action ("app.new-contact", {"<Primary>n"});
var builder = load_ui ("app-menu.ui");
set_app_menu ((MenuModel)builder.get_object ("app-menu"));