[tepl/wip/amtk-toolbar] Implement AmtkFactoryToolbar



commit 8d88529177fe29e4cac2b8a1c08d9f36820a7728
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 7 20:18:01 2017 +0200

    Implement AmtkFactoryToolbar

 amtk/Makefile.am                     |    2 +
 amtk/amtk-factory-toolbar.c          |  268 ++++++++++++++++++++++++++++++++++
 amtk/amtk-factory-toolbar.h          |   72 +++++++++
 amtk/amtk-types.h                    |    1 +
 amtk/amtk.h                          |    1 +
 docs/reference/tepl-3.0-sections.txt |   19 +++
 docs/reference/tepl-docs.xml.in      |    1 +
 po/POTFILES.in                       |    1 +
 8 files changed, 365 insertions(+), 0 deletions(-)
---
diff --git a/amtk/Makefile.am b/amtk/Makefile.am
index 10f5ec9..a7f7647 100644
--- a/amtk/Makefile.am
+++ b/amtk/Makefile.am
@@ -19,6 +19,7 @@ amtk_public_headers =                         \
        amtk-application-window.h               \
        amtk-factory.h                          \
        amtk-factory-menu.h                     \
+       amtk-factory-toolbar.h                  \
        amtk-init.h                             \
        amtk-menu-item.h                        \
        amtk-menu-shell.h                       \
@@ -33,6 +34,7 @@ amtk_public_c_files =                         \
        amtk-application-window.c               \
        amtk-factory.c                          \
        amtk-factory-menu.c                     \
+       amtk-factory-toolbar.c                  \
        amtk-init.c                             \
        amtk-menu-item.c                        \
        amtk-menu-shell.c                       \
diff --git a/amtk/amtk-factory-toolbar.c b/amtk/amtk-factory-toolbar.c
new file mode 100644
index 0000000..4392621
--- /dev/null
+++ b/amtk/amtk-factory-toolbar.c
@@ -0,0 +1,268 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2017 - 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
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Amtk is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "amtk-factory-toolbar.h"
+#include "amtk-action-info.h"
+#include "amtk-action-info-central-store.h"
+
+/**
+ * SECTION:amtk-factory-toolbar
+ * @Short_description: A factory that creates #GtkToolItem's
+ * @Title: AmtkFactoryToolbar
+ */
+
+struct _AmtkFactoryToolbarPrivate
+{
+       gint something;
+};
+
+#if 0
+enum
+{
+       PROP_0,
+       PROP_ENABLE_ME,
+       N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES];
+#endif
+
+G_DEFINE_TYPE_WITH_PRIVATE (AmtkFactoryToolbar, amtk_factory_toolbar, AMTK_TYPE_FACTORY)
+
+#if 0
+static void
+amtk_factory_toolbar_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+       AmtkFactoryToolbar *self = AMTK_FACTORY_TOOLBAR (object);
+
+       switch (prop_id)
+       {
+               case PROP_ENABLE_ME:
+                       g_value_set_boolean (value, amtk_factory_toolbar_get_enable_me (self));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+amtk_factory_toolbar_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+       AmtkFactoryToolbar *self = AMTK_FACTORY_TOOLBAR (object);
+
+       switch (prop_id)
+       {
+               case PROP_ENABLE_ME:
+                       amtk_factory_toolbar_set_enable_me (self, g_value_get_boolean (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+#endif
+
+#if 0
+static void
+amtk_factory_toolbar_finalize (GObject *object)
+{
+
+       G_OBJECT_CLASS (amtk_factory_toolbar_parent_class)->finalize (object);
+}
+#endif
+
+static void
+amtk_factory_toolbar_class_init (AmtkFactoryToolbarClass *klass)
+{
+#if 0
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->get_property = amtk_factory_toolbar_get_property;
+       object_class->set_property = amtk_factory_toolbar_set_property;
+       object_class->finalize = amtk_factory_toolbar_finalize;
+
+       properties[PROP_ENABLE_ME] =
+               g_param_spec_boolean ("enable-me",
+                                     "Enable Me",
+                                     "",
+                                     FALSE,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT |
+                                     G_PARAM_STATIC_STRINGS);
+
+       g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+#endif
+}
+
+static void
+amtk_factory_toolbar_init (AmtkFactoryToolbar *factory)
+{
+       factory->priv = amtk_factory_toolbar_get_instance_private (factory);
+}
+
+/**
+ * amtk_factory_toolbar_new:
+ * @application: (nullable): a #GtkApplication, or %NULL.
+ *
+ * Creates a new #AmtkFactoryToolbar object. Associating a #GtkApplication is
+ * optional.
+ *
+ * Returns: a new #AmtkFactoryToolbar.
+ * Since: 3.0
+ */
+AmtkFactoryToolbar *
+amtk_factory_toolbar_new (GtkApplication *application)
+{
+       g_return_val_if_fail (application == NULL || GTK_IS_APPLICATION (application), NULL);
+
+       return g_object_new (AMTK_TYPE_FACTORY_TOOLBAR,
+                            "application", application,
+                            NULL);
+}
+
+/**
+ * amtk_factory_toolbar_new_with_default_application:
+ *
+ * Calls amtk_factory_toolbar_new() with g_application_get_default() (it must be
+ * a #GtkApplication).
+ *
+ * Returns: a new #AmtkFactoryToolbar with the default #GtkApplication.
+ * Since: 3.0
+ */
+AmtkFactoryToolbar *
+amtk_factory_toolbar_new_with_default_application (void)
+{
+       return amtk_factory_toolbar_new (GTK_APPLICATION (g_application_get_default ()));
+}
+
+/**
+ * amtk_factory_toolbar_create_tool_button:
+ * @factory: an #AmtkFactoryToolbar.
+ * @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_toolbar_create_tool_button (AmtkFactoryToolbar *factory,
+                                        const gchar        *action_name)
+{
+       AmtkFactoryFlags default_flags;
+
+       g_return_val_if_fail (AMTK_IS_FACTORY_TOOLBAR (factory), NULL);
+       g_return_val_if_fail (action_name != NULL, NULL);
+
+       default_flags = amtk_factory_get_default_flags (AMTK_FACTORY (factory));
+
+       return amtk_factory_toolbar_create_tool_button_full (factory, action_name, default_flags);
+}
+
+/**
+ * amtk_factory_toolbar_create_tool_button_full:
+ * @factory: an #AmtkFactoryToolbar.
+ * @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_toolbar_create_tool_button_full (AmtkFactoryToolbar *factory,
+                                             const gchar        *action_name,
+                                             AmtkFactoryFlags    flags)
+{
+       AmtkActionInfoCentralStore *central_store;
+       AmtkActionInfo *action_info;
+       GtkToolButton *tool_button;
+       const gchar *icon_name;
+       const gchar *tooltip;
+       GtkApplication *app;
+
+       g_return_val_if_fail (AMTK_IS_FACTORY_TOOLBAR (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);
+       }
+
+       app = amtk_factory_get_application (AMTK_FACTORY (factory));
+       if ((flags & AMTK_FACTORY_IGNORE_ACCELS) == 0 &&
+           (flags & AMTK_FACTORY_IGNORE_ACCELS_FOR_APP) == 0 &&
+           app != NULL)
+       {
+               const gchar * const *accels;
+
+               accels = amtk_action_info_get_accels (action_info);
+               gtk_application_set_accels_for_action (app, action_name, accels);
+       }
+
+       amtk_action_info_mark_as_used (action_info);
+
+       return GTK_TOOL_ITEM (tool_button);
+}
diff --git a/amtk/amtk-factory-toolbar.h b/amtk/amtk-factory-toolbar.h
new file mode 100644
index 0000000..d2eb16f
--- /dev/null
+++ b/amtk/amtk-factory-toolbar.h
@@ -0,0 +1,72 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2017 - 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
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Amtk is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef AMTK_FACTORY_TOOLBAR_H
+#define AMTK_FACTORY_TOOLBAR_H
+
+#if !defined (AMTK_H_INSIDE) && !defined (AMTK_COMPILATION)
+#error "Only <amtk/amtk.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+#include <amtk/amtk-factory.h>
+#include <amtk/amtk-types.h>
+
+G_BEGIN_DECLS
+
+#define AMTK_TYPE_FACTORY_TOOLBAR             (amtk_factory_toolbar_get_type ())
+#define AMTK_FACTORY_TOOLBAR(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), AMTK_TYPE_FACTORY_TOOLBAR, 
AmtkFactoryToolbar))
+#define AMTK_FACTORY_TOOLBAR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), AMTK_TYPE_FACTORY_TOOLBAR, 
AmtkFactoryToolbarClass))
+#define AMTK_IS_FACTORY_TOOLBAR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AMTK_TYPE_FACTORY_TOOLBAR))
+#define AMTK_IS_FACTORY_TOOLBAR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), AMTK_TYPE_FACTORY_TOOLBAR))
+#define AMTK_FACTORY_TOOLBAR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), AMTK_TYPE_FACTORY_TOOLBAR, 
AmtkFactoryToolbarClass))
+
+typedef struct _AmtkFactoryToolbarClass    AmtkFactoryToolbarClass;
+typedef struct _AmtkFactoryToolbarPrivate  AmtkFactoryToolbarPrivate;
+
+struct _AmtkFactoryToolbar
+{
+       AmtkFactory parent;
+
+       AmtkFactoryToolbarPrivate *priv;
+};
+
+struct _AmtkFactoryToolbarClass
+{
+       AmtkFactoryClass parent_class;
+
+       gpointer padding[12];
+};
+
+GType                  amtk_factory_toolbar_get_type                           (void);
+
+AmtkFactoryToolbar *   amtk_factory_toolbar_new                                (GtkApplication *application);
+
+AmtkFactoryToolbar *   amtk_factory_toolbar_new_with_default_application       (void);
+
+GtkToolItem *          amtk_factory_toolbar_create_tool_button                 (AmtkFactoryToolbar *factory,
+                                                                                const gchar        
*action_name);
+
+GtkToolItem *          amtk_factory_toolbar_create_tool_button_full            (AmtkFactoryToolbar *factory,
+                                                                                const gchar        
*action_name,
+                                                                                AmtkFactoryFlags    flags);
+
+G_END_DECLS
+
+#endif /* AMTK_FACTORY_TOOLBAR_H */
diff --git a/amtk/amtk-types.h b/amtk/amtk-types.h
index f6dddb6..d1afa78 100644
--- a/amtk/amtk-types.h
+++ b/amtk/amtk-types.h
@@ -35,6 +35,7 @@ typedef struct _AmtkActionInfoCentralStore    AmtkActionInfoCentralStore;
 typedef struct _AmtkApplicationWindow          AmtkApplicationWindow;
 typedef struct _AmtkFactory                    AmtkFactory;
 typedef struct _AmtkFactoryMenu                        AmtkFactoryMenu;
+typedef struct _AmtkFactoryToolbar             AmtkFactoryToolbar;
 typedef struct _AmtkMenuShell                  AmtkMenuShell;
 
 G_END_DECLS
diff --git a/amtk/amtk.h b/amtk/amtk.h
index 145bd78..667d6c6 100644
--- a/amtk/amtk.h
+++ b/amtk/amtk.h
@@ -32,6 +32,7 @@
 #include <amtk/amtk-application-window.h>
 #include <amtk/amtk-factory.h>
 #include <amtk/amtk-factory-menu.h>
+#include <amtk/amtk-factory-toolbar.h>
 #include <amtk/amtk-init.h>
 #include <amtk/amtk-menu-item.h>
 #include <amtk/amtk-menu-shell.h>
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 7a6b9c3..70cff98 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -138,6 +138,25 @@ amtk_factory_menu_get_type
 </SECTION>
 
 <SECTION>
+<FILE>amtk-factory-toolbar</FILE>
+AmtkFactoryToolbar
+amtk_factory_toolbar_new
+amtk_factory_toolbar_new_with_default_application
+amtk_factory_toolbar_create_tool_button
+amtk_factory_toolbar_create_tool_button_full
+<SUBSECTION Standard>
+AMTK_FACTORY_TOOLBAR
+AMTK_FACTORY_TOOLBAR_CLASS
+AMTK_FACTORY_TOOLBAR_GET_CLASS
+AMTK_IS_FACTORY_TOOLBAR
+AMTK_IS_FACTORY_TOOLBAR_CLASS
+AMTK_TYPE_FACTORY_TOOLBAR
+AmtkFactoryToolbarClass
+AmtkFactoryToolbarPrivate
+amtk_factory_toolbar_get_type
+</SECTION>
+
+<SECTION>
 <FILE>amtk-menu-item</FILE>
 amtk_menu_item_get_long_description
 amtk_menu_item_set_long_description
diff --git a/docs/reference/tepl-docs.xml.in b/docs/reference/tepl-docs.xml.in
index 39b0891..1d059b6 100644
--- a/docs/reference/tepl-docs.xml.in
+++ b/docs/reference/tepl-docs.xml.in
@@ -28,6 +28,7 @@
       <xi:include href="xml/amtk-action-map.xml"/>
       <xi:include href="xml/amtk-factory.xml"/>
       <xi:include href="xml/amtk-factory-menu.xml"/>
+      <xi:include href="xml/amtk-factory-toolbar.xml"/>
       <xi:include href="xml/amtk-menu-item.xml"/>
       <xi:include href="xml/amtk-menu-shell.xml"/>
       <xi:include href="xml/amtk-utils.xml"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5218572..0175c1e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ amtk/amtk-action-map.c
 amtk/amtk-application-window.c
 amtk/amtk-factory.c
 amtk/amtk-factory-menu.c
+amtk/amtk-factory-toolbar.c
 amtk/amtk-init.c
 amtk/amtk-menu-item.c
 amtk/amtk-menu-shell.c


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