Correctly translated & sorted plug-in actions & menu entries:

2004-04-27  Michael Natterer  <mitch@gimp.org>

	Correctly translated & sorted plug-in actions & menu entries:

	* app/widgets/gimpuimanager.[ch]: added a "gchar *name" property
	and a hash table which keeps all created UI managers (similar to
	GimpActionGroup's hash table). Added function
	gimp_ui_managers_from_name() which returns a list of all managers
	with the given name.

	* app/widgets/gimpmenufactory.c: register a name per UI manager
	and pass the name to gimp_ui_manager_new().

	* app/actions/plug-in-actions.c: added code which correctly
	translates the created plug-in actions and also creates translated
	menu actions for the plug-in's menu_path elements.

	* app/gui/plug-in-menus.[ch]: sort the plug-ins' menu entries
	using a GTree. For each entry, recursivlely create submenus
	from the dynamic menu actions created above before creating
	the plug-in's menu entry itself.

	* app/gui/image-menu.c (image_menu_setup2)
	* app/gui/toolbox-menu.c (toolbox_menu_setup2): call
	plug_in_menus_create2().

	* app/gui/gui-vtable.c (gui_menus_create_entry)
	(gui_menus_delete_entry): added some uglyness which maps old <Prefix>
	menu identifiers to new-style UI manager plus ui_path tuples and
	call plug_in_menus_add,remove_proc() accordingly.

	* menus/image-menu.xml
	* menus/toolbox-menu.xml: added name="Foo" attributes to all menus
	so plug-in entries find their place.
This commit is contained in:
Michael Natterer
2004-04-27 12:28:27 +00:00
committed by Michael Natterer
parent 11309f8e5e
commit 4e8105c12f
16 changed files with 721 additions and 90 deletions

View File

@ -1,3 +1,38 @@
2004-04-27 Michael Natterer <mitch@gimp.org>
Correctly translated & sorted plug-in actions & menu entries:
* app/widgets/gimpuimanager.[ch]: added a "gchar *name" property
and a hash table which keeps all created UI managers (similar to
GimpActionGroup's hash table). Added function
gimp_ui_managers_from_name() which returns a list of all managers
with the given name.
* app/widgets/gimpmenufactory.c: register a name per UI manager
and pass the name to gimp_ui_manager_new().
* app/actions/plug-in-actions.c: added code which correctly
translates the created plug-in actions and also creates translated
menu actions for the plug-in's menu_path elements.
* app/gui/plug-in-menus.[ch]: sort the plug-ins' menu entries
using a GTree. For each entry, recursivlely create submenus
from the dynamic menu actions created above before creating
the plug-in's menu entry itself.
* app/gui/image-menu.c (image_menu_setup2)
* app/gui/toolbox-menu.c (toolbox_menu_setup2): call
plug_in_menus_create2().
* app/gui/gui-vtable.c (gui_menus_create_entry)
(gui_menus_delete_entry): added some uglyness which maps old <Prefix>
menu identifiers to new-style UI manager plus ui_path tuples and
call plug_in_menus_add,remove_proc() accordingly.
* menus/image-menu.xml
* menus/toolbox-menu.xml: added name="Foo" attributes to all menus
so plug-in entries find their place.
2004-04-27 Michael Natterer <mitch@gimp.org>
* app/gui/gui.c (gui_restore_callback): call actions_init()

View File

@ -50,6 +50,15 @@
#include "gimp-intl.h"
/* local function prototypes */
static void plug_in_actions_build_path (GimpActionGroup *group,
const gchar *path_original,
const gchar *path_translated);
/* private variables */
static GimpActionEntry plug_in_actions[] =
{
{ "plug-in-menu", NULL, N_("Filte_rs") },
@ -131,7 +140,7 @@ plug_in_actions_update (GimpActionGroup *group,
{
GimpImage *gimage = NULL;
GimpImageType type = -1;
GList *list;
GSList *list;
if (GIMP_IS_ITEM_TREE_VIEW (data))
gimage = GIMP_ITEM_TREE_VIEW (data)->gimage;
@ -254,12 +263,13 @@ void
plug_in_actions_add_proc (GimpActionGroup *group,
PlugInProcDef *proc_def)
{
GimpActionEntry entry;
const gchar *progname;
const gchar *locale_domain;
const gchar *help_domain;
gchar *label;
gchar *help_id;
const gchar *progname;
const gchar *locale_domain;
const gchar *help_domain;
gchar *path_original;
gchar *path_translated;
gchar *help_id;
gchar *p1, *p2;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (proc_def != NULL);
@ -271,27 +281,44 @@ plug_in_actions_add_proc (GimpActionGroup *group,
help_id = plug_in_proc_def_get_help_id (proc_def, help_domain);
label = g_strdup (strrchr (proc_def->menu_path, '/') + 1);
path_original = g_strdup (proc_def->menu_path);
path_translated = g_strdup (dgettext (locale_domain, path_original));
entry.name = proc_def->db_info.name;
entry.stock_id = NULL;
entry.label = label;
entry.accelerator = proc_def->accelerator;
entry.tooltip = NULL;
entry.callback = G_CALLBACK (plug_in_run_cmd_callback);
entry.help_id = help_id;
p1 = strrchr (path_original, '/');
p2 = strrchr (path_translated, '/');
g_print ("adding plug-in action '%s' (%s)\n",
entry.name, label);
if (p1 && p2)
{
gchar *label;
GtkAction *action;
g_object_set (group, "translation-domain", locale_domain, NULL);
label = p2 + 1;
gimp_action_group_add_actions (group, &entry, 1, &proc_def->db_info);
g_print ("adding plug-in action '%s' (%s)\n",
proc_def->db_info.name, label);
g_object_set (group, "translation-domain", NULL, NULL);
action = gtk_action_new (proc_def->db_info.name, label, NULL, NULL);
g_free (label);
g_free (help_id);
g_signal_connect (action, "activate",
G_CALLBACK (plug_in_run_cmd_callback),
&proc_def->db_info);
gtk_action_group_add_action_with_accel (GTK_ACTION_GROUP (group),
action,
proc_def->accelerator);
g_object_unref (action);
g_free (help_id);
*p1 = '\0';
*p2 = '\0';
plug_in_actions_build_path (group, path_original, path_translated);
g_free (path_original);
g_free (path_translated);
}
}
void
@ -314,3 +341,60 @@ plug_in_actions_remove_proc (GimpActionGroup *group,
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
}
}
/* private functions */
static void
plug_in_actions_build_path (GimpActionGroup *group,
const gchar *path_original,
const gchar *path_translated)
{
GHashTable *path_table;
gchar *p1, *p2;
path_table = g_object_get_data (G_OBJECT (group), "plug-in-path-table");
if (! path_table)
{
path_table = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
g_object_set_data_full (G_OBJECT (group), "plug-in-path-table",
path_table,
(GDestroyNotify) g_hash_table_destroy);
}
p1 = strrchr (path_original, '/');
p2 = strrchr (path_translated, '/');
if (p1 && p2 && ! g_hash_table_lookup (path_table, path_original))
{
gchar *copy_original = g_strdup (path_original);
gchar *copy_translated = g_strdup (path_translated);
gchar *label;
GtkAction *action;
label = p2 + 1;
g_print ("adding plug-in submenu '%s' (%s)\n",
path_original, label);
action = gtk_action_new (path_original, label, NULL, NULL);
gtk_action_group_add_action (GTK_ACTION_GROUP (group), action);
g_object_unref (action);
g_hash_table_insert (path_table, g_strdup (path_original), action);
p1 = strrchr (copy_original, '/');
p2 = strrchr (copy_translated, '/');
*p1 = '\0';
*p2 = '\0';
plug_in_actions_build_path (group, copy_original, copy_translated);
g_free (copy_original);
g_free (copy_translated);
}
}

View File

@ -18,6 +18,8 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
@ -236,6 +238,21 @@ gui_menus_create_entry (Gimp *gimp,
plug_in_actions_add_proc (list->data, proc_def);
}
for (list = gimp_ui_managers_from_name ("<Image>");
list;
list = g_list_next (list))
{
if (! strncmp (proc_def->menu_path, "<Toolbox>", 9))
{
plug_in_menus_add_proc (list->data, "/toolbox-menubar", proc_def);
}
else if (! strncmp (proc_def->menu_path, "<Image>", 7))
{
plug_in_menus_add_proc (list->data, "/image-menubar", proc_def);
plug_in_menus_add_proc (list->data, "/image-popup", proc_def);
}
}
progname = plug_in_proc_def_get_progname (proc_def);
locale_domain = plug_ins_locale_domain (gimp, progname, NULL);
@ -252,6 +269,13 @@ gui_menus_delete_entry (Gimp *gimp,
plug_in_menus_delete_entry (proc_def);
for (list = gimp_ui_managers_from_name ("<Image>");
list;
list = g_list_next (list))
{
plug_in_menus_remove_proc (list->data, proc_def);
}
for (list = gimp_action_groups_from_name ("plug-in");
list;
list = g_list_next (list))

View File

@ -1140,6 +1140,7 @@ image_menu_setup2 (GimpUIManager *manager,
const gchar *ui_path)
{
menus_open_recent_add (manager, ui_path);
plug_in_menus_create2 (manager, ui_path);
}
void

View File

@ -34,6 +34,7 @@
#include "plug-in/plug-in-run.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"
#include "actions/plug-in-commands.h"
@ -59,6 +60,14 @@ static gboolean plug_in_menu_tree_traverse_func (gpointer foo,
PlugInMenuEntry *menu_entry,
GimpItemFactory *item_factory);
static gboolean plug_in_menus_tree_traverse (gpointer foo,
PlugInProcDef *proc_def,
GimpUIManager *manager);
static void plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path);
/* public functions */
@ -113,6 +122,117 @@ plug_in_menus_init (Gimp *gimp,
g_slist_free (domains);
}
void
plug_in_menus_create2 (GimpUIManager *manager,
const gchar *ui_path)
{
GTree *menu_entries;
GSList *list;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
menu_entries = g_tree_new_full ((GCompareDataFunc) g_utf8_collate, NULL,
g_free, NULL);
for (list = manager->gimp->plug_in_proc_defs;
list;
list = g_slist_next (list))
{
PlugInProcDef *proc_def = list->data;
if (proc_def->prog &&
proc_def->menu_path &&
! proc_def->extensions &&
! proc_def->prefixes &&
! proc_def->magics)
{
if ((! strncmp (proc_def->menu_path, "<Toolbox>", 9) &&
! strcmp (ui_path, "/toolbox-menubar")) ||
(! strncmp (proc_def->menu_path, "<Image>", 7) &&
(! strcmp (ui_path, "/image-menubar") ||
! strcmp (ui_path, "/image-popup"))))
{
const gchar *progname;
const gchar *locale_domain;
gchar *key;
progname = plug_in_proc_def_get_progname (proc_def);
locale_domain = plug_ins_locale_domain (manager->gimp,
progname, NULL);
key = gimp_strip_uline (dgettext (locale_domain,
proc_def->menu_path));
g_tree_insert (menu_entries, key, proc_def);
}
}
}
g_object_set_data (G_OBJECT (manager), "ui-path", (gpointer) ui_path);
g_tree_foreach (menu_entries,
(GTraverseFunc) plug_in_menus_tree_traverse,
manager);
g_object_set_data (G_OBJECT (manager), "ui-path", NULL);
g_tree_destroy (menu_entries);
}
void
plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
PlugInProcDef *proc_def)
{
gchar *path;
gchar *p;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
g_return_if_fail (proc_def != NULL);
path = g_strdup (proc_def->menu_path);
p = strrchr (path, '/');
if (p)
{
gchar *action_path;
guint merge_id;
*p = '\0';
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
plug_in_menus_build_path (manager, ui_path, merge_id, path);
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
g_print ("adding UI for '%s' (@ %s)\n",
proc_def->db_info.name, action_path);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path,
proc_def->db_info.name,
proc_def->db_info.name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
g_free (action_path);
}
g_free (path);
}
void
plug_in_menus_remove_proc (GimpUIManager *manager,
PlugInProcDef *proc_def)
{
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (proc_def != NULL);
}
void
plug_in_menus_create (GimpItemFactory *item_factory,
GSList *proc_defs)
@ -396,3 +516,60 @@ plug_in_menu_tree_traverse_func (gpointer foo,
return FALSE;
}
static gboolean
plug_in_menus_tree_traverse (gpointer foo,
PlugInProcDef *proc_def,
GimpUIManager *manager)
{
const gchar *ui_path = g_object_get_data (G_OBJECT (manager), "ui-path");
plug_in_menus_add_proc (manager, ui_path, proc_def);
return FALSE;
}
static void
plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path)
{
gchar *action_path;
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
if (! gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), action_path))
{
gchar *base_path = g_strdup (path);
gchar *p;
p = strrchr (base_path, '/');
if (p)
{
gchar *name;
*p = '\0';
plug_in_menus_build_path (manager, ui_path, merge_id, base_path);
p = strrchr (action_path, '/');
*p = '\0';
g_print ("adding UI for '%s' (@ %s)\n",
path, action_path);
name = strrchr (path, '/') + 1;
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path, name, path,
GTK_UI_MANAGER_MENU,
FALSE);
}
g_free (base_path);
}
g_free (action_path);
}

View File

@ -24,6 +24,14 @@ void plug_in_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_plugins_domain);
void plug_in_menus_create2 (GimpUIManager *manager,
const gchar *ui_path);
void plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
PlugInProcDef *proc_def);
void plug_in_menus_remove_proc (GimpUIManager *manager,
PlugInProcDef *proc_def);
void plug_in_menus_create (GimpItemFactory *item_factory,
GSList *proc_defs);
void plug_in_menus_create_entry (GimpItemFactory *item_factory,

View File

@ -290,6 +290,7 @@ toolbox_menu_setup2 (GimpUIManager *manager,
const gchar *ui_path)
{
menus_open_recent_add (manager, ui_path);
plug_in_menus_create2 (manager, ui_path);
}
void

View File

@ -1140,6 +1140,7 @@ image_menu_setup2 (GimpUIManager *manager,
const gchar *ui_path)
{
menus_open_recent_add (manager, ui_path);
plug_in_menus_create2 (manager, ui_path);
}
void

View File

@ -34,6 +34,7 @@
#include "plug-in/plug-in-run.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"
#include "actions/plug-in-commands.h"
@ -59,6 +60,14 @@ static gboolean plug_in_menu_tree_traverse_func (gpointer foo,
PlugInMenuEntry *menu_entry,
GimpItemFactory *item_factory);
static gboolean plug_in_menus_tree_traverse (gpointer foo,
PlugInProcDef *proc_def,
GimpUIManager *manager);
static void plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path);
/* public functions */
@ -113,6 +122,117 @@ plug_in_menus_init (Gimp *gimp,
g_slist_free (domains);
}
void
plug_in_menus_create2 (GimpUIManager *manager,
const gchar *ui_path)
{
GTree *menu_entries;
GSList *list;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
menu_entries = g_tree_new_full ((GCompareDataFunc) g_utf8_collate, NULL,
g_free, NULL);
for (list = manager->gimp->plug_in_proc_defs;
list;
list = g_slist_next (list))
{
PlugInProcDef *proc_def = list->data;
if (proc_def->prog &&
proc_def->menu_path &&
! proc_def->extensions &&
! proc_def->prefixes &&
! proc_def->magics)
{
if ((! strncmp (proc_def->menu_path, "<Toolbox>", 9) &&
! strcmp (ui_path, "/toolbox-menubar")) ||
(! strncmp (proc_def->menu_path, "<Image>", 7) &&
(! strcmp (ui_path, "/image-menubar") ||
! strcmp (ui_path, "/image-popup"))))
{
const gchar *progname;
const gchar *locale_domain;
gchar *key;
progname = plug_in_proc_def_get_progname (proc_def);
locale_domain = plug_ins_locale_domain (manager->gimp,
progname, NULL);
key = gimp_strip_uline (dgettext (locale_domain,
proc_def->menu_path));
g_tree_insert (menu_entries, key, proc_def);
}
}
}
g_object_set_data (G_OBJECT (manager), "ui-path", (gpointer) ui_path);
g_tree_foreach (menu_entries,
(GTraverseFunc) plug_in_menus_tree_traverse,
manager);
g_object_set_data (G_OBJECT (manager), "ui-path", NULL);
g_tree_destroy (menu_entries);
}
void
plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
PlugInProcDef *proc_def)
{
gchar *path;
gchar *p;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
g_return_if_fail (proc_def != NULL);
path = g_strdup (proc_def->menu_path);
p = strrchr (path, '/');
if (p)
{
gchar *action_path;
guint merge_id;
*p = '\0';
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
plug_in_menus_build_path (manager, ui_path, merge_id, path);
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
g_print ("adding UI for '%s' (@ %s)\n",
proc_def->db_info.name, action_path);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path,
proc_def->db_info.name,
proc_def->db_info.name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
g_free (action_path);
}
g_free (path);
}
void
plug_in_menus_remove_proc (GimpUIManager *manager,
PlugInProcDef *proc_def)
{
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (proc_def != NULL);
}
void
plug_in_menus_create (GimpItemFactory *item_factory,
GSList *proc_defs)
@ -396,3 +516,60 @@ plug_in_menu_tree_traverse_func (gpointer foo,
return FALSE;
}
static gboolean
plug_in_menus_tree_traverse (gpointer foo,
PlugInProcDef *proc_def,
GimpUIManager *manager)
{
const gchar *ui_path = g_object_get_data (G_OBJECT (manager), "ui-path");
plug_in_menus_add_proc (manager, ui_path, proc_def);
return FALSE;
}
static void
plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *path)
{
gchar *action_path;
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
if (! gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), action_path))
{
gchar *base_path = g_strdup (path);
gchar *p;
p = strrchr (base_path, '/');
if (p)
{
gchar *name;
*p = '\0';
plug_in_menus_build_path (manager, ui_path, merge_id, base_path);
p = strrchr (action_path, '/');
*p = '\0';
g_print ("adding UI for '%s' (@ %s)\n",
path, action_path);
name = strrchr (path, '/') + 1;
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path, name, path,
GTK_UI_MANAGER_MENU,
FALSE);
}
g_free (base_path);
}
g_free (action_path);
}

View File

@ -24,6 +24,14 @@ void plug_in_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_plugins_domain);
void plug_in_menus_create2 (GimpUIManager *manager,
const gchar *ui_path);
void plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
PlugInProcDef *proc_def);
void plug_in_menus_remove_proc (GimpUIManager *manager,
PlugInProcDef *proc_def);
void plug_in_menus_create (GimpItemFactory *item_factory,
GSList *proc_defs);
void plug_in_menus_create_entry (GimpItemFactory *item_factory,

View File

@ -290,6 +290,7 @@ toolbox_menu_setup2 (GimpUIManager *manager,
const gchar *ui_path)
{
menus_open_recent_add (manager, ui_path);
plug_in_menus_create2 (manager, ui_path);
}
void

View File

@ -318,7 +318,7 @@ gimp_menu_factory_manager_new (GimpMenuFactory *factory,
GimpUIManager *manager;
GList *list;
manager = gimp_ui_manager_new (factory->gimp);
manager = gimp_ui_manager_new (factory->gimp, entry->identifier);
gtk_ui_manager_set_add_tearoffs (GTK_UI_MANAGER (manager),
create_tearoff);

View File

@ -38,22 +38,27 @@
enum
{
PROP_0,
PROP_NAME,
PROP_GIMP
};
static void gimp_ui_manager_init (GimpUIManager *manager);
static void gimp_ui_manager_class_init (GimpUIManagerClass *klass);
static void gimp_ui_manager_init (GimpUIManager *manager);
static void gimp_ui_manager_class_init (GimpUIManagerClass *klass);
static void gimp_ui_manager_finalize (GObject *object);
static void gimp_ui_manager_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_ui_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static GObject * gimp_ui_manager_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_ui_manager_dispose (GObject *object);
static void gimp_ui_manager_finalize (GObject *object);
static void gimp_ui_manager_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_ui_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static GtkUIManagerClass *parent_class = NULL;
@ -94,24 +99,95 @@ gimp_ui_manager_class_init (GimpUIManagerClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_ui_manager_constructor;
object_class->dispose = gimp_ui_manager_dispose;
object_class->finalize = gimp_ui_manager_finalize;
object_class->set_property = gimp_ui_manager_set_property;
object_class->get_property = gimp_ui_manager_get_property;
g_object_class_install_property (object_class, PROP_NAME,
g_param_spec_string ("name",
NULL, NULL,
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp",
NULL, NULL,
GIMP_TYPE_GIMP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
klass->managers = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
}
static void
gimp_ui_manager_init (GimpUIManager *manager)
{
manager->name = NULL;
manager->gimp = NULL;
}
static GObject *
gimp_ui_manager_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpUIManager *manager;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
manager = GIMP_UI_MANAGER (object);
if (manager->name)
{
GimpUIManagerClass *manager_class;
GList *list;
manager_class = GIMP_UI_MANAGER_GET_CLASS (object);
list = g_hash_table_lookup (manager_class->managers, manager->name);
list = g_list_append (list, manager);
g_hash_table_replace (manager_class->managers,
g_strdup (manager->name), list);
}
return object;
}
static void
gimp_ui_manager_dispose (GObject *object)
{
GimpUIManager *manager = GIMP_UI_MANAGER (object);
if (manager->name)
{
GimpUIManagerClass *manager_class;
GList *list;
manager_class = GIMP_UI_MANAGER_GET_CLASS (object);
list = g_hash_table_lookup (manager_class->managers, manager->name);
if (list)
{
list = g_list_remove (list, manager);
if (list)
g_hash_table_replace (manager_class->managers,
g_strdup (manager->name), list);
else
g_hash_table_remove (manager_class->managers, manager->name);
}
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_ui_manager_finalize (GObject *object)
{
@ -134,6 +210,12 @@ gimp_ui_manager_finalize (GObject *object)
g_list_free (manager->registered_uis);
manager->registered_uis = NULL;
if (manager->name)
{
g_free (manager->name);
manager->name = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -147,6 +229,10 @@ gimp_ui_manager_set_property (GObject *object,
switch (prop_id)
{
case PROP_NAME:
g_free (manager->name);
manager->name = g_value_dup_string (value);
break;
case PROP_GIMP:
manager->gimp = g_value_get_object (value);
break;
@ -166,6 +252,9 @@ gimp_ui_manager_get_property (GObject *object,
switch (prop_id)
{
case PROP_NAME:
g_value_set_string (value, manager->name);
break;
case PROP_GIMP:
g_value_set_object (value, manager->gimp);
break;
@ -184,19 +273,38 @@ gimp_ui_manager_get_property (GObject *object,
* Returns: the new #GimpUIManager
*/
GimpUIManager *
gimp_ui_manager_new (Gimp *gimp)
gimp_ui_manager_new (Gimp *gimp,
const gchar *name)
{
GimpUIManager *manager;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
manager = g_object_new (GIMP_TYPE_UI_MANAGER,
"name", name,
"gimp", gimp,
NULL);
return manager;
}
GList *
gimp_ui_managers_from_name (const gchar *name)
{
GimpUIManagerClass *manager_class;
GList *list;
g_return_val_if_fail (name != NULL, NULL);
manager_class = g_type_class_ref (GIMP_TYPE_UI_MANAGER);
list = g_hash_table_lookup (manager_class->managers, name);
g_type_class_unref (manager_class);
return list;
}
void
gimp_ui_manager_update (GimpUIManager *manager,
gpointer update_data)

View File

@ -51,6 +51,7 @@ struct _GimpUIManager
{
GtkUIManager parent_instance;
gchar *name;
Gimp *gimp;
GList *registered_uis;
};
@ -58,11 +59,16 @@ struct _GimpUIManager
struct _GimpUIManagerClass
{
GtkUIManagerClass parent_class;
GHashTable *managers;
};
GType gimp_ui_manager_get_type (void);
GimpUIManager * gimp_ui_manager_new (Gimp *gimp);
GimpUIManager * gimp_ui_manager_new (Gimp *gimp,
const gchar *name);
GList * gimp_ui_managers_from_name (const gchar *name);
void gimp_ui_manager_update (GimpUIManager *manager,
gpointer update_data);

View File

@ -4,15 +4,15 @@
<ui>
<menubar action="image-menubar">
<menu action="file-menu">
<menu action="file-menu" name="File">
<menuitem action="file-new" />
<menuitem action="file-open" />
<menu action="file-open-recent-menu">
<menu action="file-open-recent-menu" name="Open Recent">
<placeholder name="file-open-recent-placeholder" />
<separator />
<menuitem action="dialogs-document-history" />
</menu>
<menu action="file-acquire-menu">
<menu action="file-acquire-menu" name="Acquire">
</menu>
<separator />
<menuitem action="file-save" />
@ -25,7 +25,7 @@
<menuitem action="file-quit" />
</menu>
<menu action="edit-menu">
<menu action="edit-menu" name="Edit">
<menuitem action="edit-undo" />
<menuitem action="edit-redo" />
<menuitem action="dialogs-undo-history" />
@ -35,7 +35,7 @@
<menuitem action="edit-paste" />
<menuitem action="edit-paste-into" />
<menuitem action="edit-paste-as-new" />
<menu action="edit-buffer-menu">
<menu action="edit-buffer-menu" name="Buffer">
<menuitem action="edit-named-cut" />
<menuitem action="edit-named-copy" />
<menuitem action="edit-named-paste" />
@ -50,7 +50,7 @@
<separator />
</menu>
<menu action="select-menu">
<menu action="select-menu" name="Select">
<menuitem action="select-all" />
<menuitem action="select-none" />
<menuitem action="select-invert" />
@ -69,10 +69,10 @@
<menuitem action="select-to-vectors" />
</menu>
<menu action="view-menu">
<menu action="view-menu" name="View">
<menuitem action="view-new" />
<menuitem action="view-dot-for-dot" />
<menu action="view-zoom-menu">
<menu action="view-zoom-menu" name="Zoom">
<menuitem action="view-zoom-out" />
<menuitem action="view-zoom-in" />
<menuitem action="view-zoom-fit" />
@ -111,13 +111,13 @@
<menuitem action="view-move-to-screen" />
</menu>
<menu action="image-menu">
<menu action="image-mode-menu">
<menu action="image-menu" name="Image">
<menu action="image-mode-menu" name="Mode">
<menuitem action="image-convert-rgb" />
<menuitem action="image-convert-grayscale" />
<menuitem action="image-convert-indexed" />
</menu>
<menu action="image-transform-menu">
<menu action="image-transform-menu" name="Transform">
<menuitem action="image-flip-horizontal" />
<menuitem action="image-flip-vertical" />
<separator />
@ -138,7 +138,7 @@
<menuitem action="image-configure-grid" />
</menu>
<menu action="layers-menu">
<menu action="layers-menu" name="Layer">
<menuitem action="layers-new" />
<menuitem action="layers-duplicate" />
<menuitem action="layers-anchor" />
@ -146,7 +146,7 @@
<menuitem action="layers-delete" />
<menuitem action="layers-text-discard" />
<separator />
<menu action="layers-stack-menu">
<menu action="layers-stack-menu" name="Stack">
<menuitem action="layers-select-previous" />
<menuitem action="layers-select-next" />
<menuitem action="layers-select-top" />
@ -157,7 +157,7 @@
<menuitem action="layers-raise-to-top" />
<menuitem action="layers-lower-to-bottom" />
</menu>
<menu action="layers-colors-menu">
<menu action="layers-colors-menu" name="Colors">
<menuitem action="tools-color-balance" />
<menuitem action="tools-hue-saturation" />
<menuitem action="tools-colorize" />
@ -169,13 +169,13 @@
<separator />
<menuitem action="drawable-desaturate" />
<menuitem action="drawable-invert" />
<menu action="layers-colors-auto-menu">
<menu action="layers-colors-auto-menu" name="Auto">
<menuitem action="drawable-equalize" />
</menu>
<separator />
<menuitem action="dialogs-histogram" />
</menu>
<menu action="layers-mask-menu">
<menu action="layers-mask-menu" name="Mask">
<menuitem action="layers-mask-add" />
<menuitem action="layers-mask-apply" />
<menuitem action="layers-mask-delete" />
@ -185,7 +185,7 @@
<menuitem action="layers-mask-selection-subtract" />
<menuitem action="layers-mask-selection-intersect" />
</menu>
<menu action="layers-transparency-menu">
<menu action="layers-transparency-menu" name="Transparency">
<menuitem action="layers-alpha-add" />
<separator />
<menuitem action="layers-alpha-selection-replace" />
@ -194,7 +194,7 @@
<menuitem action="layers-alpha-selection-intersect" />
<separator />
</menu>
<menu action="layers-transform-menu">
<menu action="layers-transform-menu" name="Transform">
<menuitem action="drawable-flip-horizontal" />
<menuitem action="drawable-flip-vertical" />
<separator />
@ -212,19 +212,19 @@
<separator />
</menu>
<menu action="tools-menu">
<menu action="tools-menu" name="Tools">
<menuitem action="dialogs-toolbox" />
<menuitem action="tools-default-colors" />
<menuitem action="tools-swap-colors" />
<separator />
<menu action="tools-select-menu">
<menu action="tools-select-menu" name="Selection Tools">
<menuitem action="tools-rect-select" />
<menuitem action="tools-ellipse-select" />
<menuitem action="tools-free-select" />
<menuitem action="tools-by-color-select" />
<menuitem action="tools-iscissors" />
</menu>
<menu action="tools-paint-menu">
<menu action="tools-paint-menu" name="Paint Tools">
<menuitem action="tools-bucket-fill" />
<menuitem action="tools-blend" />
<menuitem action="tools-pencil" />
@ -237,7 +237,7 @@
<menuitem action="tools-smudge" />
<menuitem action="tools-dodge-burn" />
</menu>
<menu action="tools-transform-menu">
<menu action="tools-transform-menu" name="Transform Tools">
<menuitem action="tools-move" />
<menuitem action="tools-crop" />
<menuitem action="tools-rotate" />
@ -245,7 +245,7 @@
<menuitem action="tools-perspective" />
<menuitem action="tools-flip" />
</menu>
<menu action="tools-color-menu">
<menu action="tools-color-menu" name="Color Tools">
<menuitem action="tools-color-balance" />
<menuitem action="tools-hue-saturation" />
<menuitem action="tools-colorize" />
@ -262,8 +262,8 @@
<menuitem action="tools-text" />
</menu>
<menu action="dialogs-menu">
<menu action="dialogs-new-dock-menu">
<menu action="dialogs-menu" name="Dialogs">
<menu action="dialogs-new-dock-menu" name="Create New Dock">
<menuitem action="dialogs-new-dock-lcp" />
<menuitem action="dialogs-new-dock-data" />
<menuitem action="dialogs-new-dock-stuff" />
@ -295,52 +295,52 @@
<menuitem action="dialogs-error-console" />
</menu>
<menu action="plug-in-menu">
<menu action="plug-in-menu" name="Filters">
<menuitem action="plug-in-repeat" />
<menuitem action="plug-in-reshow" />
<separator />
<menu action="plug-in-blur-menu">
<menu action="plug-in-blur-menu" name="Blur">
</menu>
<menu action="plug-in-colors-menu">
<menu action="plug-in-colors-map-menu">
<menu action="plug-in-colors-menu" name="Colors">
<menu action="plug-in-colors-map-menu" name="Map">
</menu>
</menu>
<menu action="plug-in-noise-menu">
<menu action="plug-in-noise-menu" name="Noise">
</menu>
<menu action="plug-in-edge-detect-menu">
<menu action="plug-in-edge-detect-menu" name="Edge Detect">
</menu>
<menu action="plug-in-enhance-menu">
<menu action="plug-in-enhance-menu" name="Enhance">
</menu>
<menu action="plug-in-generic-menu">
<menu action="plug-in-generic-menu" name="Generic">
</menu>
<separator />
<menu action="plug-in-glass-effects-menu">
<menu action="plug-in-glass-effects-menu" name="Glass Effects">
</menu>
<menu action="plug-in-light-effects-menu">
<menu action="plug-in-light-effects-menu" name="Light Effects">
</menu>
<menu action="plug-in-distorts-menu">
<menu action="plug-in-distorts-menu" name="Distorts">
</menu>
<menu action="plug-in-artistic-menu">
<menu action="plug-in-artistic-menu" name="Artistic">
</menu>
<menu action="plug-in-map-menu">
<menu action="plug-in-map-menu" name="Map">
</menu>
<menu action="plug-in-render-menu">
<menu action="plug-in-render-clouds-menu">
<menu action="plug-in-render-menu" name="Render">
<menu action="plug-in-render-clouds-menu" name="Clouds">
</menu>
<menu action="plug-in-render-nature-menu">
<menu action="plug-in-render-nature-menu" name="Nature">
</menu>
<menu action="plug-in-render-pattern-menu">
<menu action="plug-in-render-pattern-menu" name="Pattern">
</menu>
</menu>
<menu action="plug-in-web-menu">
<menu action="plug-in-web-menu" name="Web">
</menu>
<separator />
<menu action="plug-in-animation-menu">
<menu action="plug-in-animation-menu" name="Animation">
</menu>
<menu action="plug-in-combine-menu">
<menu action="plug-in-combine-menu" name="Combine">
</menu>
<separator />
<menu action="plug-in-toys-menu">
<menu action="plug-in-toys-menu" name="Toys">
</menu>
</menu>

View File

@ -4,20 +4,20 @@
<ui>
<menubar action="toolbox-menubar">
<menu action="file-menu">
<menu action="file-menu" name="File">
<menuitem action="file-new" />
<menuitem action="file-open" />
<menu action="file-open-recent-menu">
<menu action="file-open-recent-menu" name="Open Recent">
<placeholder name="file-open-recent-placeholder" />
<separator />
<menuitem action="dialogs-document-history" />
</menu>
<menu action="file-acquire-menu">
<menu action="file-acquire-menu" name="Acquire">
</menu>
<separator />
<menuitem action="dialogs-preferences" />
<menu action="dialogs-menu">
<menu action="dialogs-new-dock-menu">
<menu action="dialogs-menu" name="Dialogs">
<menu action="dialogs-new-dock-menu" name="Create New Dock">
<menuitem action="dialogs-new-dock-lcp" />
<menuitem action="dialogs-new-dock-data" />
<menuitem action="dialogs-new-dock-stuff" />
@ -48,7 +48,7 @@
<menuitem action="dialogs-tools" />
<menuitem action="dialogs-error-console" />
</menu>
<menu action="debug-menu">
<menu action="debug-menu" name="Debug">
<menuitem action="debug-mem-profile" />
<menuitem action="debug-dump-items" />
</menu>
@ -56,12 +56,12 @@
<menuitem action="file-quit" />
</menu>
<menu action="extensions-menu">
<menu action="extensions-menu" name="Xtns">
<menuitem action="dialogs-module-manager" />
<separator />
</menu>
<menu action="help-menu">
<menu action="help-menu" name="Help">
<menuitem action="help-help" />
<menuitem action="help-context-help" />
<separator />