mirror of https://github.com/GNOME/gimp.git
pdb: add gimp_pdb_set_proc_menu_label()
and all the needed code in libgimp/ and app/ to set a plug-in procedure's menu label using the new API. Remove the menu label from GPProcInstall.
This commit is contained in:
parent
33c84ceb08
commit
453b4f4aa2
|
@ -28,7 +28,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 750 procedures registered total */
|
||||
/* 751 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -338,6 +338,39 @@ pdb_get_proc_image_types_invoker (GimpProcedure *procedure,
|
|||
return return_vals;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
pdb_set_proc_menu_label_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
const gchar *procedure_name;
|
||||
const gchar *menu_label;
|
||||
|
||||
procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
|
||||
menu_label = 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_set_proc_menu_label (plug_in, procedure_name,
|
||||
menu_label);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
pdb_get_proc_menu_label_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -1074,6 +1107,36 @@ register_pdb_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-pdb-set-proc-menu-label
|
||||
*/
|
||||
procedure = gimp_procedure_new (pdb_set_proc_menu_label_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"gimp-pdb-set-proc-menu-label");
|
||||
gimp_procedure_set_static_strings (procedure,
|
||||
"Set the menu label for a plug-in procedure.",
|
||||
"This procedure sets the menu label 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-label",
|
||||
"menu label",
|
||||
"The procedure's menu label",
|
||||
FALSE, FALSE, TRUE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-pdb-get-proc-menu-label
|
||||
*/
|
||||
|
|
|
@ -756,7 +756,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
|
|||
#define VALIDATE_OR_NULL(str) ((str) == NULL || g_utf8_validate ((str), -1, NULL))
|
||||
|
||||
if (VALIDATE (proc_install->name) &&
|
||||
VALIDATE_OR_NULL (proc_install->menu_label) &&
|
||||
VALIDATE_OR_NULL (proc_install->blurb) &&
|
||||
VALIDATE_OR_NULL (proc_install->help) &&
|
||||
VALIDATE_OR_NULL (proc_install->help_id) &&
|
||||
|
@ -823,21 +822,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
|
|||
return;
|
||||
}
|
||||
|
||||
if (proc_install->menu_label && strlen (proc_install->menu_label) &&
|
||||
proc_install->menu_label[0] == '<')
|
||||
{
|
||||
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
|
||||
"Plug-in \"%s\"\n(%s)\n\n"
|
||||
"attempted to install procedure \"%s\" with a full "
|
||||
"menu path \"%s\" as menu label, this is not supported "
|
||||
"any longer.",
|
||||
gimp_object_get_name (plug_in),
|
||||
gimp_file_get_utf8_name (plug_in->file),
|
||||
proc_install->name,
|
||||
proc_install->menu_label);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create the procedure object */
|
||||
|
||||
switch (proc_install->type)
|
||||
|
@ -867,9 +851,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
|
|||
proc_install->date,
|
||||
NULL);
|
||||
|
||||
if (proc_install->menu_label && strlen (proc_install->menu_label))
|
||||
proc->menu_label = g_strdup (proc_install->menu_label);
|
||||
|
||||
gimp_plug_in_procedure_set_help_id (proc, proc_install->help_id);
|
||||
|
||||
for (i = 0; i < proc_install->nparams; i++)
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
|
||||
|
||||
gboolean
|
||||
gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *image_types)
|
||||
gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *image_types)
|
||||
{
|
||||
GimpPlugInProcedure *proc = NULL;
|
||||
|
||||
|
@ -89,6 +89,67 @@ gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *menu_label)
|
||||
{
|
||||
GimpPlugInProcedure *proc = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
|
||||
g_return_val_if_fail (proc_name != NULL, FALSE);
|
||||
g_return_val_if_fail (menu_label != NULL && strlen (menu_label), FALSE);
|
||||
|
||||
if (plug_in->plug_in_def)
|
||||
proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
|
||||
proc_name);
|
||||
|
||||
if (! proc)
|
||||
proc = gimp_plug_in_procedure_find (plug_in->temp_procedures, proc_name);
|
||||
|
||||
if (! proc)
|
||||
{
|
||||
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
|
||||
"Plug-in \"%s\"\n(%s)\n"
|
||||
"attempted to register the menu label \"%s\" "
|
||||
"for the procedure \"%s\".\n"
|
||||
"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_label, proc_name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (GIMP_PROCEDURE (proc)->proc_type)
|
||||
{
|
||||
case GIMP_PDB_PROC_TYPE_INTERNAL:
|
||||
return FALSE;
|
||||
|
||||
case GIMP_PDB_PROC_TYPE_PLUGIN:
|
||||
case GIMP_PDB_PROC_TYPE_EXTENSION:
|
||||
if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
|
||||
plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
|
||||
return FALSE;
|
||||
|
||||
case GIMP_PDB_PROC_TYPE_TEMPORARY:
|
||||
break;
|
||||
}
|
||||
|
||||
if (! gimp_plug_in_procedure_set_menu_label (proc, menu_label, &error))
|
||||
{
|
||||
gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *image_types);
|
||||
gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *menu_label);
|
||||
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
|
||||
const gchar *proc_name,
|
||||
const gchar *menu_path);
|
||||
|
|
|
@ -602,6 +602,41 @@ gimp_plug_in_procedure_get_help_domain (GimpPlugInProcedure *proc)
|
|||
return g_quark_to_string (proc->help_domain);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_plug_in_procedure_set_menu_label (GimpPlugInProcedure *proc,
|
||||
const gchar *menu_label,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
|
||||
g_return_val_if_fail (menu_label != NULL && strlen (menu_label), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (menu_label[0] == '<')
|
||||
{
|
||||
gchar *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\n"
|
||||
"attempted to install procedure \"%s\" with a full "
|
||||
"menu path \"%s\" as menu label, this is not supported "
|
||||
"any longer.",
|
||||
basename, gimp_file_get_utf8_name (proc->file),
|
||||
gimp_object_get_name (proc),
|
||||
menu_label);
|
||||
|
||||
g_free (basename);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_clear_pointer (&proc->label, g_free);
|
||||
|
||||
g_free (proc->menu_label);
|
||||
proc->menu_label = g_strdup (menu_label);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
|
||||
const gchar *menu_path,
|
||||
|
|
|
@ -107,6 +107,10 @@ const gchar * gimp_plug_in_procedure_get_help_domain (GimpPlugInProcedure *pro
|
|||
void gimp_plug_in_procedure_set_help_id (GimpPlugInProcedure *proc,
|
||||
const gchar *help_id);
|
||||
|
||||
gboolean gimp_plug_in_procedure_set_menu_label (GimpPlugInProcedure *proc,
|
||||
const gchar *menu_label,
|
||||
GError **error);
|
||||
|
||||
gboolean gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
|
||||
const gchar *menu_path,
|
||||
GError **error);
|
||||
|
|
|
@ -340,6 +340,44 @@ _gimp_pdb_get_proc_image_types (const gchar *procedure_name)
|
|||
return image_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* _gimp_pdb_set_proc_menu_label:
|
||||
* @procedure_name: The procedure for which to install the menu path.
|
||||
* @menu_label: The procedure's menu label.
|
||||
*
|
||||
* Set the menu label for a plug-in procedure.
|
||||
*
|
||||
* This procedure sets the menu label for the given procedure.
|
||||
*
|
||||
* Returns: TRUE on success.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
gboolean
|
||||
_gimp_pdb_set_proc_menu_label (const gchar *procedure_name,
|
||||
const gchar *menu_label)
|
||||
{
|
||||
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_label,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
"gimp-pdb-set-proc-menu-label",
|
||||
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_label:
|
||||
* @procedure_name: The procedure name.
|
||||
|
|
|
@ -51,6 +51,8 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar
|
|||
G_GNUC_INTERNAL gboolean _gimp_pdb_set_proc_image_types (const gchar *procedure_name,
|
||||
const gchar *image_types);
|
||||
G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_image_types (const gchar *procedure_name);
|
||||
G_GNUC_INTERNAL gboolean _gimp_pdb_set_proc_menu_label (const gchar *procedure_name,
|
||||
const gchar *menu_label);
|
||||
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);
|
||||
|
|
|
@ -371,7 +371,6 @@ gimp_procedure_real_install (GimpProcedure *procedure)
|
|||
proc_install.authors = (gchar *) gimp_procedure_get_authors (procedure);
|
||||
proc_install.copyright = (gchar *) gimp_procedure_get_copyright (procedure);
|
||||
proc_install.date = (gchar *) gimp_procedure_get_date (procedure);
|
||||
proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (procedure);
|
||||
proc_install.type = gimp_procedure_get_proc_type (procedure);
|
||||
proc_install.nparams = n_args;
|
||||
proc_install.nreturn_vals = n_return_vals;
|
||||
|
@ -404,6 +403,10 @@ gimp_procedure_real_install (GimpProcedure *procedure)
|
|||
_gimp_pdb_set_proc_image_types (gimp_procedure_get_name (procedure),
|
||||
procedure->priv->image_types);
|
||||
|
||||
if (procedure->priv->menu_label)
|
||||
_gimp_pdb_set_proc_menu_label (gimp_procedure_get_name (procedure),
|
||||
procedure->priv->menu_label);
|
||||
|
||||
for (list = gimp_procedure_get_menu_paths (procedure);
|
||||
list;
|
||||
list = g_list_next (list))
|
||||
|
@ -638,9 +641,14 @@ gimp_procedure_set_menu_label (GimpProcedure *procedure,
|
|||
const gchar *menu_label)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
|
||||
g_return_if_fail (menu_label != NULL && strlen (menu_label));
|
||||
|
||||
g_clear_pointer (&procedure->priv->menu_label, g_free);
|
||||
procedure->priv->menu_label = g_strdup (menu_label);
|
||||
|
||||
if (procedure->priv->installed)
|
||||
_gimp_pdb_set_proc_menu_label (gimp_procedure_get_name (procedure),
|
||||
procedure->priv->menu_label);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1221,9 +1221,6 @@ _gp_proc_install_read (GIOChannel *channel,
|
|||
if (! _gimp_wire_read_string (channel,
|
||||
&proc_install->date, 1, user_data))
|
||||
goto cleanup;
|
||||
if (! _gimp_wire_read_string (channel,
|
||||
&proc_install->menu_label, 1, user_data))
|
||||
goto cleanup;
|
||||
|
||||
if (! _gimp_wire_read_int32 (channel,
|
||||
&proc_install->type, 1, user_data))
|
||||
|
@ -1266,7 +1263,6 @@ _gp_proc_install_read (GIOChannel *channel,
|
|||
g_free (proc_install->authors);
|
||||
g_free (proc_install->copyright);
|
||||
g_free (proc_install->date);
|
||||
g_free (proc_install->menu_label);
|
||||
|
||||
if (proc_install->params)
|
||||
{
|
||||
|
@ -1465,9 +1461,6 @@ _gp_proc_install_write (GIOChannel *channel,
|
|||
if (! _gimp_wire_write_string (channel,
|
||||
&proc_install->date, 1, user_data))
|
||||
return;
|
||||
if (! _gimp_wire_write_string (channel,
|
||||
&proc_install->menu_label, 1, user_data))
|
||||
return;
|
||||
|
||||
if (! _gimp_wire_write_int32 (channel,
|
||||
&proc_install->type, 1, user_data))
|
||||
|
@ -1512,7 +1505,6 @@ _gp_proc_install_destroy (GimpWireMessage *msg)
|
|||
g_free (proc_install->authors);
|
||||
g_free (proc_install->copyright);
|
||||
g_free (proc_install->date);
|
||||
g_free (proc_install->menu_label);
|
||||
|
||||
for (i = 0; i < proc_install->nparams; i++)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ G_BEGIN_DECLS
|
|||
|
||||
/* Increment every time the protocol changes
|
||||
*/
|
||||
#define GIMP_PROTOCOL_VERSION 0x010A
|
||||
#define GIMP_PROTOCOL_VERSION 0x010B
|
||||
|
||||
|
||||
enum
|
||||
|
@ -288,7 +288,6 @@ struct _GPProcInstall
|
|||
gchar *authors;
|
||||
gchar *copyright;
|
||||
gchar *date;
|
||||
gchar *menu_label;
|
||||
guint32 type;
|
||||
guint32 nparams;
|
||||
guint32 nreturn_vals;
|
||||
|
|
|
@ -328,6 +328,42 @@ CODE
|
|||
);
|
||||
}
|
||||
|
||||
sub pdb_set_proc_menu_label {
|
||||
$blurb = "Set the menu label for a plug-in procedure.";
|
||||
|
||||
$help = <<HELP;
|
||||
This procedure sets the menu label 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_label', type => 'string', non_empty => 1,
|
||||
desc => "The procedure's menu label" }
|
||||
);
|
||||
|
||||
%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_set_proc_menu_label (plug_in, procedure_name,
|
||||
menu_label);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub pdb_get_proc_menu_label {
|
||||
$blurb = <<'BLURB';
|
||||
Queries the procedural database for the procedure's menu label.
|
||||
|
@ -889,6 +925,7 @@ CODE
|
|||
pdb_get_proc_info
|
||||
pdb_set_proc_image_types
|
||||
pdb_get_proc_image_types
|
||||
pdb_set_proc_menu_label
|
||||
pdb_get_proc_menu_label
|
||||
pdb_add_proc_menu_path
|
||||
pdb_get_proc_menu_paths
|
||||
|
|
|
@ -189,7 +189,7 @@ script_fu_script_install_proc (GimpPlugIn *plug_in,
|
|||
|
||||
gimp_procedure_set_image_types (procedure, script->image_types);
|
||||
|
||||
if (menu_label)
|
||||
if (menu_label && strlen (menu_label))
|
||||
gimp_procedure_set_menu_label (procedure, menu_label);
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
|
|
Loading…
Reference in New Issue