diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c index 120b24bae8..d352c30616 100644 --- a/app/pdb/pdb-cmds.c +++ b/app/pdb/pdb-cmds.c @@ -34,7 +34,9 @@ #include "core/gimpparamspecs.h" #include "gimp-pdb-compat.h" #include "gimppdb-query.h" +#include "plug-in/gimpplugin.h" #include "plug-in/gimppluginmanager-data.h" +#include "plug-in/gimppluginmanager.h" #include "plug-in/gimppluginprocedure.h" #include "gimppdb.h" @@ -345,6 +347,39 @@ pdb_get_proc_menu_label_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +pdb_add_proc_menu_path_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + const gchar *procedure_name; + const gchar *menu_path; + + procedure_name = g_value_get_string (gimp_value_array_index (args, 0)); + menu_path = g_value_get_string (gimp_value_array_index (args, 1)); + + if (success) + { + GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; + + if (plug_in && + gimp_pdb_is_canonical_procedure (procedure_name, error)) + { + success = gimp_plug_in_add_proc_menu_path (plug_in, procedure_name, + menu_path); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * pdb_get_proc_menu_paths_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -968,6 +1003,36 @@ register_pdb_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-pdb-add-proc-menu-path + */ + procedure = gimp_procedure_new (pdb_add_proc_menu_path_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-pdb-add-proc-menu-path"); + gimp_procedure_set_static_strings (procedure, + "Register an additional menu path for a plug-in procedure.", + "This procedure installs an additional menu entry for the given procedure.", + "Michael Natterer ", + "Michael Natterer", + "2019", + NULL); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("procedure-name", + "procedure name", + "The procedure for which to install the menu path", + FALSE, FALSE, TRUE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("menu-path", + "menu path", + "The procedure's additional menu path", + FALSE, FALSE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-pdb-get-proc-menu-paths */ diff --git a/app/pdb/plug-in-cmds.c b/app/pdb/plug-in-cmds.c index 03ab051021..84a3f341fd 100644 --- a/app/pdb/plug-in-cmds.c +++ b/app/pdb/plug-in-cmds.c @@ -182,38 +182,6 @@ plugin_menu_branch_register_invoker (GimpProcedure *procedure, error ? *error : NULL); } -static GimpValueArray * -plugin_menu_register_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - const gchar *procedure_name; - const gchar *menu_path; - - procedure_name = g_value_get_string (gimp_value_array_index (args, 0)); - menu_path = g_value_get_string (gimp_value_array_index (args, 1)); - - if (success) - { - GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; - - if (plug_in && - gimp_pdb_is_canonical_procedure (procedure_name, error)) - { - success = gimp_plug_in_menu_register (plug_in, procedure_name, menu_path); - } - else - success = FALSE; - } - - return gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); -} - static GimpValueArray * plugin_icon_register_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -481,36 +449,6 @@ register_plug_in_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - /* - * gimp-plugin-menu-register - */ - procedure = gimp_procedure_new (plugin_menu_register_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-plugin-menu-register"); - gimp_procedure_set_static_strings (procedure, - "Register an additional menu path for a plug-in procedure.", - "This procedure installs an additional menu entry for the given procedure.", - "Michael Natterer ", - "Michael Natterer", - "2004", - NULL); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("procedure-name", - "procedure name", - "The procedure for which to install the menu path", - FALSE, FALSE, TRUE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("menu-path", - "menu path", - "The procedure's additional menu path", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-plugin-icon-register */ diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 424d79472a..57f3eff5c4 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -874,11 +874,11 @@ gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in) return undo_desc ? undo_desc : gimp_object_get_name (plug_in); } -/* called from the PDB (gimp_plugin_menu_register) */ +/* called from the PDB (gimp_pdb_add_proc_menu_path) */ gboolean -gimp_plug_in_menu_register (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_path) +gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_path) { GimpPlugInProcedure *proc = NULL; GError *error = NULL; @@ -900,8 +900,8 @@ gimp_plug_in_menu_register (GimpPlugIn *plug_in, "Plug-in \"%s\"\n(%s)\n" "attempted to register the menu item \"%s\" " "for the procedure \"%s\".\n" - "It has however not installed that procedure. This " - "is not allowed.", + "It has however not installed that procedure. " + "This is not allowed.", gimp_object_get_name (plug_in), gimp_file_get_utf8_name (plug_in->file), menu_path, proc_name); @@ -929,7 +929,7 @@ gimp_plug_in_menu_register (GimpPlugIn *plug_in, gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, "Plug-in \"%s\"\n(%s)\n" "attempted to register the procedure \"%s\" " - "in the menu \"%s\", but the procedure has no label. " + "in the menu \"%s\", but the procedure has no label. " "This is not allowed.", gimp_object_get_name (plug_in), gimp_file_get_utf8_name (plug_in->file), diff --git a/app/plug-in/gimpplugin.h b/app/plug-in/gimpplugin.h index 2cd3756467..659f70ca28 100644 --- a/app/plug-in/gimpplugin.h +++ b/app/plug-in/gimpplugin.h @@ -76,48 +76,48 @@ struct _GimpPlugInClass }; -GType gimp_plug_in_get_type (void) G_GNUC_CONST; +GType gimp_plug_in_get_type (void) G_GNUC_CONST; -GimpPlugIn * gimp_plug_in_new (GimpPlugInManager *manager, - GimpContext *context, - GimpProgress *progress, - GimpPlugInProcedure *procedure, - GFile *file); +GimpPlugIn * gimp_plug_in_new (GimpPlugInManager *manager, + GimpContext *context, + GimpProgress *progress, + GimpPlugInProcedure *procedure, + GFile *file); -gboolean gimp_plug_in_open (GimpPlugIn *plug_in, - GimpPlugInCallMode call_mode, - gboolean synchronous); -void gimp_plug_in_close (GimpPlugIn *plug_in, - gboolean kill_it); +gboolean gimp_plug_in_open (GimpPlugIn *plug_in, + GimpPlugInCallMode call_mode, + gboolean synchronous); +void gimp_plug_in_close (GimpPlugIn *plug_in, + gboolean kill_it); GimpPlugInProcFrame * - gimp_plug_in_get_proc_frame (GimpPlugIn *plug_in); + gimp_plug_in_get_proc_frame (GimpPlugIn *plug_in); GimpPlugInProcFrame * - gimp_plug_in_proc_frame_push (GimpPlugIn *plug_in, - GimpContext *context, - GimpProgress *progress, - GimpTemporaryProcedure *procedure); -void gimp_plug_in_proc_frame_pop (GimpPlugIn *plug_in); + gimp_plug_in_proc_frame_push (GimpPlugIn *plug_in, + GimpContext *context, + GimpProgress *progress, + GimpTemporaryProcedure *procedure); +void gimp_plug_in_proc_frame_pop (GimpPlugIn *plug_in); -void gimp_plug_in_main_loop (GimpPlugIn *plug_in); -void gimp_plug_in_main_loop_quit (GimpPlugIn *plug_in); +void gimp_plug_in_main_loop (GimpPlugIn *plug_in); +void gimp_plug_in_main_loop_quit (GimpPlugIn *plug_in); -const gchar * gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in); +const gchar * gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in); -gboolean gimp_plug_in_menu_register (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_path); +gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_path); -void gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in, - GimpTemporaryProcedure *procedure); -void gimp_plug_in_remove_temp_proc (GimpPlugIn *plug_in, - GimpTemporaryProcedure *procedure); +void gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in, + GimpTemporaryProcedure *procedure); +void gimp_plug_in_remove_temp_proc (GimpPlugIn *plug_in, + GimpTemporaryProcedure *procedure); -void gimp_plug_in_set_error_handler (GimpPlugIn *plug_in, - GimpPDBErrorHandler handler); +void gimp_plug_in_set_error_handler (GimpPlugIn *plug_in, + GimpPDBErrorHandler handler); GimpPDBErrorHandler - gimp_plug_in_get_error_handler (GimpPlugIn *plug_in); + gimp_plug_in_get_error_handler (GimpPlugIn *plug_in); #endif /* __GIMP_PLUG_IN_H__ */ diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index c11e7019ad..2e9e9fe542 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -619,6 +619,24 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, procedure = GIMP_PROCEDURE (proc); + if (! proc->menu_label) + { + basename = g_path_get_basename (gimp_file_get_utf8_name (proc->file)); + + g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_FAILED, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register the procedure \"%s\" " + "in the menu \"%s\", but the procedure has no label. " + "This is not allowed.", + basename, gimp_file_get_utf8_name (proc->file), + gimp_object_get_name (proc), + menu_path); + + g_free (basename); + + return FALSE; + } + p = strchr (menu_path, '>'); if (p == NULL || (*(++p) && *p != '/')) { diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c index b847805160..2c9edfe3c1 100644 --- a/libgimp/gimppdb_pdb.c +++ b/libgimp/gimppdb_pdb.c @@ -338,6 +338,45 @@ _gimp_pdb_get_proc_menu_label (const gchar *procedure_name) return menu_label; } +/** + * _gimp_pdb_add_proc_menu_path: + * @procedure_name: The procedure for which to install the menu path. + * @menu_path: The procedure's additional menu path. + * + * Register an additional menu path for a plug-in procedure. + * + * This procedure installs an additional menu entry for the given + * procedure. + * + * Returns: TRUE on success. + * + * Since: 3.0 + **/ +gboolean +_gimp_pdb_add_proc_menu_path (const gchar *procedure_name, + const gchar *menu_path) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean success = TRUE; + + args = gimp_value_array_new_from_types (NULL, + G_TYPE_STRING, procedure_name, + G_TYPE_STRING, menu_path, + G_TYPE_NONE); + + return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-pdb-add-proc-menu-path", + args); + gimp_value_array_unref (args); + + success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; + + gimp_value_array_unref (return_vals); + + return success; +} + /** * _gimp_pdb_get_proc_menu_paths: * @procedure_name: The procedure name. diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h index 85cba99c53..43b0faca79 100644 --- a/libgimp/gimppdb_pdb.h +++ b/libgimp/gimppdb_pdb.h @@ -50,6 +50,8 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar gint *num_values); G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_image_types (const gchar *procedure_name); G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_menu_label (const gchar *procedure_name); +G_GNUC_INTERNAL gboolean _gimp_pdb_add_proc_menu_path (const gchar *procedure_name, + const gchar *menu_path); G_GNUC_INTERNAL gchar** _gimp_pdb_get_proc_menu_paths (const gchar *procedure_name, gint *num_menu_paths); G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_documentation (const gchar *procedure_name, diff --git a/libgimp/gimpplugin_pdb.c b/libgimp/gimpplugin_pdb.c index fb2a99da76..4732bf608f 100644 --- a/libgimp/gimpplugin_pdb.c +++ b/libgimp/gimpplugin_pdb.c @@ -149,45 +149,6 @@ _gimp_plugin_menu_branch_register (const gchar *menu_path, return success; } -/** - * _gimp_plugin_menu_register: - * @procedure_name: The procedure for which to install the menu path. - * @menu_path: The procedure's additional menu path. - * - * Register an additional menu path for a plug-in procedure. - * - * This procedure installs an additional menu entry for the given - * procedure. - * - * Returns: TRUE on success. - * - * Since: 2.2 - **/ -gboolean -_gimp_plugin_menu_register (const gchar *procedure_name, - const gchar *menu_path) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gboolean success = TRUE; - - args = gimp_value_array_new_from_types (NULL, - G_TYPE_STRING, procedure_name, - G_TYPE_STRING, menu_path, - G_TYPE_NONE); - - return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-plugin-menu-register", - args); - gimp_value_array_unref (args); - - success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; - - gimp_value_array_unref (return_vals); - - return success; -} - /** * _gimp_plugin_icon_register: * @procedure_name: The procedure for which to install the icon. diff --git a/libgimp/gimpplugin_pdb.h b/libgimp/gimpplugin_pdb.h index 1d515a9f02..2fe7a15295 100644 --- a/libgimp/gimpplugin_pdb.h +++ b/libgimp/gimpplugin_pdb.h @@ -38,8 +38,6 @@ G_GNUC_INTERNAL gboolean _gimp_plugin_help_register (const gc const gchar *domain_uri); G_GNUC_INTERNAL gboolean _gimp_plugin_menu_branch_register (const gchar *menu_path, const gchar *menu_name); -G_GNUC_INTERNAL gboolean _gimp_plugin_menu_register (const gchar *procedure_name, - const gchar *menu_path); G_GNUC_INTERNAL gboolean _gimp_plugin_icon_register (const gchar *procedure_name, GimpIconType icon_type, gint icon_data_length, diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c index 24f60c1467..5852141470 100644 --- a/libgimp/gimpprocedure.c +++ b/libgimp/gimpprocedure.c @@ -31,6 +31,7 @@ #include "gimpgpparams.h" #include "gimppdb-private.h" #include "gimpplugin-private.h" +#include "gimppdb_pdb.h" #include "gimpplugin_pdb.h" #include "gimpprocedure-private.h" @@ -398,8 +399,8 @@ gimp_procedure_real_install (GimpProcedure *procedure) list; list = g_list_next (list)) { - _gimp_plugin_menu_register (gimp_procedure_get_name (procedure), - list->data); + _gimp_pdb_add_proc_menu_path (gimp_procedure_get_name (procedure), + list->data); } procedure->priv->installed = TRUE; @@ -679,8 +680,8 @@ gimp_procedure_add_menu_path (GimpProcedure *procedure, g_strdup (menu_path)); if (procedure->priv->installed) - _gimp_plugin_menu_register (gimp_procedure_get_name (procedure), - menu_path); + _gimp_pdb_add_proc_menu_path (gimp_procedure_get_name (procedure), + menu_path); } /** diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb index 6ee392e30f..0a30ac67a5 100644 --- a/pdb/groups/pdb.pdb +++ b/pdb/groups/pdb.pdb @@ -337,6 +337,42 @@ CODE ); } +sub pdb_add_proc_menu_path { + $blurb = "Register an additional menu path for a plug-in procedure."; + + $help = < 'procedure_name', type => 'string', non_empty => 1, + desc => 'The procedure for which to install the menu path' }, + { name => 'menu_path', type => 'string', + desc => "The procedure's additional menu path" } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; + + if (plug_in && + gimp_pdb_is_canonical_procedure (procedure_name, error)) + { + success = gimp_plug_in_add_proc_menu_path (plug_in, procedure_name, + menu_path); + } + else + success = FALSE; +} +CODE + ); +} + sub pdb_get_proc_menu_paths { $blurb = <<'BLURB'; Queries the procedural database for the procedure's menu paths. @@ -758,6 +794,8 @@ CODE @headers = qw("libgimpbase/gimpbase.h" "core/gimp.h" "core/gimpparamspecs-desc.h" + "plug-in/gimpplugin.h" + "plug-in/gimppluginmanager.h" "plug-in/gimppluginmanager-data.h" "plug-in/gimppluginprocedure.h" "gimppdb-query.h" @@ -773,6 +811,7 @@ CODE pdb_get_proc_info pdb_get_proc_image_types pdb_get_proc_menu_label + pdb_add_proc_menu_path pdb_get_proc_menu_paths pdb_get_proc_documentation pdb_get_proc_attribution diff --git a/pdb/groups/plug_in.pdb b/pdb/groups/plug_in.pdb index 3b2db6e1b4..d515ab8aec 100644 --- a/pdb/groups/plug_in.pdb +++ b/pdb/groups/plug_in.pdb @@ -146,41 +146,6 @@ CODE ); } -sub plugin_menu_register { - $blurb = "Register an additional menu path for a plug-in procedure."; - - $help = < 'procedure_name', type => 'string', non_empty => 1, - desc => 'The procedure for which to install the menu path' }, - { name => 'menu_path', type => 'string', - desc => "The procedure's additional menu path" } - ); - - %invoke = ( - code => <<'CODE' -{ - GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; - - if (plug_in && - gimp_pdb_is_canonical_procedure (procedure_name, error)) - { - success = gimp_plug_in_menu_register (plug_in, procedure_name, menu_path); - } - else - success = FALSE; -} -CODE - ); -} - sub plugin_menu_branch_register { $blurb = "Register a sub-menu."; @@ -357,12 +322,11 @@ CODE plugin_domain_register plugin_help_register plugin_menu_branch_register - plugin_menu_register plugin_icon_register plugin_set_pdb_error_handler plugin_get_pdb_error_handler); -%exports = (app => [@procs], lib => [@procs[1,2,3,4,5,6,7]]); +%exports = (app => [@procs], lib => [@procs[1,2,3,4,5,6]]); $desc = 'Plug-in';