Added some signals inspired by Rockwalrus' libpdb:

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

	Added some signals inspired by Rockwalrus' libpdb:

	* app/pdb/gimppdb.[ch]: added signals "register-procedure" and
	"unregister-procedure".

	* app/pdb/gimppluginprocedure.[ch]: added signal "menu-path-added".

	* app/actions/plug-in-actions.[ch]
	* app/menus/plug-in-menus.[ch]: connect to the new signals and
	create/destroy plug-in actions and menus accordingly. Made all
	needed functions private and merged some of them with the newly
	added signal callbacks.

	* app/core/gimp-gui.[ch]
	* app/gui/gui-vtable.c: removed gimp_menus_create_item() and
	gimp_menus_delete_item() and all related stuff.

	* app/plug-in/plug-in.c
	* app/plug-in/plug-ins.c: removed calls to the removed functions.

	* app/plug-in/plug-ins.c (plug_ins_init): add the plug-in
	procedures to the PDB *after* calling gimp_menus_init() so their
	locale domains are properly initialized when the menus are
	created.
This commit is contained in:
Michael Natterer 2006-04-27 19:36:13 +00:00 committed by Michael Natterer
parent 9120cb78c1
commit ee66f2f31d
18 changed files with 554 additions and 459 deletions

View File

@ -1,3 +1,30 @@
2006-04-27 Michael Natterer <mitch@gimp.org>
Added some signals inspired by Rockwalrus' libpdb:
* app/pdb/gimppdb.[ch]: added signals "register-procedure" and
"unregister-procedure".
* app/pdb/gimppluginprocedure.[ch]: added signal "menu-path-added".
* app/actions/plug-in-actions.[ch]
* app/menus/plug-in-menus.[ch]: connect to the new signals and
create/destroy plug-in actions and menus accordingly. Made all
needed functions private and merged some of them with the newly
added signal callbacks.
* app/core/gimp-gui.[ch]
* app/gui/gui-vtable.c: removed gimp_menus_create_item() and
gimp_menus_delete_item() and all related stuff.
* app/plug-in/plug-in.c
* app/plug-in/plug-ins.c: removed calls to the removed functions.
* app/plug-in/plug-ins.c (plug_ins_init): add the plug-in
procedures to the PDB *after* calling gimp_menus_init() so their
locale domains are properly initialized when the menus are
created.
2006-04-27 Sven Neumann <sven@gimp.org>
* app/core/gimpcontext.c: fixed argument order for using

View File

@ -51,13 +51,25 @@
/* local function prototypes */
static void plug_in_actions_last_changed (Gimp *gimp,
GimpActionGroup *group);
static gboolean plug_in_actions_check_translation (const gchar *original,
const gchar *translated);
static void plug_in_actions_build_path (GimpActionGroup *group,
const gchar *original,
const gchar *translated);
static void plug_in_actions_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpActionGroup *group);
static void plug_in_actions_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpActionGroup *group);
static void plug_in_actions_menu_path_added (GimpPlugInProcedure *proc,
const gchar *menu_path,
GimpActionGroup *group);
static void plug_in_actions_add_proc (GimpActionGroup *group,
GimpPlugInProcedure *proc);
static void plug_in_actions_last_changed (Gimp *gimp,
GimpActionGroup *group);
static gboolean plug_in_actions_check_translation (const gchar *original,
const gchar *translated);
static void plug_in_actions_build_path (GimpActionGroup *group,
const gchar *original,
const gchar *translated);
/* private variables */
@ -141,18 +153,34 @@ plug_in_actions_setup (GimpActionGroup *group)
list;
list = g_slist_next (list))
{
GimpPlugInProcedure *proc = list->data;
GimpPlugInProcedure *plug_in_proc = list->data;
if (proc->prog &&
proc->menu_paths &&
! proc->extensions &&
! proc->prefixes &&
! proc->magics)
if (! plug_in_proc->prog)
continue;
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_actions_menu_path_added),
group, 0);
if (plug_in_proc->prog &&
plug_in_proc->menu_paths &&
! plug_in_proc->extensions &&
! plug_in_proc->prefixes &&
! plug_in_proc->magics)
{
plug_in_actions_add_proc (group, proc);
plug_in_actions_register_procedure (group->gimp->pdb,
GIMP_PROCEDURE (plug_in_proc),
group);
}
}
g_signal_connect_object (group->gimp->pdb, "register-procedure",
G_CALLBACK (plug_in_actions_register_procedure),
group, 0);
g_signal_connect_object (group->gimp->pdb, "unregister-procedure",
G_CALLBACK (plug_in_actions_unregister_procedure),
group, 0);
n_entries = group->gimp->config->plug_in_history_size;
entries = g_new0 (GimpEnumActionEntry, n_entries);
@ -255,6 +283,124 @@ plug_in_actions_update (GimpActionGroup *group,
}
void
plug_in_actions_add_branch (GimpActionGroup *group,
const gchar *progname,
const gchar *menu_path,
const gchar *menu_label)
{
const gchar *locale_domain;
const gchar *path_translated;
const gchar *label_translated;
gchar *full;
gchar *full_translated;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (menu_path != NULL);
g_return_if_fail (menu_label != NULL);
locale_domain = plug_in_locale_domain (group->gimp, progname, NULL);
path_translated = dgettext (locale_domain, menu_path);
label_translated = dgettext (locale_domain, menu_label);
full = g_strconcat (menu_path, "/", menu_label, NULL);
full_translated = g_strconcat (path_translated, "/", label_translated, NULL);
if (plug_in_actions_check_translation (full, full_translated))
plug_in_actions_build_path (group, full, full_translated);
else
plug_in_actions_build_path (group, full, full);
g_free (full_translated);
g_free (full);
}
/* private functions */
static void
plug_in_actions_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpActionGroup *group)
{
if (GIMP_IS_PLUG_IN_PROCEDURE (procedure))
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (procedure);
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_actions_menu_path_added),
group, 0);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
{
#if 0
g_print ("%s: %s\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (procedure)));
#endif
plug_in_actions_add_proc (group, plug_in_proc);
}
}
}
static void
plug_in_actions_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpActionGroup *group)
{
if (GIMP_IS_PLUG_IN_PROCEDURE (procedure))
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (procedure);
g_signal_handlers_disconnect_by_func (plug_in_proc,
plug_in_actions_menu_path_added,
group);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
{
GtkAction *action;
#if 0
g_print ("%s: %s\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (procedure)));
#endif
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
GIMP_OBJECT (procedure)->name);
if (action)
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
}
}
}
static void
plug_in_actions_menu_path_added (GimpPlugInProcedure *plug_in_proc,
const gchar *menu_path,
GimpActionGroup *group)
{
const gchar *progname;
const gchar *locale_domain;
const gchar *path_translated;
#if 0
g_print ("%s: %s (%s)\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (plug_in_proc)), menu_path);
#endif
progname = gimp_plug_in_procedure_get_progname (plug_in_proc);
locale_domain = plug_in_locale_domain (group->gimp, progname, NULL);
path_translated = dgettext (locale_domain, menu_path);
if (plug_in_actions_check_translation (menu_path, path_translated))
plug_in_actions_build_path (group, menu_path, path_translated);
else
plug_in_actions_build_path (group, menu_path, menu_path);
}
static void
plug_in_actions_add_proc (GimpActionGroup *group,
GimpPlugInProcedure *proc)
{
@ -347,90 +493,6 @@ plug_in_actions_add_proc (GimpActionGroup *group,
}
}
void
plug_in_actions_add_path (GimpActionGroup *group,
GimpPlugInProcedure *proc,
const gchar *menu_path)
{
const gchar *progname;
const gchar *locale_domain;
const gchar *path_translated;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
g_return_if_fail (menu_path != NULL);
progname = gimp_plug_in_procedure_get_progname (proc);
locale_domain = plug_in_locale_domain (group->gimp, progname, NULL);
path_translated = dgettext (locale_domain, menu_path);
if (plug_in_actions_check_translation (menu_path, path_translated))
plug_in_actions_build_path (group, menu_path, path_translated);
else
plug_in_actions_build_path (group, menu_path, menu_path);
}
void
plug_in_actions_remove_proc (GimpActionGroup *group,
GimpPlugInProcedure *proc)
{
GtkAction *action;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
GIMP_OBJECT (proc)->name);
if (action)
{
#if 0
g_print ("removing plug-in action '%s'\n",
GIMP_OBJECT (proc)->name);
#endif
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
}
}
void
plug_in_actions_add_branch (GimpActionGroup *group,
const gchar *progname,
const gchar *menu_path,
const gchar *menu_label)
{
const gchar *locale_domain;
const gchar *path_translated;
const gchar *label_translated;
gchar *full;
gchar *full_translated;
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
g_return_if_fail (menu_path != NULL);
g_return_if_fail (menu_label != NULL);
locale_domain = plug_in_locale_domain (group->gimp, progname, NULL);
path_translated = dgettext (locale_domain, menu_path);
label_translated = dgettext (locale_domain, menu_label);
full = g_strconcat (menu_path, "/", menu_label, NULL);
full_translated = g_strconcat (path_translated, "/", label_translated, NULL);
if (plug_in_actions_check_translation (full, full_translated))
plug_in_actions_build_path (group, full, full_translated);
else
plug_in_actions_build_path (group, full, full);
g_free (full_translated);
g_free (full);
}
/* private functions */
static void
plug_in_actions_last_changed (Gimp *gimp,
GimpActionGroup *group)

View File

@ -20,22 +20,14 @@
#define __PLUG_IN_ACTIONS_H__
void plug_in_actions_setup (GimpActionGroup *group);
void plug_in_actions_update (GimpActionGroup *group,
gpointer data);
void plug_in_actions_setup (GimpActionGroup *group);
void plug_in_actions_update (GimpActionGroup *group,
gpointer data);
void plug_in_actions_add_proc (GimpActionGroup *group,
GimpPlugInProcedure *proc);
void plug_in_actions_add_path (GimpActionGroup *group,
GimpPlugInProcedure *proc,
const gchar *menu_path);
void plug_in_actions_remove_proc (GimpActionGroup *group,
GimpPlugInProcedure *proc);
void plug_in_actions_add_branch (GimpActionGroup *group,
const gchar *progname,
const gchar *menu_path,
const gchar *menu_label);
void plug_in_actions_add_branch (GimpActionGroup *group,
const gchar *progname,
const gchar *menu_path,
const gchar *menu_label);
#endif /* __PLUG_IN_ACTIONS_H__ */

View File

@ -24,8 +24,6 @@
#include "core-types.h"
#include "pdb/gimppluginprocedure.h"
#include "gimp.h"
#include "gimp-gui.h"
#include "gimpcontainer.h"
@ -59,8 +57,6 @@ gimp_gui_init (Gimp *gimp)
gimp->gui.display_delete = NULL;
gimp->gui.displays_reconnect = NULL;
gimp->gui.menus_init = NULL;
gimp->gui.menus_create_item = NULL;
gimp->gui.menus_delete_item = NULL;
gimp->gui.menus_create_branch = NULL;
gimp->gui.progress_new = NULL;
gimp->gui.progress_free = NULL;
@ -310,29 +306,6 @@ gimp_menus_init (Gimp *gimp,
gimp->gui.menus_init (gimp, plug_in_defs, std_plugins_domain);
}
void
gimp_menus_create_item (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
if (gimp->gui.menus_create_item)
gimp->gui.menus_create_item (gimp, proc, menu_path);
}
void
gimp_menus_delete_item (Gimp *gimp,
GimpPlugInProcedure *proc)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
if (gimp->gui.menus_delete_item)
gimp->gui.menus_delete_item (gimp, proc);
}
void
gimp_menus_create_branch (Gimp *gimp,
const gchar *progname,

View File

@ -58,11 +58,6 @@ struct _GimpGui
void (* menus_init) (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_domain);
void (* menus_create_item) (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path);
void (* menus_delete_item) (Gimp *gimp,
GimpPlugInProcedure *proc);
void (* menus_create_branch) (Gimp *gimp,
const gchar *progname,
const gchar *menu_path,
@ -127,11 +122,6 @@ void gimp_help (Gimp *gimp,
void gimp_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_plugins_domain);
void gimp_menus_create_item (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path);
void gimp_menus_delete_item (Gimp *gimp,
GimpPlugInProcedure *proc);
void gimp_menus_create_branch (Gimp *gimp,
const gchar *progname,
const gchar *menu_path,

View File

@ -106,11 +106,6 @@ static void gui_displays_reconnect (Gimp *gimp,
static void gui_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *plugins_domain);
static void gui_menus_create_item (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path);
static void gui_menus_delete_item (Gimp *gimp,
GimpPlugInProcedure *proc);
static void gui_menus_create_branch (Gimp *gimp,
const gchar *progname,
const gchar *menu_path,
@ -160,8 +155,6 @@ gui_vtable_init (Gimp *gimp)
gimp->gui.display_delete = gui_display_delete;
gimp->gui.displays_reconnect = gui_displays_reconnect;
gimp->gui.menus_init = gui_menus_init;
gimp->gui.menus_create_item = gui_menus_create_item;
gimp->gui.menus_delete_item = gui_menus_delete_item;
gimp->gui.menus_create_branch = gui_menus_create_branch;
gimp->gui.progress_new = gui_new_progress;
gimp->gui.progress_free = gui_free_progress;
@ -387,152 +380,6 @@ gui_menus_init (Gimp *gimp,
plug_in_menus_init (gimp, plug_in_defs, std_plugins_domain);
}
static void
gui_menus_add_proc (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path)
{
gchar *prefix;
gchar *p;
GList *list;
prefix = g_strdup (menu_path);
p = strchr (prefix, '>');
if (p)
{
p[1] = '\0';
for (list = gimp_ui_managers_from_name (prefix);
list;
list = g_list_next (list))
{
if (! strcmp (prefix, "<Image>"))
{
plug_in_menus_add_proc (list->data, "/image-menubar",
proc, menu_path);
plug_in_menus_add_proc (list->data, "/dummy-menubar/image-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Toolbox>"))
{
plug_in_menus_add_proc (list->data, "/toolbox-menubar",
proc, menu_path);
}
else if (! strcmp (prefix, "<Brushes>"))
{
plug_in_menus_add_proc (list->data, "/brushes-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Gradients>"))
{
plug_in_menus_add_proc (list->data, "/gradients-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Palettes>"))
{
plug_in_menus_add_proc (list->data, "/palettes-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Patterns>"))
{
plug_in_menus_add_proc (list->data, "/patterns-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Fonts>"))
{
plug_in_menus_add_proc (list->data, "/fonts-popup",
proc, menu_path);
}
else if (! strcmp (prefix, "<Buffers>"))
{
plug_in_menus_add_proc (list->data, "/buffers-popup",
proc, menu_path);
}
}
}
g_free (prefix);
}
static void
gui_menus_delete_proc (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path)
{
gchar *prefix;
gchar *p;
GList *list;
prefix = g_strdup (menu_path);
p = strchr (prefix, '>');
if (p)
{
p[1] = '\0';
for (list = gimp_ui_managers_from_name (prefix);
list;
list = g_list_next (list))
{
plug_in_menus_remove_proc (list->data, proc);
}
}
g_free (prefix);
}
static void
gui_menus_create_item (Gimp *gimp,
GimpPlugInProcedure *proc,
const gchar *menu_path)
{
GList *list;
for (list = gimp_action_groups_from_name ("plug-in");
list;
list = g_list_next (list))
{
if (menu_path == NULL)
{
plug_in_actions_add_proc (list->data, proc);
}
else
{
plug_in_actions_add_path (list->data, proc, menu_path);
}
}
if (menu_path == NULL)
{
for (list = proc->menu_paths; list; list = g_list_next (list))
gui_menus_add_proc (gimp, proc, list->data);
}
else
{
gui_menus_add_proc (gimp, proc, menu_path);
}
}
static void
gui_menus_delete_item (Gimp *gimp,
GimpPlugInProcedure *proc)
{
GList *list;
for (list = proc->menu_paths; list; list = g_list_next (list))
gui_menus_delete_proc (gimp, proc, list->data);
for (list = gimp_action_groups_from_name ("plug-in");
list;
list = g_list_next (list))
{
plug_in_actions_remove_proc (list->data, proc);
}
}
static void
gui_menus_create_branch (Gimp *gimp,
const gchar *progname,

View File

@ -53,14 +53,27 @@ struct _PlugInMenuEntry
/* local function prototypes */
static gboolean plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
GimpUIManager *manager);
static gchar * plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *menu_path,
gboolean for_menu);
static void plug_in_menus_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpUIManager *manager);
static void plug_in_menus_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpUIManager *manager);
static void plug_in_menus_menu_path_added (GimpPlugInProcedure *plug_in_proc,
const gchar *menu_path,
GimpUIManager *manager);
static void plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
GimpPlugInProcedure *proc,
const gchar *menu_path);
static gboolean plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
GimpUIManager *manager);
static gchar * plug_in_menus_build_path (GimpUIManager *manager,
const gchar *ui_path,
guint merge_id,
const gchar *menu_path,
gboolean for_menu);
/* public functions */
@ -119,18 +132,15 @@ void
plug_in_menus_setup (GimpUIManager *manager,
const gchar *ui_path)
{
GtkUIManager *ui_manager;
GTree *menu_entries;
GSList *list;
guint merge_id;
gint i;
GTree *menu_entries;
GSList *list;
guint merge_id;
gint i;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
ui_manager = GTK_UI_MANAGER (manager);
merge_id = gtk_ui_manager_new_merge_id (ui_manager);
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
for (i = 0; i < manager->gimp->config->plug_in_history_size; i++)
{
@ -141,7 +151,7 @@ plug_in_menus_setup (GimpUIManager *manager,
action_path = g_strdup_printf ("%s/Filters/Recently Used/Plug-Ins",
ui_path);
gtk_ui_manager_add_ui (ui_manager, merge_id,
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path, action_name, action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
@ -157,17 +167,23 @@ plug_in_menus_setup (GimpUIManager *manager,
list;
list = g_slist_next (list))
{
GimpPlugInProcedure *proc = list->data;
GimpPlugInProcedure *plug_in_proc = list->data;
if (proc->prog &&
proc->menu_paths &&
! proc->extensions &&
! proc->prefixes &&
! proc->magics)
if (! plug_in_proc->prog)
continue;
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_menus_menu_path_added),
manager, 0);
if (plug_in_proc->menu_paths &&
! plug_in_proc->extensions &&
! plug_in_proc->prefixes &&
! plug_in_proc->magics)
{
GList *path;
for (path = proc->menu_paths; path; path = g_list_next (path))
for (path = plug_in_proc->menu_paths; path; path = g_list_next (path))
{
if (! strncmp (path->data, manager->name, strlen (manager->name)))
{
@ -176,15 +192,15 @@ plug_in_menus_setup (GimpUIManager *manager,
const gchar *locale_domain;
gchar *key;
entry->proc = proc;
entry->proc = plug_in_proc;
entry->menu_path = path->data;
progname = gimp_plug_in_procedure_get_progname (proc);
progname = gimp_plug_in_procedure_get_progname (plug_in_proc);
locale_domain = plug_in_locale_domain (manager->gimp,
progname, NULL);
if (proc->menu_label)
if (plug_in_proc->menu_label)
{
gchar *menu;
gchar *strip;
@ -193,7 +209,7 @@ plug_in_menus_setup (GimpUIManager *manager,
path->data),
"/",
dgettext (locale_domain,
proc->menu_label),
plug_in_proc->menu_label),
NULL);
strip = gimp_strip_uline (menu);
@ -228,9 +244,150 @@ plug_in_menus_setup (GimpUIManager *manager,
g_object_set_data (G_OBJECT (manager), "ui-path", NULL);
g_tree_destroy (menu_entries);
g_signal_connect_object (manager->gimp->pdb, "register-procedure",
G_CALLBACK (plug_in_menus_register_procedure),
manager, 0);
g_signal_connect_object (manager->gimp->pdb, "unregister-procedure",
G_CALLBACK (plug_in_menus_unregister_procedure),
manager, 0);
}
void
/* private functions */
static void
plug_in_menus_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpUIManager *manager)
{
if (GIMP_IS_PLUG_IN_PROCEDURE (procedure))
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (procedure);
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_menus_menu_path_added),
manager, 0);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
{
GList *list;
#if 0
g_print ("%s: %s\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (procedure)));
#endif
for (list = plug_in_proc->menu_paths; list; list = g_list_next (list))
plug_in_menus_menu_path_added (plug_in_proc, list->data, manager);
}
}
}
static void
plug_in_menus_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure,
GimpUIManager *manager)
{
if (GIMP_IS_PLUG_IN_PROCEDURE (procedure))
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (procedure);
g_signal_handlers_disconnect_by_func (plug_in_proc,
plug_in_menus_menu_path_added,
manager);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
{
GList *list;
#if 0
g_print ("%s: %s\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (procedure)));
#endif
for (list = plug_in_proc->menu_paths; list; list = g_list_next (list))
{
if (! strncmp (list->data, manager->name, strlen (manager->name)))
{
gchar *merge_key;
guint merge_id;
merge_key = g_strdup_printf ("%s-merge-id",
GIMP_OBJECT (plug_in_proc)->name);
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
merge_key));
g_free (merge_key);
if (merge_id)
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager),
merge_id);
break;
}
}
}
}
}
static void
plug_in_menus_menu_path_added (GimpPlugInProcedure *plug_in_proc,
const gchar *menu_path,
GimpUIManager *manager)
{
#if 0
g_print ("%s: %s (%s)\n", G_STRFUNC,
gimp_object_get_name (GIMP_OBJECT (plug_in_proc)), menu_path);
#endif
if (! strncmp (menu_path, manager->name, strlen (manager->name)))
{
if (! strcmp (manager->name, "<Image>"))
{
plug_in_menus_add_proc (manager, "/image-menubar",
plug_in_proc, menu_path);
plug_in_menus_add_proc (manager, "/dummy-menubar/image-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Toolbox>"))
{
plug_in_menus_add_proc (manager, "/toolbox-menubar",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Brushes>"))
{
plug_in_menus_add_proc (manager, "/brushes-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Gradients>"))
{
plug_in_menus_add_proc (manager, "/gradients-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Palettes>"))
{
plug_in_menus_add_proc (manager, "/palettes-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Patterns>"))
{
plug_in_menus_add_proc (manager, "/patterns-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Fonts>"))
{
plug_in_menus_add_proc (manager, "/fonts-popup",
plug_in_proc, menu_path);
}
else if (! strcmp (manager->name, "<Buffers>"))
{
plug_in_menus_add_proc (manager, "/buffers-popup",
plug_in_proc, menu_path);
}
}
}
static void
plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
GimpPlugInProcedure *proc,
@ -317,28 +474,6 @@ plug_in_menus_add_proc (GimpUIManager *manager,
g_free (path);
}
void
plug_in_menus_remove_proc (GimpUIManager *manager,
GimpPlugInProcedure *proc)
{
gchar *merge_key;
guint merge_id;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
merge_key = g_strdup_printf ("%s-merge-id", GIMP_OBJECT (proc)->name);
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
merge_key));
g_free (merge_key);
if (merge_id)
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
}
/* private functions */
static gboolean
plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,

View File

@ -20,18 +20,12 @@
#define __PLUG_IN_MENUS_H__
void plug_in_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_plugins_domain);
void plug_in_menus_init (Gimp *gimp,
GSList *plug_in_defs,
const gchar *std_plugins_domain);
void plug_in_menus_setup (GimpUIManager *manager,
const gchar *ui_path);
void plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *ui_path,
GimpPlugInProcedure *proc,
const gchar *menu_path);
void plug_in_menus_remove_proc (GimpUIManager *manager,
GimpPlugInProcedure *proc);
void plug_in_menus_setup (GimpUIManager *manager,
const gchar *ui_path);
#endif /* __PLUG_IN_MENUS_H__ */

View File

@ -33,6 +33,7 @@
#include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
#include "core/gimpprogress.h"
#include "gimppdb.h"
@ -54,21 +55,35 @@ gimp_pdb_eek (void)
}
static void gimp_pdb_finalize (GObject *object);
static gint64 gimp_pdb_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_pdb_entry_free (gpointer key,
gpointer value,
gpointer user_data);
static void gimp_pdb_entry_memsize (gpointer key,
gpointer value,
gpointer user_data);
enum
{
REGISTER_PROCEDURE,
UNREGISTER_PROCEDURE,
LAST_SIGNAL
};
static void gimp_pdb_finalize (GObject *object);
static gint64 gimp_pdb_get_memsize (GimpObject *object,
gint64 *gui_size);
static void gimp_pdb_real_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure);
static void gimp_pdb_real_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure);
static void gimp_pdb_entry_free (gpointer key,
gpointer value,
gpointer user_data);
static void gimp_pdb_entry_memsize (gpointer key,
gpointer value,
gpointer user_data);
G_DEFINE_TYPE (GimpPDB, gimp_pdb, GIMP_TYPE_OBJECT);
#define parent_class gimp_pdb_parent_class
static guint gimp_pdb_signals[LAST_SIGNAL] = { 0 };
static void
gimp_pdb_class_init (GimpPDBClass *klass)
@ -76,9 +91,32 @@ gimp_pdb_class_init (GimpPDBClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
gimp_pdb_signals[REGISTER_PROCEDURE] =
g_signal_new ("register-procedure",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpPDBClass, register_procedure),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_PROCEDURE);
gimp_pdb_signals[UNREGISTER_PROCEDURE] =
g_signal_new ("unregister-procedure",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpPDBClass, unregister_procedure),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_PROCEDURE);
object_class->finalize = gimp_pdb_finalize;
gimp_object_class->get_memsize = gimp_pdb_get_memsize;
klass->register_procedure = gimp_pdb_real_register_procedure;
klass->unregister_procedure = gimp_pdb_real_unregister_procedure;
}
static void
@ -125,6 +163,45 @@ gimp_pdb_get_memsize (GimpObject *object,
gui_size);
}
static void
gimp_pdb_real_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure)
{
const gchar *name;
GList *list;
name = gimp_object_get_name (GIMP_OBJECT (procedure));
list = g_hash_table_lookup (pdb->procedures, name);
g_hash_table_insert (pdb->procedures, (gpointer) name,
g_list_prepend (list, g_object_ref (procedure)));
}
static void
gimp_pdb_real_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure)
{
const gchar *name;
GList *list;
name = gimp_object_get_name (GIMP_OBJECT (procedure));
list = g_hash_table_lookup (pdb->procedures, name);
if (list)
{
list = g_list_remove (list, procedure);
if (list)
g_hash_table_insert (pdb->procedures, (gpointer) name, list);
else
g_hash_table_remove (pdb->procedures, name);
g_object_unref (procedure);
}
}
/* public functions */
@ -148,45 +225,22 @@ void
gimp_pdb_register_procedure (GimpPDB *pdb,
GimpProcedure *procedure)
{
const gchar *name;
GList *list;
g_return_if_fail (GIMP_IS_PDB (pdb));
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
name = gimp_object_get_name (GIMP_OBJECT (procedure));
list = g_hash_table_lookup (pdb->procedures, name);
g_hash_table_insert (pdb->procedures, (gpointer) name,
g_list_prepend (list, g_object_ref (procedure)));
g_signal_emit (pdb, gimp_pdb_signals[REGISTER_PROCEDURE], 0,
procedure);
}
void
gimp_pdb_unregister_procedure (GimpPDB *pdb,
GimpProcedure *procedure)
{
const gchar *name;
GList *list;
g_return_if_fail (GIMP_IS_PDB (pdb));
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
name = gimp_object_get_name (GIMP_OBJECT (procedure));
list = g_hash_table_lookup (pdb->procedures, name);
if (list)
{
list = g_list_remove (list, procedure);
if (list)
g_hash_table_insert (pdb->procedures, (gpointer) name, list);
else
g_hash_table_remove (pdb->procedures, name);
g_object_unref (procedure);
}
g_signal_emit (pdb, gimp_pdb_signals[UNREGISTER_PROCEDURE], 0,
procedure);
}
GimpProcedure *

View File

@ -46,6 +46,11 @@ struct _GimpPDB
struct _GimpPDBClass
{
GimpObjectClass parent_class;
void (* register_procedure) (GimpPDB *pdb,
GimpProcedure *procedure);
void (* unregister_procedure) (GimpPDB *pdb,
GimpProcedure *procedure);
};

View File

@ -30,6 +30,7 @@
#include "pdb-types.h"
#include "core/gimp.h"
#include "core/gimpmarshal.h"
#include "core/gimpparamspecs.h"
#include "plug-in/plug-in.h"
@ -42,6 +43,13 @@
#include "gimp-intl.h"
enum
{
MENU_PATH_ADDED,
LAST_SIGNAL
};
static void gimp_plug_in_procedure_finalize (GObject *object);
static gint64 gimp_plug_in_procedure_get_memsize (GimpObject *object,
@ -67,6 +75,8 @@ G_DEFINE_TYPE (GimpPlugInProcedure, gimp_plug_in_procedure,
#define parent_class gimp_plug_in_procedure_parent_class
static guint gimp_plug_in_procedure_signals[LAST_SIGNAL] = { 0 };
static void
gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
@ -75,6 +85,16 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpProcedureClass *proc_class = GIMP_PROCEDURE_CLASS (klass);
gimp_plug_in_procedure_signals[MENU_PATH_ADDED] =
g_signal_new ("menu-path-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpPlugInProcedureClass, menu_path_added),
NULL, NULL,
gimp_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
object_class->finalize = gimp_plug_in_procedure_finalize;
gimp_object_class->get_memsize = gimp_plug_in_procedure_get_memsize;
@ -83,6 +103,7 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
proc_class->execute_async = gimp_plug_in_procedure_execute_async;
klass->get_progname = gimp_plug_in_procedure_real_get_progname;
klass->menu_path_added = NULL;
}
static void
@ -431,6 +452,9 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
proc->menu_paths = g_list_append (proc->menu_paths, g_strdup (menu_path));
g_signal_emit (proc, gimp_plug_in_procedure_signals[MENU_PATH_ADDED], 0,
menu_path);
return TRUE;
failure:

View File

@ -52,7 +52,7 @@ struct _GimpPlugInProcedure
gchar *image_types;
PlugInImageType image_types_val;
time_t mtime;
gboolean installed_during_init;
gboolean installed_during_init;
/* file proc specific members */
gboolean file_proc;
@ -70,7 +70,12 @@ struct _GimpPlugInProcedureClass
{
GimpProcedureClass parent_class;
const gchar * (* get_progname) (const GimpPlugInProcedure *procedure);
/* virtual functions */
const gchar * (* get_progname) (const GimpPlugInProcedure *procedure);
/* signals */
void (* menu_path_added) (GimpPlugInProcedure *procedure,
const gchar *menu_path);
};

View File

@ -1059,11 +1059,6 @@ plug_in_menu_register (PlugIn *plug_in,
return FALSE;
}
if (GIMP_IS_TEMPORARY_PROCEDURE (proc) && ! plug_in->gimp->no_interface)
{
gimp_menus_create_item (plug_in->gimp, proc, menu_path);
}
return TRUE;
}

View File

@ -246,12 +246,6 @@ plug_ins_init (Gimp *gimp,
g_free (pluginrc);
/* add the plug-in procs to the procedure database */
for (list = gimp->plug_in_procedures; list; list = list->next)
{
plug_ins_add_to_db (gimp, context, list->data);
}
/* create help_path and locale_domain lists */
for (list = gimp->plug_in_defs; list; list = list->next)
{
@ -283,6 +277,12 @@ plug_ins_init (Gimp *gimp,
plug_in_standard_locale_domain ());
}
/* add the plug-in procs to the procedure database */
for (list = gimp->plug_in_procedures; list; list = list->next)
{
plug_ins_add_to_db (gimp, context, list->data);
}
/* build list of automatically started extensions */
for (list = gimp->plug_in_procedures, nth = 0; list; list = list->next, nth++)
{
@ -411,14 +411,6 @@ plug_ins_temp_procedure_add (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (proc));
if (! gimp->no_interface)
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
gimp_menus_create_item (gimp, plug_in_proc, NULL);
}
/* Register the procedural database entry */
gimp_pdb_register_procedure (gimp->pdb, GIMP_PROCEDURE (proc));
@ -434,14 +426,6 @@ plug_ins_temp_procedure_remove (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (proc));
if (! gimp->no_interface)
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
gimp_menus_delete_item (gimp, plug_in_proc);
}
/* Remove the definition from the global list */
gimp->plug_in_procedures = g_slist_remove (gimp->plug_in_procedures, proc);

View File

@ -30,6 +30,7 @@
#include "pdb-types.h"
#include "core/gimp.h"
#include "core/gimpmarshal.h"
#include "core/gimpparamspecs.h"
#include "plug-in/plug-in.h"
@ -42,6 +43,13 @@
#include "gimp-intl.h"
enum
{
MENU_PATH_ADDED,
LAST_SIGNAL
};
static void gimp_plug_in_procedure_finalize (GObject *object);
static gint64 gimp_plug_in_procedure_get_memsize (GimpObject *object,
@ -67,6 +75,8 @@ G_DEFINE_TYPE (GimpPlugInProcedure, gimp_plug_in_procedure,
#define parent_class gimp_plug_in_procedure_parent_class
static guint gimp_plug_in_procedure_signals[LAST_SIGNAL] = { 0 };
static void
gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
@ -75,6 +85,16 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpProcedureClass *proc_class = GIMP_PROCEDURE_CLASS (klass);
gimp_plug_in_procedure_signals[MENU_PATH_ADDED] =
g_signal_new ("menu-path-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpPlugInProcedureClass, menu_path_added),
NULL, NULL,
gimp_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
object_class->finalize = gimp_plug_in_procedure_finalize;
gimp_object_class->get_memsize = gimp_plug_in_procedure_get_memsize;
@ -83,6 +103,7 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
proc_class->execute_async = gimp_plug_in_procedure_execute_async;
klass->get_progname = gimp_plug_in_procedure_real_get_progname;
klass->menu_path_added = NULL;
}
static void
@ -431,6 +452,9 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
proc->menu_paths = g_list_append (proc->menu_paths, g_strdup (menu_path));
g_signal_emit (proc, gimp_plug_in_procedure_signals[MENU_PATH_ADDED], 0,
menu_path);
return TRUE;
failure:

View File

@ -52,7 +52,7 @@ struct _GimpPlugInProcedure
gchar *image_types;
PlugInImageType image_types_val;
time_t mtime;
gboolean installed_during_init;
gboolean installed_during_init;
/* file proc specific members */
gboolean file_proc;
@ -70,7 +70,12 @@ struct _GimpPlugInProcedureClass
{
GimpProcedureClass parent_class;
const gchar * (* get_progname) (const GimpPlugInProcedure *procedure);
/* virtual functions */
const gchar * (* get_progname) (const GimpPlugInProcedure *procedure);
/* signals */
void (* menu_path_added) (GimpPlugInProcedure *procedure,
const gchar *menu_path);
};

View File

@ -1059,11 +1059,6 @@ plug_in_menu_register (PlugIn *plug_in,
return FALSE;
}
if (GIMP_IS_TEMPORARY_PROCEDURE (proc) && ! plug_in->gimp->no_interface)
{
gimp_menus_create_item (plug_in->gimp, proc, menu_path);
}
return TRUE;
}

View File

@ -246,12 +246,6 @@ plug_ins_init (Gimp *gimp,
g_free (pluginrc);
/* add the plug-in procs to the procedure database */
for (list = gimp->plug_in_procedures; list; list = list->next)
{
plug_ins_add_to_db (gimp, context, list->data);
}
/* create help_path and locale_domain lists */
for (list = gimp->plug_in_defs; list; list = list->next)
{
@ -283,6 +277,12 @@ plug_ins_init (Gimp *gimp,
plug_in_standard_locale_domain ());
}
/* add the plug-in procs to the procedure database */
for (list = gimp->plug_in_procedures; list; list = list->next)
{
plug_ins_add_to_db (gimp, context, list->data);
}
/* build list of automatically started extensions */
for (list = gimp->plug_in_procedures, nth = 0; list; list = list->next, nth++)
{
@ -411,14 +411,6 @@ plug_ins_temp_procedure_add (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (proc));
if (! gimp->no_interface)
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
gimp_menus_create_item (gimp, plug_in_proc, NULL);
}
/* Register the procedural database entry */
gimp_pdb_register_procedure (gimp->pdb, GIMP_PROCEDURE (proc));
@ -434,14 +426,6 @@ plug_ins_temp_procedure_remove (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (proc));
if (! gimp->no_interface)
{
GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
if (plug_in_proc->menu_label || plug_in_proc->menu_paths)
gimp_menus_delete_item (gimp, plug_in_proc);
}
/* Remove the definition from the global list */
gimp->plug_in_procedures = g_slist_remove (gimp->plug_in_procedures, proc);