[amtk] ActionInfoStore: add set_all_accels_to_app()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [amtk] ActionInfoStore: add set_all_accels_to_app()
- Date: Fri, 13 Apr 2018 13:36:47 +0000 (UTC)
commit cca6599214535aeda3f9bd23023b776d412af3bf
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Apr 13 14:53:34 2018 +0200
ActionInfoStore: add set_all_accels_to_app()
amtk/amtk-action-info-store.c | 58 +++++++++++++++++++++++++++++++++-
amtk/amtk-action-info-store.h | 7 +++-
amtk/amtk-factory.c | 4 ++-
docs/reference/amtk-5.0-sections.txt | 1 +
4 files changed, 66 insertions(+), 4 deletions(-)
---
diff --git a/amtk/amtk-action-info-store.c b/amtk/amtk-action-info-store.c
index 0308af2..642cc9c 100644
--- a/amtk/amtk-action-info-store.c
+++ b/amtk/amtk-action-info-store.c
@@ -1,7 +1,7 @@
/*
* This file is part of Amtk - Actions, Menus and Toolbars Kit
*
- * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2017, 2018 - Sébastien Wilmet <swilmet gnome org>
*
* Amtk is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -196,6 +196,62 @@ amtk_action_info_store_lookup (AmtkActionInfoStore *store,
}
static void
+set_accels_to_app_cb (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ const gchar *action_name = key;
+ const AmtkActionInfo *action_info = value;
+ GtkApplication *application = GTK_APPLICATION (user_data);
+ const gchar * const *accels;
+
+ accels = amtk_action_info_get_accels (action_info);
+ gtk_application_set_accels_for_action (application, action_name, accels);
+}
+
+/**
+ * amtk_action_info_store_set_all_accels_to_app:
+ * @store: an #AmtkActionInfoStore.
+ * @application: a #GtkApplication.
+ *
+ * Calls gtk_application_set_accels_for_action() for all #AmtkActionInfo's part
+ * of @store with the accelerators returned by amtk_action_info_get_accels().
+ * This function does *not* call amtk_action_info_mark_as_used(), because if it
+ * did it would not be possible to detect dead code in @store with
+ * amtk_action_info_store_check_all_used().
+ *
+ * This function is not recommended if @store is provided by a library, because
+ * a future version of the library may add accelerators that are not wanted in
+ * the application. So for a library store, you should let #AmtkFactory call
+ * gtk_application_set_accels_for_action().
+ *
+ * This function can be convenient for an application store, in combination with
+ * %AMTK_FACTORY_IGNORE_ACCELS_FOR_APP (and/or having a %NULL #GtkApplication in
+ * #AmtkFactory). It has the advantage that
+ * gtk_application_set_accels_for_action() is called only once per action, not
+ * each time that a #GtkApplicationWindow is created.
+ *
+ * This function can also be useful if – for some actions – the objects are not
+ * created directly with #AmtkFactory on application startup, but are created
+ * later, on demand. For example to create a #GtkShortcutsWindow with
+ * #AmtkFactory, containing information about actions that are not added to any
+ * menu or toolbar.
+ *
+ * Since: 5.0
+ */
+void
+amtk_action_info_store_set_all_accels_to_app (AmtkActionInfoStore *store,
+ GtkApplication *application)
+{
+ g_return_if_fail (AMTK_IS_ACTION_INFO_STORE (store));
+ g_return_if_fail (GTK_IS_APPLICATION (application));
+
+ g_hash_table_foreach (store->priv->hash_table,
+ set_accels_to_app_cb,
+ application);
+}
+
+static void
check_used_cb (gpointer key,
gpointer value,
gpointer user_data)
diff --git a/amtk/amtk-action-info-store.h b/amtk/amtk-action-info-store.h
index 9462ec8..24d7db4 100644
--- a/amtk/amtk-action-info-store.h
+++ b/amtk/amtk-action-info-store.h
@@ -1,7 +1,7 @@
/*
* This file is part of Amtk - Actions, Menus and Toolbars Kit
*
- * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2017, 2018 - Sébastien Wilmet <swilmet gnome org>
*
* Amtk is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
@@ -24,7 +24,7 @@
#error "Only <amtk/amtk.h> can be included directly."
#endif
-#include <glib-object.h>
+#include <gtk/gtk.h>
#include <amtk/amtk-types.h>
G_BEGIN_DECLS
@@ -68,6 +68,9 @@ void amtk_action_info_store_add_entries (AmtkActionInfoStore
*store,
AmtkActionInfo * amtk_action_info_store_lookup (AmtkActionInfoStore *store,
const gchar *action_name);
+void amtk_action_info_store_set_all_accels_to_app (AmtkActionInfoStore *store,
+ GtkApplication *application);
+
void amtk_action_info_store_check_all_used (AmtkActionInfoStore *store);
G_END_DECLS
diff --git a/amtk/amtk-factory.c b/amtk/amtk-factory.c
index c8e3b05..84eed92 100644
--- a/amtk/amtk-factory.c
+++ b/amtk/amtk-factory.c
@@ -38,7 +38,9 @@
* that action, if any). Note that gtk_application_set_accels_for_action() is
* called by factory functions and not by amtk_action_info_store_add(), so that
* libraries can provide their own store and the accelerators are set to the
- * #GtkApplication only if an #AmtkActionInfo is actually used.
+ * #GtkApplication only if an #AmtkActionInfo is actually used. For an
+ * application store, amtk_action_info_store_set_all_accels_to_app() is an
+ * alternative.
*
* #AmtkFactoryFlags permits to control how a factory function creates the
* object, to ignore some steps. Factory functions are declined in two variants:
diff --git a/docs/reference/amtk-5.0-sections.txt b/docs/reference/amtk-5.0-sections.txt
index 229ea89..f11981e 100644
--- a/docs/reference/amtk-5.0-sections.txt
+++ b/docs/reference/amtk-5.0-sections.txt
@@ -63,6 +63,7 @@ amtk_action_info_store_new
amtk_action_info_store_add
amtk_action_info_store_add_entries
amtk_action_info_store_lookup
+amtk_action_info_store_set_all_accels_to_app
amtk_action_info_store_check_all_used
<SUBSECTION Standard>
AMTK_ACTION_INFO_STORE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]