Commit ca179a77 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Changed plug-in menu registration again to allow passing just the menu

2004-05-07  Michael Natterer  <mitch@gimp.org>

	Changed plug-in menu registration again to allow passing just the
	menu item's label (not the full path) in gimp_install_procedure()
	and only the path (excluding the item's label) in
	gimp_plugin_menu_register(). Matches the internal action system
	better and makes translating the menu paths much easier.

	(Of yourse it's still possible to use the old syntax for backward
	compatibility).

	* app/plug-in/plug-in-proc.[ch]: added "gchar *menu_label".

	* app/plug-in/plug-in-params.[ch]: added new functions
	plug_in_param_defs_check() and plug_in_proc_args_check() which
	check if a procedure's parameters match its menu location
	(e.g. <Image> needs RUN-MODE, IMAGE, DRAWABLE).

	* app/plug-in/plug-in-message.c (plug_in_handle_proc_install): if
	registering an old-style (full) menu_path, use
	plug_in_param_defs_check(), set proc_def->menu_label otherwise.

	* tools/pdbgen/pdb/plug_in.pdb (plugin_menu_register): use
	plug_in_proc_args_check() on the passed menu_path and make sugre
	old and new style menu registration are not mixed.

	* app/pdb/plug_in_cmds.c: regenerated.

	* app/plug-in/plug-in-rc.c: save/restore "menu_label".

	* app/actions/file-dialog-actions.c
	* app/actions/plug-in-actions.c
	* app/menus/plug-in-menus.c: changed action/menu creation
	accordingly. Some hacks needed to allow both old and new style
	menu_label/menu_paths.

	* app/plug-in/plug-in.c
	* app/widgets/gimpfiledialog.c
	* app/xcf/xcf.c: changed accordingly.

	* plug-ins/common/align_layers.c
	* plug-ins/common/animationplay.c
	* plug-ins/common/animoptimize.c
	* plug-ins/common/apply_lens.c
	* plug-ins/common/autocrop.c
	* plug-ins/common/autostretch_hsv.c
	* plug-ins/common/blinds.c
	* plug-ins/common/blur.c
	* plug-ins/common/borderaverage.c
	* plug-ins/common/bumpmap.c
	* plug-ins/common/c_astretch.c
	* plug-ins/common/ccanalyze.c
	* plug-ins/common/channel_mixer.c
	* plug-ins/common/checkerboard.c
	* plug-ins/common/color_enhance.c
	* plug-ins/common/colorify.c
	* plug-ins/common/colortoalpha.c
	* plug-ins/common/compose.c
	* plug-ins/common/convmatrix.c
	* plug-ins/common/cubism.c
	* plug-ins/common/curve_bend.c
	* plug-ins/common/decompose.c
	* plug-ins/common/deinterlace.c
	* plug-ins/common/depthmerge.c
	* plug-ins/common/destripe.c
	* plug-ins/common/diffraction.c
	* plug-ins/common/displace.c
	* plug-ins/common/edge.c
	* plug-ins/common/emboss.c
	* plug-ins/common/engrave.c
	* plug-ins/common/exchange.c
	* plug-ins/common/film.c
	* plug-ins/common/flarefx.c
	* plug-ins/common/fractaltrace.c
	* plug-ins/common/screenshot.c: ported the first few plug-ins
	to the new registration scheme.
parent 4844990e
2004-05-07 Michael Natterer <mitch@gimp.org>
Changed plug-in menu registration again to allow passing just the
menu item's label (not the full path) in gimp_install_procedure()
and only the path (excluding the item's label) in
gimp_plugin_menu_register(). Matches the internal action system
better and makes translating the menu paths much easier.
(Of yourse it's still possible to use the old syntax for backward
compatibility).
* app/plug-in/plug-in-proc.[ch]: added "gchar *menu_label".
* app/plug-in/plug-in-params.[ch]: added new functions
plug_in_param_defs_check() and plug_in_proc_args_check() which
check if a procedure's parameters match its menu location
(e.g. <Image> needs RUN-MODE, IMAGE, DRAWABLE).
* app/plug-in/plug-in-message.c (plug_in_handle_proc_install): if
registering an old-style (full) menu_path, use
plug_in_param_defs_check(), set proc_def->menu_label otherwise.
* tools/pdbgen/pdb/plug_in.pdb (plugin_menu_register): use
plug_in_proc_args_check() on the passed menu_path and make sure
old and new style menu registration are not mixed.
* app/pdb/plug_in_cmds.c: regenerated.
* app/plug-in/plug-in-rc.c: save/restore "menu_label".
* app/actions/file-dialog-actions.c
* app/actions/plug-in-actions.c
* app/menus/plug-in-menus.c: changed action/menu creation
accordingly. Some hacks needed to allow both old and new style
menu_label/menu_paths.
* app/plug-in/plug-in.c
* app/widgets/gimpfiledialog.c
* app/xcf/xcf.c: changed accordingly.
* plug-ins/common/align_layers.c
* plug-ins/common/animationplay.c
* plug-ins/common/animoptimize.c
* plug-ins/common/apply_lens.c
* plug-ins/common/autocrop.c
* plug-ins/common/autostretch_hsv.c
* plug-ins/common/blinds.c
* plug-ins/common/blur.c
* plug-ins/common/borderaverage.c
* plug-ins/common/bumpmap.c
* plug-ins/common/c_astretch.c
* plug-ins/common/ccanalyze.c
* plug-ins/common/channel_mixer.c
* plug-ins/common/checkerboard.c
* plug-ins/common/color_enhance.c
* plug-ins/common/colorify.c
* plug-ins/common/colortoalpha.c
* plug-ins/common/compose.c
* plug-ins/common/convmatrix.c
* plug-ins/common/cubism.c
* plug-ins/common/curve_bend.c
* plug-ins/common/decompose.c
* plug-ins/common/deinterlace.c
* plug-ins/common/depthmerge.c
* plug-ins/common/destripe.c
* plug-ins/common/diffraction.c
* plug-ins/common/displace.c
* plug-ins/common/edge.c
* plug-ins/common/emboss.c
* plug-ins/common/engrave.c
* plug-ins/common/exchange.c
* plug-ins/common/film.c
* plug-ins/common/flarefx.c
* plug-ins/common/fractaltrace.c
* plug-ins/common/screenshot.c: ported the first few plug-ins
to the new registration scheme.
2004-05-06 Manish Singh <yosh@gimp.org>
* tools/pdbgen/pdb/app.pl: make libgimp* headers always included
......
......@@ -51,6 +51,7 @@ file_dialog_actions_setup (GimpActionGroup *group,
const gchar *stock_id = NULL;
gchar *help_id;
GimpPlugInActionEntry entry;
gchar *label;
gboolean is_xcf;
if (! file_proc->menu_paths)
......@@ -77,9 +78,14 @@ file_dialog_actions_setup (GimpActionGroup *group,
help_id = plug_in_proc_def_get_help_id (file_proc, help_domain);
}
if (file_proc->menu_label)
label = file_proc->menu_label;
else
label = strrchr (file_proc->menu_paths->data, '/') + 1;
entry.name = file_proc->db_info.name;
entry.stock_id = stock_id;
entry.label = strstr (file_proc->menu_paths->data, "/") + 1;
entry.label = label;
entry.accelerator = file_proc->accelerator;
entry.tooltip = NULL;
entry.proc_def = file_proc;
......
......@@ -269,18 +269,32 @@ plug_in_actions_add_proc (GimpActionGroup *group,
help_id = plug_in_proc_def_get_help_id (proc_def, help_domain);
path_original = g_strdup (proc_def->menu_paths->data);
path_translated = g_strdup (dgettext (locale_domain, path_original));
if (proc_def->menu_label)
{
path_original = g_strdup (proc_def->menu_label);
path_translated = g_strdup (dgettext (locale_domain, path_original));
p1 = strrchr (path_original, '/');
p2 = strrchr (path_translated, '/');
p1 = path_original;
p2 = path_translated;
}
else
{
path_original = g_strdup (proc_def->menu_paths->data);
path_translated = g_strdup (dgettext (locale_domain, path_original));
p1 = strrchr (path_original, '/');
p2 = strrchr (path_translated, '/');
}
if (p1 && p2)
{
GimpPlugInActionEntry entry;
gchar *label;
label = p2 + 1;
if (proc_def->menu_label)
label = proc_def->menu_label;
else
label = p2 + 1;
entry.name = proc_def->db_info.name;
entry.stock_id = NULL;
......@@ -298,10 +312,22 @@ plug_in_actions_add_proc (GimpActionGroup *group,
gimp_action_group_add_plug_in_actions (group, &entry, 1,
G_CALLBACK (plug_in_run_cmd_callback));
*p1 = '\0';
*p2 = '\0';
if (proc_def->menu_label)
{
GList *list;
plug_in_actions_build_path (group, path_original, path_translated);
for (list = proc_def->menu_paths; list; list = g_list_next (list))
plug_in_actions_build_path (group,
list->data,
dgettext (locale_domain, list->data));
}
else
{
*p1 = '\0';
*p2 = '\0';
plug_in_actions_build_path (group, path_original, path_translated);
}
}
g_free (path_original);
......
......@@ -41,7 +41,7 @@
/* local function prototypes */
static gboolean plug_in_menus_tree_traverse (const gchar *menu_path,
static gboolean plug_in_menus_tree_traverse (gchar *menu_path,
PlugInProcDef *proc_def,
GimpUIManager *manager);
static void plug_in_menus_build_path (GimpUIManager *manager,
......@@ -140,6 +140,7 @@ plug_in_menus_setup (GimpUIManager *manager,
{
const gchar *progname;
const gchar *locale_domain;
gchar *stripped;
gchar *key;
progname = plug_in_proc_def_get_progname (proc_def);
......@@ -147,7 +148,17 @@ plug_in_menus_setup (GimpUIManager *manager,
locale_domain = plug_ins_locale_domain (manager->gimp,
progname, NULL);
key = gimp_strip_uline (dgettext (locale_domain, path->data));
stripped = gimp_strip_uline (dgettext (locale_domain,
path->data));
if (proc_def->menu_label)
key = g_strdup_printf ("%s/%s",
stripped, proc_def->menu_label);
else
key = g_strdup (stripped);
g_free (stripped);
g_tree_insert (menu_entries, key, proc_def);
}
}
......@@ -172,7 +183,9 @@ plug_in_menus_add_proc (GimpUIManager *manager,
const gchar *menu_path)
{
gchar *path;
gchar *p;
gchar *action_path;
gchar *merge_key;
guint merge_id;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
......@@ -180,49 +193,43 @@ plug_in_menus_add_proc (GimpUIManager *manager,
path = g_strdup (menu_path);
p = strrchr (path, '/');
if (p)
if (! proc_def->menu_label)
{
gchar *action_path;
gchar *merge_key;
guint merge_id;
gchar *p = strrchr (path, '/');
*p = '\0';
}
merge_key = g_strdup_printf ("%s-merge-id", proc_def->db_info.name);
merge_key = g_strdup_printf ("%s-merge-id", proc_def->db_info.name);
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
merge_key));
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
merge_key));
if (! merge_id)
{
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
g_object_set_data (G_OBJECT (manager), merge_key,
GUINT_TO_POINTER (merge_id));
}
if (! merge_id)
{
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
g_object_set_data (G_OBJECT (manager), merge_key,
GUINT_TO_POINTER (merge_id));
}
g_free (merge_key);
g_free (merge_key);
plug_in_menus_build_path (manager, ui_path, merge_id, path);
plug_in_menus_build_path (manager, ui_path, merge_id, path);
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
action_path = g_strdup_printf ("%s%s", ui_path, strchr (path, '/'));
#if 0
g_print ("adding UI for '%s' (@ %s)\n",
proc_def->db_info.name, action_path);
g_print ("adding UI for '%s' (@ %s)\n",
proc_def->db_info.name, action_path);
#endif
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);
}
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);
}
......@@ -249,12 +256,18 @@ plug_in_menus_remove_proc (GimpUIManager *manager,
/* private functions */
static gboolean
plug_in_menus_tree_traverse (const gchar *menu_path,
plug_in_menus_tree_traverse (gchar *menu_path,
PlugInProcDef *proc_def,
GimpUIManager *manager)
{
const gchar *ui_path = g_object_get_data (G_OBJECT (manager), "ui-path");
if (proc_def->menu_label)
{
gchar *p = strrchr (menu_path, '/');
*p = '\0';
}
plug_in_menus_add_proc (manager, ui_path, proc_def, menu_path);
return FALSE;
......
......@@ -73,6 +73,7 @@ plug_in_proc_def_free (PlugInProcDef *proc_def)
g_free (proc_def->db_info.values);
g_free (proc_def->prog);
g_free (proc_def->menu_label);
g_list_foreach (proc_def->menu_paths, (GFunc) g_free, NULL);
g_list_free (proc_def->menu_paths);
......@@ -144,9 +145,9 @@ plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def,
}
gint
plug_in_proc_def_compare_menu_path (gconstpointer a,
gconstpointer b,
gpointer user_data)
plug_in_proc_def_compare_menu_path (gconstpointer a,
gconstpointer b,
gpointer user_data)
{
Gimp *gimp = GIMP (user_data);
const PlugInProcDef *proc_def_a = a;
......
......@@ -27,6 +27,7 @@
struct _PlugInProcDef
{
gchar *prog;
gchar *menu_label;
GList *menu_paths;
gchar *accelerator;
gchar *extensions;
......
......@@ -28,12 +28,14 @@
#include "libgimpbase/gimpbasetypes.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimpprotocol.h"
#include "pdb-types.h"
#include "procedural_db.h"
#include "core/gimp.h"
#include "plug-in/plug-in-def.h"
#include "plug-in/plug-in-params.h"
#include "plug-in/plug-in-proc.h"
#include "plug-in/plug-in-progress.h"
#include "plug-in/plug-in.h"
......@@ -525,8 +527,46 @@ plugin_menu_register_invoker (Gimp *gimp,
if (! strcmp (procedure_name, proc_def->db_info.name))
{
proc_def->menu_paths = g_list_append (proc_def->menu_paths,
g_strdup (menu_path));
if (proc_def->menu_label)
{
GError *error = NULL;
if (! plug_in_proc_args_check (gimp->current_plug_in->name,
gimp->current_plug_in->prog,
procedure_name,
menu_path,
proc_def->db_info.args,
proc_def->db_info.num_args,
proc_def->db_info.values,
proc_def->db_info.num_values,
&error))
{
g_message (error->message);
g_clear_error (&error);
success = FALSE;
}
else
{
proc_def->menu_paths = g_list_append (proc_def->menu_paths,
g_strdup (menu_path));
}
}
else
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install additional menu_path \"%s\"\n"
"for procedure \"%s\".\n"
"However the menu_path given in "
"gimp_install_procedure() already contained "
"a path. To make this work, pass just the menu's "
"label to gimp_install_procedure().",
gimp_filename_to_utf8 (gimp->current_plug_in->name),
gimp_filename_to_utf8 (gimp->current_plug_in->prog),
menu_path, procedure_name);
success = FALSE;
}
break;
}
......
......@@ -543,92 +543,25 @@ plug_in_handle_proc_install (PlugIn *plug_in,
* --only sanity check arguments when the procedure requests a menu path
*/
if (proc_install->menu_path)
if (proc_install->menu_path && proc_install->menu_path[0] == '<')
{
if (strncmp (proc_install->menu_path, "<Toolbox>", 9) == 0)
{
if ((proc_install->nparams < 1) ||
(proc_install->params[0].type != GIMP_PDB_INT32))
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install <Toolbox> procedure \"%s\" "
"which does not take the standard <Toolbox> Plug-In "
"args.\n"
"(INT32)",
gimp_filename_to_utf8 (plug_in->name),
gimp_filename_to_utf8 (plug_in->prog),
proc_install->name);
return;
}
}
else if (strncmp (proc_install->menu_path, "<Image>", 7) == 0)
{
if ((proc_install->nparams < 3) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE))
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install <Image> procedure \"%s\" "
"which does not take the standard <Image> Plug-In "
"args.\n"
"(INT32, IMAGE, DRAWABLE)",
gimp_filename_to_utf8 (plug_in->name),
gimp_filename_to_utf8 (plug_in->prog),
proc_install->name);
return;
}
}
else if (strncmp (proc_install->menu_path, "<Load>", 6) == 0)
{
if ((proc_install->nparams < 3) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_STRING) ||
(proc_install->params[2].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install <Load> procedure \"%s\" "
"which does not take the standard <Load> Plug-In "
"args.\n"
"(INT32, STRING, STRING)",
gimp_filename_to_utf8 (plug_in->name),
gimp_filename_to_utf8 (plug_in->prog),
proc_install->name);
return;
}
}
else if (strncmp (proc_install->menu_path, "<Save>", 6) == 0)
{
if ((proc_install->nparams < 5) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[4].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install <Save> procedure \"%s\" "
"which does not take the standard <Save> Plug-In "
"args.\n"
"(INT32, IMAGE, DRAWABLE, STRING, STRING)",
gimp_filename_to_utf8 (plug_in->name),
gimp_filename_to_utf8 (plug_in->prog),
proc_install->name);
return;
}
}
else
{
g_message ("Plug-In \"%s\"\n(%s)\n\n"
"attempted to install procedure \"%s\" "
"in an invalid menu location.\n"
"Use either \"<Toolbox>\", \"<Image>\", "
"\"<Load>\", or \"<Save>\".",
gimp_filename_to_utf8 (plug_in->name),
gimp_filename_to_utf8 (plug_in->prog),
proc_install->name);
return;
}
GError *error = NULL;
if (! plug_in_param_defs_check (plug_in->name,
plug_in->prog,
proc_install->name,
proc_install->menu_path,
proc_install->params,
proc_install->nparams,
proc_install->return_vals,
proc_install->nreturn_vals,
&error))
{
g_message (error->message);
g_clear_error (&error);
return;
}
}
/* Sanity check for array arguments */
......@@ -746,12 +679,17 @@ plug_in_handle_proc_install (PlugIn *plug_in,
proc_def = plug_in_proc_def_new ();
proc_def->prog = g_strdup (prog);
if (proc_install->menu_path)
proc_def->menu_paths = g_list_append (proc_def->menu_paths,
g_strdup (proc_install->menu_path));
{
if (proc_install->menu_path[0] == '<')
proc_def->menu_paths =
g_list_append (proc_def->menu_paths,
g_strdup (proc_install->menu_path));
else
proc_def->menu_label = g_strdup (proc_install->menu_path);
}
proc_def->prog = g_strdup (prog);
proc_def->accelerator = NULL;
proc_def->extensions = NULL;
proc_def->prefixes = NULL;
......
......@@ -890,7 +890,6 @@ gchar *
plug_in_get_undo_desc (PlugIn *plug_in)
{
PlugInProcDef *proc_def;
gchar *stripped;
gchar *undo_desc;
g_return_val_if_fail (plug_in != NULL, NULL);
......@@ -904,17 +903,28 @@ plug_in_get_undo_desc (PlugIn *plug_in)
else
proc_def = NULL;
if (proc_def && proc_def->menu_paths)
if (proc_def && (proc_def->menu_label || proc_def->menu_paths))
{
const gchar *path;
gchar *stripped;
gchar *ellipses;
path = dgettext (plug_ins_locale_domain (plug_in->gimp,
plug_in->prog, NULL),
proc_def->menu_paths->data);
if (proc_def->menu_label)
path = dgettext (plug_ins_locale_domain (plug_in->gimp,
plug_in->prog, NULL),
proc_def->menu_label);
else
path = dgettext (plug_ins_locale_domain (plug_in->gimp,
plug_in->prog, NULL),
proc_def->menu_paths->data);
stripped = gimp_strip_uline (path);
if (proc_def->menu_label)
undo_desc = g_strdup (stripped);
else
undo_desc = g_strdup (strrchr (stripped, '/') + 1);
stripped = gimp_strip_uline (path);
undo_desc = g_path_get_basename (stripped);
g_free (stripped);
ellipses = strstr (undo_desc, "...");
......
......@@ -73,6 +73,7 @@ plug_in_proc_def_free (PlugInProcDef *proc_def)
g_free (proc_def->db_info.values);
g_free (proc_def->prog);
g_free (proc_def->menu_label);
g_list_foreach (proc_def->menu_paths, (GFunc) g_free, NULL);
g_list_free (proc_def->menu_paths);
......@@ -144,9 +145,9 @@ plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def,
}
gint
plug_in_proc_def_compare_menu_path (gconstpointer a,
gconstpointer b,
gpointer user_data)
plug_in_proc_def_compare_menu_path (gconstpointer a,
gconstpointer b,
gpointer user_data)
{