[gnome-contacts] Clean up the application's GActions. Bug 775573.



commit 9910fe5d8322f3cf70e27eef77d7bbc605fe3b1d
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Dec 3 19:22:22 2016 +0100

    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.

 data/ui/app-menu.ui   |    2 +-
 src/contacts-app.vala |   33 ++++++++++++---------------------
 2 files changed, 13 insertions(+), 22 deletions(-)
---
diff --git a/data/ui/app-menu.ui b/data/ui/app-menu.ui
index 9711cb9..852515a 100644
--- a/data/ui/app-menu.ui
+++ b/data/ui/app-menu.ui
@@ -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>
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 050569b..89919a4 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -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);
-
-    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.add_action_entries (this.action_entries, this);
+
+    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"));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]