[tepl] AmtkFactory: add functions to create GtkMenuToolButton's



commit 8d71792e4bfa3cb6d9264a0a4b9147d4ab61af72
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Aug 10 15:55:01 2017 +0200

    AmtkFactory: add functions to create GtkMenuToolButton's

 amtk/amtk-factory.c                  |  116 +++++++++++++++++++++++++++-------
 amtk/amtk-factory.h                  |    7 ++
 docs/reference/tepl-3.0-sections.txt |    2 +
 3 files changed, 103 insertions(+), 22 deletions(-)
---
diff --git a/amtk/amtk-factory.c b/amtk/amtk-factory.c
index 863dfde..2b1b9dd 100644
--- a/amtk/amtk-factory.c
+++ b/amtk/amtk-factory.c
@@ -440,6 +440,45 @@ common_create (AmtkFactory       *factory,
        return action_info;
 }
 
+static AmtkActionInfo *
+common_create_tool_button (AmtkFactory       *factory,
+                          const gchar       *action_name,
+                          AmtkFactoryFlags   flags,
+                          GtkToolButton    **tool_button)
+{
+       AmtkActionInfo *action_info;
+       const gchar *icon_name;
+       const gchar *tooltip;
+
+       action_info = common_create (factory, action_name, flags, (GtkWidget **)tool_button);
+       if (action_info == NULL)
+       {
+               return NULL;
+       }
+
+       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);
+       }
+
+       return action_info;
+}
+
 /**
  * amtk_factory_create_menu_item:
  * @factory: an #AmtkFactory.
@@ -587,43 +626,76 @@ amtk_factory_create_tool_button_full (AmtkFactory      *factory,
                                      const gchar      *action_name,
                                      AmtkFactoryFlags  flags)
 {
-       GtkWidget *widget;
        GtkToolButton *tool_button;
        AmtkActionInfo *action_info;
-       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);
 
-       widget = GTK_WIDGET (gtk_tool_button_new (NULL, NULL));
-       tool_button = GTK_TOOL_BUTTON (widget);
+       tool_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
 
-       action_info = common_create (factory, action_name, flags, &widget);
+       action_info = common_create_tool_button (factory, action_name, flags, &tool_button);
        if (action_info == NULL)
        {
                return NULL;
        }
 
-       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));
-       }
+       return GTK_TOOL_ITEM (tool_button);
+}
 
-       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);
-       }
+/**
+ * amtk_factory_create_menu_tool_button:
+ * @factory: an #AmtkFactory.
+ * @action_name: an action name.
+ *
+ * Creates a new #GtkMenuToolButton for @action_name with the
+ * #AmtkFactory:default-flags.
+ *
+ * Returns: (transfer floating): a new #GtkMenuToolButton for @action_name.
+ * Since: 3.0
+ */
+GtkMenuToolButton *
+amtk_factory_create_menu_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);
 
-       tooltip = amtk_action_info_get_tooltip (action_info);
-       if ((flags & AMTK_FACTORY_IGNORE_TOOLTIP) == 0 &&
-           tooltip != NULL)
+       return amtk_factory_create_menu_tool_button_full (factory,
+                                                         action_name,
+                                                         factory->priv->default_flags);
+}
+
+/**
+ * amtk_factory_create_menu_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 #GtkMenuToolButton for @action_name.
+ * Since: 3.0
+ */
+GtkMenuToolButton *
+amtk_factory_create_menu_tool_button_full (AmtkFactory      *factory,
+                                          const gchar      *action_name,
+                                          AmtkFactoryFlags  flags)
+{
+       GtkToolButton *menu_tool_button;
+       AmtkActionInfo *action_info;
+
+       g_return_val_if_fail (AMTK_IS_FACTORY (factory), NULL);
+       g_return_val_if_fail (action_name != NULL, NULL);
+
+       menu_tool_button = GTK_TOOL_BUTTON (gtk_menu_tool_button_new (NULL, NULL));
+
+       action_info = common_create_tool_button (factory, action_name, flags, &menu_tool_button);
+       if (action_info == NULL)
        {
-               gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (tool_button), tooltip);
+               return NULL;
        }
 
-       return GTK_TOOL_ITEM (tool_button);
+       return GTK_MENU_TOOL_BUTTON (menu_tool_button);
 }
diff --git a/amtk/amtk-factory.h b/amtk/amtk-factory.h
index 4a6483d..b2494b8 100644
--- a/amtk/amtk-factory.h
+++ b/amtk/amtk-factory.h
@@ -111,6 +111,13 @@ GtkToolItem *              amtk_factory_create_tool_button_full            (AmtkFactory  
    *factory,
                                                                         const gchar      *action_name,
                                                                         AmtkFactoryFlags  flags);
 
+GtkMenuToolButton *    amtk_factory_create_menu_tool_button            (AmtkFactory *factory,
+                                                                        const gchar *action_name);
+
+GtkMenuToolButton *    amtk_factory_create_menu_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 8813eaa..91ae96e 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -111,6 +111,8 @@ amtk_factory_create_menu_item
 amtk_factory_create_menu_item_full
 amtk_factory_create_tool_button
 amtk_factory_create_tool_button_full
+amtk_factory_create_menu_tool_button
+amtk_factory_create_menu_tool_button_full
 <SUBSECTION Standard>
 AMTK_FACTORY
 AMTK_FACTORY_CLASS


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