[tepl] AmtkFactory: add functions to create GtkToolButton's
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] AmtkFactory: add functions to create GtkToolButton's
- Date: Tue, 8 Aug 2017 17:38:11 +0000 (UTC)
commit 28a032d2f58fdaefe7ad0356dbb5b7010a242bc4
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Aug 7 19:55:12 2017 +0200
AmtkFactory: add functions to create GtkToolButton's
No need to create an AmtkFactoryToolbar subclass, because there is no
need to add other properties specific for toolbars.
amtk/amtk-factory.c | 105 ++++++++++++++++++++++++++++++++++
amtk/amtk-factory.h | 7 ++
docs/reference/tepl-3.0-sections.txt | 2 +
3 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/amtk/amtk-factory.c b/amtk/amtk-factory.c
index 54b6b4e..cb30cb0 100644
--- a/amtk/amtk-factory.c
+++ b/amtk/amtk-factory.c
@@ -18,6 +18,8 @@
*/
#include "amtk-factory.h"
+#include "amtk-action-info.h"
+#include "amtk-action-info-central-store.h"
#include "amtk-enum-types.h"
/**
@@ -249,3 +251,106 @@ amtk_factory_set_default_flags (AmtkFactory *factory,
g_object_notify_by_pspec (G_OBJECT (factory), properties[PROP_DEFAULT_FLAGS]);
}
}
+
+/**
+ * amtk_factory_create_tool_button:
+ * @factory: an #AmtkFactory.
+ * @action_name: an action name.
+ *
+ * Creates a new #GtkToolButton for @action_name with the
+ * #AmtkFactory:default-flags.
+ *
+ * Returns: (transfer floating): a new #GtkToolButton for @action_name.
+ * Since: 3.0
+ */
+GtkToolItem *
+amtk_factory_create_tool_button (AmtkFactory *factory,
+ const gchar *action_name)
+{
+ g_return_val_if_fail (AMTK_IS_FACTORY (factory), NULL);
+ g_return_val_if_fail (action_name != NULL, NULL);
+
+ return amtk_factory_create_tool_button_full (factory,
+ action_name,
+ factory->priv->default_flags);
+}
+
+/**
+ * amtk_factory_create_tool_button_full:
+ * @factory: an #AmtkFactory.
+ * @action_name: an action name.
+ * @flags: #AmtkFactoryFlags.
+ *
+ * This function ignores the #AmtkFactory:default-flags property and takes the
+ * @flags argument instead.
+ *
+ * Returns: (transfer floating): a new #GtkToolButton for @action_name.
+ * Since: 3.0
+ */
+GtkToolItem *
+amtk_factory_create_tool_button_full (AmtkFactory *factory,
+ const gchar *action_name,
+ AmtkFactoryFlags flags)
+{
+ AmtkActionInfoCentralStore *central_store;
+ AmtkActionInfo *action_info;
+ GtkToolButton *tool_button;
+ const gchar *icon_name;
+ const gchar *tooltip;
+
+ g_return_val_if_fail (AMTK_IS_FACTORY (factory), NULL);
+ g_return_val_if_fail (action_name != NULL, NULL);
+
+ central_store = amtk_action_info_central_store_get_singleton ();
+ action_info = amtk_action_info_central_store_lookup (central_store, action_name);
+
+ if (action_info == NULL)
+ {
+ g_warning ("%s(): action name '%s' not found.",
+ G_STRFUNC,
+ action_name);
+
+ return NULL;
+ }
+
+ tool_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
+
+ if ((flags & AMTK_FACTORY_IGNORE_GACTION) == 0)
+ {
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (tool_button), action_name);
+ }
+
+ if ((flags & AMTK_FACTORY_IGNORE_LABEL) == 0)
+ {
+ gtk_tool_button_set_use_underline (tool_button, TRUE);
+ gtk_tool_button_set_label (tool_button, amtk_action_info_get_label (action_info));
+ }
+
+ icon_name = amtk_action_info_get_icon_name (action_info);
+ if ((flags & AMTK_FACTORY_IGNORE_ICON) == 0 &&
+ icon_name != NULL)
+ {
+ gtk_tool_button_set_icon_name (tool_button, icon_name);
+ }
+
+ tooltip = amtk_action_info_get_tooltip (action_info);
+ if ((flags & AMTK_FACTORY_IGNORE_TOOLTIP) == 0 &&
+ tooltip != NULL)
+ {
+ gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (tool_button), tooltip);
+ }
+
+ if ((flags & AMTK_FACTORY_IGNORE_ACCELS) == 0 &&
+ (flags & AMTK_FACTORY_IGNORE_ACCELS_FOR_APP) == 0 &&
+ factory->priv->app != NULL)
+ {
+ const gchar * const *accels;
+
+ accels = amtk_action_info_get_accels (action_info);
+ gtk_application_set_accels_for_action (factory->priv->app, action_name, accels);
+ }
+
+ amtk_action_info_mark_as_used (action_info);
+
+ return GTK_TOOL_ITEM (tool_button);
+}
diff --git a/amtk/amtk-factory.h b/amtk/amtk-factory.h
index aa44e7b..bf7e51b 100644
--- a/amtk/amtk-factory.h
+++ b/amtk/amtk-factory.h
@@ -93,6 +93,13 @@ AmtkFactoryFlags amtk_factory_get_default_flags (AmtkFactory *factory);
void amtk_factory_set_default_flags (AmtkFactory *factory,
AmtkFactoryFlags default_flags);
+GtkToolItem * amtk_factory_create_tool_button (AmtkFactory *factory,
+ const gchar *action_name);
+
+GtkToolItem * amtk_factory_create_tool_button_full (AmtkFactory *factory,
+ const gchar *action_name,
+ AmtkFactoryFlags flags);
+
G_END_DECLS
#endif /* AMTK_FACTORY_H */
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 7a6b9c3..a69ce76 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -104,6 +104,8 @@ AmtkFactoryFlags
amtk_factory_get_application
amtk_factory_get_default_flags
amtk_factory_set_default_flags
+amtk_factory_create_tool_button
+amtk_factory_create_tool_button_full
<SUBSECTION Standard>
AMTK_FACTORY
AMTK_FACTORY_CLASS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]