[tepl] AmtkFactoryMenu: subclass AmtkFactory
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] AmtkFactoryMenu: subclass AmtkFactory
- Date: Mon, 17 Jul 2017 13:18:32 +0000 (UTC)
commit 3c85244d7cf553e2bc59ce2f04ddc76e2b0d8e1d
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 17 15:14:51 2017 +0200
AmtkFactoryMenu: subclass AmtkFactory
amtk/amtk-factory-menu.c | 121 +++-------------------------------
amtk/amtk-factory-menu.h | 7 +-
docs/reference/tepl-3.0-sections.txt | 1 -
3 files changed, 12 insertions(+), 117 deletions(-)
---
diff --git a/amtk/amtk-factory-menu.c b/amtk/amtk-factory-menu.c
index 736e418..c04ecd5 100644
--- a/amtk/amtk-factory-menu.c
+++ b/amtk/amtk-factory-menu.c
@@ -28,107 +28,18 @@
* @Title: AmtkFactoryMenu
*
* #AmtkFactoryMenu permits to create #GtkMenuItem's from #AmtkActionInfo's.
- *
- * A #GtkApplication can be associated so that when a menu item is created,
- * gtk_application_set_accels_for_action() is called. See
- * amtk_factory_menu_create_menu_item() for more details.
*/
struct _AmtkFactoryMenuPrivate
{
- GtkApplication *app;
-};
-
-enum
-{
- PROP_0,
- PROP_APPLICATION,
- N_PROPERTIES
+ gint something;
};
-static GParamSpec *properties[N_PROPERTIES];
-
-G_DEFINE_TYPE_WITH_PRIVATE (AmtkFactoryMenu, amtk_factory_menu, G_TYPE_OBJECT)
-
-static void
-amtk_factory_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- AmtkFactoryMenu *factory = AMTK_FACTORY_MENU (object);
-
- switch (prop_id)
- {
- case PROP_APPLICATION:
- g_value_set_object (value, amtk_factory_menu_get_application (factory));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-amtk_factory_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- AmtkFactoryMenu *factory = AMTK_FACTORY_MENU (object);
-
- switch (prop_id)
- {
- case PROP_APPLICATION:
- g_assert (factory->priv->app == NULL);
- factory->priv->app = g_value_dup_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-amtk_factory_menu_dispose (GObject *object)
-{
- AmtkFactoryMenu *factory = AMTK_FACTORY_MENU (object);
-
- g_clear_object (&factory->priv->app);
-
- G_OBJECT_CLASS (amtk_factory_menu_parent_class)->dispose (object);
-}
+G_DEFINE_TYPE_WITH_PRIVATE (AmtkFactoryMenu, amtk_factory_menu, AMTK_TYPE_FACTORY)
static void
amtk_factory_menu_class_init (AmtkFactoryMenuClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = amtk_factory_menu_get_property;
- object_class->set_property = amtk_factory_menu_set_property;
- object_class->dispose = amtk_factory_menu_dispose;
-
- /**
- * AmtkFactoryMenu:application:
- *
- * The associated #GtkApplication. #AmtkFactoryMenu has a strong
- * reference to the #GtkApplication (which means that once the menu is
- * created you should free the #AmtkFactoryMenu).
- *
- * Since: 3.0
- */
- properties[PROP_APPLICATION] =
- g_param_spec_object ("application",
- "GtkApplication",
- "",
- GTK_TYPE_APPLICATION,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
@@ -160,7 +71,8 @@ amtk_factory_menu_new (GtkApplication *application)
/**
* amtk_factory_menu_new_with_default_application:
*
- * Calls amtk_factory_menu_new() with g_application_get_default().
+ * Calls amtk_factory_menu_new() with g_application_get_default() (it must be a
+ * #GtkApplication).
*
* Returns: a new #AmtkFactoryMenu with the default #GtkApplication.
* Since: 3.0
@@ -172,21 +84,6 @@ amtk_factory_menu_new_with_default_application (void)
}
/**
- * amtk_factory_menu_get_application:
- * @factory: an #AmtkFactoryMenu.
- *
- * Returns: (transfer none): the #AmtkFactoryMenu:application.
- * Since: 3.0
- */
-GtkApplication *
-amtk_factory_menu_get_application (AmtkFactoryMenu *factory)
-{
- g_return_val_if_fail (AMTK_IS_FACTORY_MENU (factory), NULL);
-
- return factory->priv->app;
-}
-
-/**
* amtk_factory_menu_create_menu_item:
* @factory: an #AmtkFactoryMenu.
* @action_name: an action name.
@@ -200,7 +97,7 @@ amtk_factory_menu_get_application (AmtkFactoryMenu *factory)
* The icon is set. And the tooltip is set with
* amtk_menu_item_set_long_description().
*
- * If the #AmtkFactoryMenu:application is non-%NULL, this function also calls
+ * If the #AmtkFactory:application is non-%NULL, this function also calls
* gtk_application_set_accels_for_action() with the accelerators returned by
* amtk_action_info_get_accels() (this will erase previously set accelerators
* for that action, if any).
@@ -218,6 +115,7 @@ amtk_factory_menu_create_menu_item (AmtkFactoryMenu *factory,
const gchar * const *accels;
const gchar *icon_name;
const gchar *tooltip;
+ GtkApplication *app;
g_return_val_if_fail (AMTK_IS_FACTORY_MENU (factory), NULL);
g_return_val_if_fail (action_name != NULL, NULL);
@@ -276,11 +174,10 @@ amtk_factory_menu_create_menu_item (AmtkFactoryMenu *factory,
amtk_menu_item_set_long_description (menu_item, tooltip);
}
- if (factory->priv->app != NULL)
+ app = amtk_factory_get_application (AMTK_FACTORY (factory));
+ if (app != NULL)
{
- gtk_application_set_accels_for_action (factory->priv->app,
- action_name,
- accels);
+ gtk_application_set_accels_for_action (app, action_name, accels);
}
amtk_action_info_mark_as_used (action_info);
diff --git a/amtk/amtk-factory-menu.h b/amtk/amtk-factory-menu.h
index 9a918bd..ee80330 100644
--- a/amtk/amtk-factory-menu.h
+++ b/amtk/amtk-factory-menu.h
@@ -25,6 +25,7 @@
#endif
#include <gtk/gtk.h>
+#include <amtk/amtk-factory.h>
#include <amtk/amtk-types.h>
G_BEGIN_DECLS
@@ -41,14 +42,14 @@ typedef struct _AmtkFactoryMenuPrivate AmtkFactoryMenuPrivate;
struct _AmtkFactoryMenu
{
- GObject parent;
+ AmtkFactory parent;
AmtkFactoryMenuPrivate *priv;
};
struct _AmtkFactoryMenuClass
{
- GObjectClass parent_class;
+ AmtkFactoryClass parent_class;
};
GType amtk_factory_menu_get_type (void);
@@ -57,8 +58,6 @@ AmtkFactoryMenu * amtk_factory_menu_new (GtkApplication
*application);
AmtkFactoryMenu * amtk_factory_menu_new_with_default_application (void);
-GtkApplication * amtk_factory_menu_get_application (AmtkFactoryMenu *factory);
-
GtkWidget * amtk_factory_menu_create_menu_item (AmtkFactoryMenu *factory,
const gchar *action_name);
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 25dcba5..a9d60e2 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -111,7 +111,6 @@ amtk_factory_get_type
AmtkFactoryMenu
amtk_factory_menu_new
amtk_factory_menu_new_with_default_application
-amtk_factory_menu_get_application
amtk_factory_menu_create_menu_item
<SUBSECTION Standard>
AMTK_FACTORY_MENU
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]