app: Add GimpMenuFactoryPrivate

Add GimpMenuFactoryPrivate. Note that we don't introduce a Gimp-getter
since the menu factory is globally accesible and we want to have as
much control as possible in who can get the Gimp instance.
This commit is contained in:
Martin Nordholts 2009-12-06 10:23:05 +01:00
parent b1b560b0c4
commit 482f31cd3f
4 changed files with 48 additions and 32 deletions

View File

@ -120,7 +120,7 @@ debug_dump_menus_cmd_callback (GtkAction *action,
{
GList *list;
for (list = global_menu_factory->registered_menus;
for (list = gimp_menu_factory_get_registered_menus (global_menu_factory);
list;
list = g_list_next (list))
{
@ -161,7 +161,7 @@ debug_dump_managers_cmd_callback (GtkAction *action,
{
GList *list;
for (list = global_menu_factory->registered_menus;
for (list = gimp_menu_factory_get_registered_menus (global_menu_factory);
list;
list = g_list_next (list))
{

View File

@ -377,7 +377,6 @@ menus_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (global_menu_factory != NULL);
g_return_if_fail (global_menu_factory->gimp == gimp);
g_object_unref (global_menu_factory);
global_menu_factory = NULL;

View File

@ -35,6 +35,14 @@
#include "gimpuimanager.h"
struct _GimpMenuFactoryPrivate
{
Gimp *gimp;
GimpActionFactory *action_factory;
GList *registered_menus;
};
static void gimp_menu_factory_finalize (GObject *object);
@ -49,13 +57,16 @@ gimp_menu_factory_class_init (GimpMenuFactoryClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_menu_factory_finalize;
g_type_class_add_private (klass, sizeof (GimpMenuFactoryPrivate));
}
static void
gimp_menu_factory_init (GimpMenuFactory *factory)
{
factory->gimp = NULL;
factory->registered_menus = NULL;
factory->p = G_TYPE_INSTANCE_GET_PRIVATE (factory,
GIMP_TYPE_MENU_FACTORY,
GimpMenuFactoryPrivate);
}
static void
@ -64,7 +75,7 @@ gimp_menu_factory_finalize (GObject *object)
GimpMenuFactory *factory = GIMP_MENU_FACTORY (object);
GList *list;
for (list = factory->registered_menus; list; list = g_list_next (list))
for (list = factory->p->registered_menus; list; list = g_list_next (list))
{
GimpMenuFactoryEntry *entry = list->data;
GList *uis;
@ -89,8 +100,8 @@ gimp_menu_factory_finalize (GObject *object)
g_slice_free (GimpMenuFactoryEntry, entry);
}
g_list_free (factory->registered_menus);
factory->registered_menus = NULL;
g_list_free (factory->p->registered_menus);
factory->p->registered_menus = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -106,8 +117,8 @@ gimp_menu_factory_new (Gimp *gimp,
factory = g_object_new (GIMP_TYPE_MENU_FACTORY, NULL);
factory->gimp = gimp;
factory->action_factory = action_factory;
factory->p->gimp = gimp;
factory->p->action_factory = action_factory;
return factory;
}
@ -131,7 +142,7 @@ gimp_menu_factory_manager_register (GimpMenuFactory *factory,
entry->identifier = g_strdup (identifier);
factory->registered_menus = g_list_prepend (factory->registered_menus, entry);
factory->p->registered_menus = g_list_prepend (factory->p->registered_menus, entry);
va_start (args, first_group);
@ -172,6 +183,14 @@ gimp_menu_factory_manager_register (GimpMenuFactory *factory,
va_end (args);
}
GList *
gimp_menu_factory_get_registered_menus (GimpMenuFactory *factory)
{
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (factory), NULL);
return factory->p->registered_menus;
}
GimpUIManager *
gimp_menu_factory_manager_new (GimpMenuFactory *factory,
const gchar *identifier,
@ -183,7 +202,7 @@ gimp_menu_factory_manager_new (GimpMenuFactory *factory,
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (factory), NULL);
g_return_val_if_fail (identifier != NULL, NULL);
for (list = factory->registered_menus; list; list = g_list_next (list))
for (list = factory->p->registered_menus; list; list = g_list_next (list))
{
GimpMenuFactoryEntry *entry = list->data;
@ -193,7 +212,7 @@ gimp_menu_factory_manager_new (GimpMenuFactory *factory,
GtkAccelGroup *accel_group;
GList *list;
manager = gimp_ui_manager_new (factory->gimp, entry->identifier);
manager = gimp_ui_manager_new (factory->p->gimp, entry->identifier);
gtk_ui_manager_set_add_tearoffs (GTK_UI_MANAGER (manager),
create_tearoff);
@ -205,7 +224,7 @@ gimp_menu_factory_manager_new (GimpMenuFactory *factory,
GList *actions;
GList *list2;
group = gimp_action_factory_group_new (factory->action_factory,
group = gimp_action_factory_group_new (factory->p->action_factory,
(const gchar *) list->data,
callback_data);

View File

@ -43,15 +43,14 @@ struct _GimpMenuFactoryEntry
#define GIMP_MENU_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_MENU_FACTORY, GimpMenuFactoryClass))
typedef struct _GimpMenuFactoryClass GimpMenuFactoryClass;
typedef struct _GimpMenuFactoryPrivate GimpMenuFactoryPrivate;
typedef struct _GimpMenuFactoryClass GimpMenuFactoryClass;
struct _GimpMenuFactory
{
GimpObject parent_instance;
GimpObject parent_instance;
Gimp *gimp;
GimpActionFactory *action_factory;
GList *registered_menus;
GimpMenuFactoryPrivate *p;
};
struct _GimpMenuFactoryClass
@ -60,20 +59,19 @@ struct _GimpMenuFactoryClass
};
GType gimp_menu_factory_get_type (void) G_GNUC_CONST;
GType gimp_menu_factory_get_type (void) G_GNUC_CONST;
GimpMenuFactory * gimp_menu_factory_new (Gimp *gimp,
GimpActionFactory *action_factory);
void gimp_menu_factory_manager_register (GimpMenuFactory *factory,
const gchar *identifier,
const gchar *first_group,
...) G_GNUC_NULL_TERMINATED;
GList * gimp_menu_factory_get_registered_menus (GimpMenuFactory *factory);
GimpUIManager * gimp_menu_factory_manager_new (GimpMenuFactory *factory,
const gchar *identifier,
gpointer callback_data,
gboolean create_tearoff);
GimpMenuFactory * gimp_menu_factory_new (Gimp *gimp,
GimpActionFactory *action_factory);
void gimp_menu_factory_manager_register (GimpMenuFactory *factory,
const gchar *identifier,
const gchar *first_group,
...) G_GNUC_NULL_TERMINATED;
GimpUIManager * gimp_menu_factory_manager_new (GimpMenuFactory *factory,
const gchar *identifier,
gpointer callback_data,
gboolean create_tearoff);
#endif /* __GIMP_MENU_FACTORY_H__ */