pdb: move gimp_plugin_menu_register() from the "plugin" to the "pdb" group

and call it gimp_pdb_add_proc_menu_path(). Move around and rename some
code in app/ to prepare for more procedure setters to work this way.
This commit is contained in:
Michael Natterer 2019-09-08 15:53:37 +02:00
parent 7a9517c261
commit d89adebff8
12 changed files with 206 additions and 181 deletions

View File

@ -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 <mitch@gimp.org>",
"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
*/

View File

@ -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 <mitch@gimp.org>",
"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
*/

View File

@ -874,9 +874,9 @@ 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,
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path)
{
@ -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);

View File

@ -105,7 +105,7 @@ void gimp_plug_in_main_loop_quit (GimpPlugIn *plug_in);
const gchar * gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in);
gboolean gimp_plug_in_menu_register (GimpPlugIn *plug_in,
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path);

View File

@ -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 != '/'))
{

View File

@ -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.

View File

@ -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,

View File

@ -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.

View File

@ -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,

View File

@ -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,7 +399,7 @@ gimp_procedure_real_install (GimpProcedure *procedure)
list;
list = g_list_next (list))
{
_gimp_plugin_menu_register (gimp_procedure_get_name (procedure),
_gimp_pdb_add_proc_menu_path (gimp_procedure_get_name (procedure),
list->data);
}
@ -679,7 +680,7 @@ gimp_procedure_add_menu_path (GimpProcedure *procedure,
g_strdup (menu_path));
if (procedure->priv->installed)
_gimp_plugin_menu_register (gimp_procedure_get_name (procedure),
_gimp_pdb_add_proc_menu_path (gimp_procedure_get_name (procedure),
menu_path);
}

View File

@ -337,6 +337,42 @@ CODE
);
}
sub pdb_add_proc_menu_path {
$blurb = "Register an additional menu path for a plug-in procedure.";
$help = <<HELP;
This procedure installs an additional menu entry for the given procedure.
HELP
&mitch_pdb_misc('2019', '3.0');
$lib_private = 1;
@inargs = (
{ name => '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

View File

@ -146,41 +146,6 @@ CODE
);
}
sub plugin_menu_register {
$blurb = "Register an additional menu path for a plug-in procedure.";
$help = <<HELP;
This procedure installs an additional menu entry for the given procedure.
HELP
&mitch_pdb_misc('2004', '2.2');
$lib_private = 1;
@inargs = (
{ name => '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';