app, libgimp, pdb: clean up some more code redundancy.

This commit is contained in:
Jehan 2025-02-25 20:17:05 +01:00
parent 1e869b9ce0
commit 711be6db8c
8 changed files with 25 additions and 55 deletions

View file

@ -176,7 +176,6 @@ pdb_proc_exists_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
const gchar *procedure_name;
gboolean exists = FALSE;
gboolean is_internal = FALSE;
procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
@ -197,21 +196,18 @@ pdb_proc_exists_invoker (GimpProcedure *procedure,
}
exists = (proc != NULL);
if (exists)
is_internal = (proc->proc_type == GIMP_PDB_PROC_TYPE_INTERNAL);
}
else
success = FALSE;
{
success = FALSE;
}
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
{
g_value_set_boolean (gimp_value_array_index (return_vals, 1), exists);
g_value_set_boolean (gimp_value_array_index (return_vals, 2), is_internal);
}
g_value_set_boolean (gimp_value_array_index (return_vals, 1), exists);
return return_vals;
}
@ -1389,12 +1385,6 @@ register_pdb_procs (GimpPDB *pdb)
"Whether a procedure of that name is registered",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("is-internal",
"is internal",
"Whether the procedure is an internal procedure",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);

View file

@ -143,12 +143,10 @@ gboolean
gimp_pdb_procedure_exists (GimpPDB *pdb,
const gchar *procedure_name)
{
gboolean is_core;
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), FALSE);
return _gimp_pdb_proc_exists (procedure_name, &is_core);
return _gimp_pdb_proc_exists (procedure_name);
}
/**
@ -170,7 +168,6 @@ gimp_pdb_lookup_procedure (GimpPDB *pdb,
const gchar *procedure_name)
{
GimpProcedure *procedure;
gboolean is_internal = FALSE;
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
@ -178,9 +175,9 @@ gimp_pdb_lookup_procedure (GimpPDB *pdb,
procedure = g_hash_table_lookup (pdb->procedures, procedure_name);
if (! procedure && gimp_is_canonical_identifier (procedure_name) &&
_gimp_pdb_proc_exists (procedure_name, &is_internal))
_gimp_pdb_proc_exists (procedure_name))
{
procedure = _gimp_pdb_procedure_new (pdb, procedure_name, is_internal);
procedure = _gimp_pdb_procedure_new (pdb, procedure_name);
if (procedure)
g_hash_table_insert (pdb->procedures,

View file

@ -169,7 +169,6 @@ _gimp_pdb_query (const gchar *name,
/**
* _gimp_pdb_proc_exists:
* @procedure_name: The procedure name.
* @is_internal: (out): Whether the procedure is an internal procedure.
*
* Checks if the specified procedure exists in the procedural database
*
@ -181,8 +180,7 @@ _gimp_pdb_query (const gchar *name,
* Since: 2.6
**/
gboolean
_gimp_pdb_proc_exists (const gchar *procedure_name,
gboolean *is_internal)
_gimp_pdb_proc_exists (const gchar *procedure_name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
@ -198,10 +196,7 @@ _gimp_pdb_proc_exists (const gchar *procedure_name,
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
exists = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
*is_internal = GIMP_VALUES_GET_BOOLEAN (return_vals, 2);
}
exists = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
gimp_value_array_unref (return_vals);

View file

@ -42,8 +42,7 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_query (const gcha
const gchar *date,
const gchar *proc_type,
gchar ***procedure_names);
G_GNUC_INTERNAL gboolean _gimp_pdb_proc_exists (const gchar *procedure_name,
gboolean *is_internal);
G_GNUC_INTERNAL gboolean _gimp_pdb_proc_exists (const gchar *procedure_name);
G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar *procedure_name,
GimpPDBProcType *proc_type,
gint *num_args,

View file

@ -40,7 +40,6 @@ struct _GimpPDBProcedure
GimpProcedure parent_instance;
GimpPDB *pdb;
gboolean is_internal;
};
@ -98,7 +97,6 @@ _gimp_pdb_procedure_class_init (GimpPDBProcedureClass *klass)
static void
_gimp_pdb_procedure_init (GimpPDBProcedure *procedure)
{
procedure->is_internal = FALSE;
}
static void
@ -189,8 +187,7 @@ gimp_pdb_procedure_run (GimpProcedure *procedure,
GimpProcedure *
_gimp_pdb_procedure_new (GimpPDB *pdb,
const gchar *name,
gboolean is_internal)
const gchar *name)
{
GimpProcedure *procedure;
gchar *blurb;
@ -215,7 +212,6 @@ _gimp_pdb_procedure_new (GimpPDB *pdb,
"procedure-type", type,
"pdb", pdb,
NULL);
GIMP_PDB_PROCEDURE (procedure)->is_internal = is_internal;
_gimp_pdb_get_proc_documentation (name, &blurb, &help, &help_id);
gimp_procedure_set_documentation (procedure, blurb, help, help_id);
@ -271,11 +267,3 @@ _gimp_pdb_procedure_new (GimpPDB *pdb,
return procedure;
}
gboolean
_gimp_pdb_procedure_is_internal (GimpPDBProcedure *procedure)
{
g_return_val_if_fail (GIMP_IS_PDB_PROCEDURE (procedure), FALSE);
return procedure->is_internal;
}

View file

@ -31,11 +31,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GimpPDBProcedure, _gimp_pdb_procedure, GIMP, PDB_PROCEDURE, GimpProcedure)
G_GNUC_INTERNAL GimpProcedure * _gimp_pdb_procedure_new (GimpPDB *pdb,
const gchar *name,
gboolean is_internal);
G_GNUC_INTERNAL gboolean _gimp_pdb_procedure_is_internal (GimpPDBProcedure *procedure);
G_GNUC_INTERNAL GimpProcedure * _gimp_pdb_procedure_new (GimpPDB *pdb,
const gchar *name);
G_END_DECLS

View file

@ -2251,9 +2251,15 @@ gimp_procedure_is_internal (GimpProcedure *procedure)
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), FALSE);
if (GIMP_IS_PDB_PROCEDURE (procedure))
return _gimp_pdb_procedure_is_internal (GIMP_PDB_PROCEDURE (procedure));
{
GimpProcedurePrivate *priv = gimp_procedure_get_instance_private (procedure);
return (priv->proc_type == GIMP_PDB_PROC_TYPE_INTERNAL);
}
else
return FALSE;
{
return FALSE;
}
}
/**

View file

@ -157,9 +157,7 @@ HELP
@outargs = (
{ name => 'exists', type => 'boolean',
desc => 'Whether a procedure of that name is registered' },
{ name => 'is_internal', type => 'boolean',
desc => 'Whether the procedure is an internal procedure' }
desc => 'Whether a procedure of that name is registered' }
);
%invoke = (
@ -180,11 +178,11 @@ HELP
}
exists = (proc != NULL);
if (exists)
is_internal = (proc->proc_type == GIMP_PDB_PROC_TYPE_INTERNAL);
}
else
success = FALSE;
{
success = FALSE;
}
}
CODE
);