mirror of https://github.com/GNOME/gimp.git
app, libgimp, pdb: factorize a bunch of similar code into gimp_pdb_get_resource().
Rather than reimplementing the same checks for every possible resource data type, just do it once and redirect to the correct factory container. For the libgimp API, we leave per-type functions `gimp_*_get_by_name()` (where * can be brush|gradient|font|palette|pattern so far), but internally they all use gimp_pdb_get_resource(). Note that eventually we want these functions to return a list of resources as it should be possible to have several resources of a given type with the same name (since they are made by third-party who might have had the same idea of a name).
This commit is contained in:
parent
ccde23ebaa
commit
d439e9ff5c
|
@ -96,7 +96,8 @@ brush_get_by_name_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
brush = gimp_pdb_get_brush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
brush = GIMP_BRUSH (gimp_pdb_get_resource (gimp, GIMP_TYPE_BRUSH, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! brush)
|
||||
success = FALSE;
|
||||
|
|
|
@ -40,8 +40,10 @@
|
|||
#include "core/gimpcontainer.h"
|
||||
#include "core/gimpdashpattern.h"
|
||||
#include "core/gimpdatafactory.h"
|
||||
#include "core/gimpdynamics.h"
|
||||
#include "core/gimpgradient.h"
|
||||
#include "core/gimplist.h"
|
||||
#include "core/gimpmybrush.h"
|
||||
#include "core/gimppalette.h"
|
||||
#include "core/gimpparamspecs.h"
|
||||
#include "core/gimppattern.h"
|
||||
|
@ -1371,7 +1373,7 @@ context_set_dynamics_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
GimpDynamics *dynamics = GIMP_DYNAMICS (gimp_pdb_get_resource (gimp, GIMP_TYPE_DYNAMICS, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (dynamics)
|
||||
gimp_context_set_dynamics (context, dynamics);
|
||||
|
@ -1485,7 +1487,8 @@ context_set_mypaint_brush_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
GimpMybrush *brush = GIMP_MYBRUSH (gimp_pdb_get_resource (gimp, GIMP_TYPE_MYBRUSH, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (brush)
|
||||
gimp_context_set_mybrush (context, brush);
|
||||
|
|
|
@ -56,7 +56,7 @@ font_get_by_name_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
font = gimp_pdb_get_font (gimp, name, error);
|
||||
font = GIMP_FONT (gimp_pdb_get_resource (gimp, GIMP_TYPE_FONT, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! font)
|
||||
success = FALSE;
|
||||
|
|
|
@ -27,16 +27,19 @@
|
|||
#include "pdb-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpbrush.h"
|
||||
#include "core/gimpbrushgenerated.h"
|
||||
#include "core/gimpchannel.h"
|
||||
#include "core/gimpcontainer.h"
|
||||
#include "core/gimpdatafactory.h"
|
||||
#include "core/gimpdrawable.h"
|
||||
#include "core/gimpdynamics.h"
|
||||
#include "core/gimpgradient.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-guides.h"
|
||||
#include "core/gimpimage-sample-points.h"
|
||||
#include "core/gimpitem.h"
|
||||
#include "core/gimpmybrush.h"
|
||||
#include "core/gimppalette.h"
|
||||
#include "core/gimppattern.h"
|
||||
|
||||
|
@ -51,27 +54,60 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static GimpObject *
|
||||
gimp_pdb_get_data_factory_item (GimpDataFactory *factory,
|
||||
const gchar *name)
|
||||
static GimpResource * gimp_pdb_get_data_factory_item (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name);
|
||||
const gchar * gimp_pdb_get_data_label (GType data_type);
|
||||
|
||||
|
||||
static GimpResource *
|
||||
gimp_pdb_get_data_factory_item (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpObject *object;
|
||||
GimpDataFactory *factory;
|
||||
GimpObject *resource;
|
||||
|
||||
object = gimp_container_get_child_by_name (gimp_data_factory_get_container (factory), name);
|
||||
factory = gimp_pdb_get_data_factory (gimp, data_type);
|
||||
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
||||
|
||||
if (! object)
|
||||
object = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (factory), name);
|
||||
resource = gimp_container_get_child_by_name (gimp_data_factory_get_container (factory), name);
|
||||
|
||||
if (! object && ! strcmp (name, "Standard"))
|
||||
{
|
||||
Gimp *gimp = gimp_data_factory_get_gimp (factory);
|
||||
if (! resource)
|
||||
resource = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (factory),
|
||||
name);
|
||||
|
||||
object = (GimpObject *)
|
||||
gimp_data_factory_data_get_standard (factory,
|
||||
gimp_get_user_context (gimp));
|
||||
}
|
||||
if (! resource && ! strcmp (name, "Standard"))
|
||||
resource = (GimpObject *) gimp_data_factory_data_get_standard (factory,
|
||||
gimp_get_user_context (gimp));
|
||||
|
||||
return object;
|
||||
return (GimpResource *) resource;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gimp_pdb_get_data_label (GType data_type)
|
||||
{
|
||||
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
|
||||
|
||||
if (g_type_is_a (data_type, GIMP_TYPE_BRUSH_GENERATED))
|
||||
return C_("PDB-error-data-label", "Generated brush");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_BRUSH))
|
||||
return C_("PDB-error-data-label", "Brush");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PATTERN))
|
||||
return C_("PDB-error-data-label", "Pattern");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_GRADIENT))
|
||||
return C_("PDB-error-data-label", "Gradient");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PALETTE))
|
||||
return C_("PDB-error-data-label", "Palette");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_FONT))
|
||||
return C_("PDB-error-data-label", "Font");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_DYNAMICS))
|
||||
return C_("PDB-error-data-label", "Paint dynamics");
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_MYBRUSH))
|
||||
return C_("PDB-error-data-label", "MyPaint brush");
|
||||
|
||||
/* If we reach this, it means we forgot a data type in our list! */
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
GimpDataFactory *
|
||||
|
@ -81,71 +117,88 @@ gimp_pdb_get_data_factory (Gimp *gimp,
|
|||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
|
||||
|
||||
if (g_type_is_a (data_type, GIMP_TYPE_BRUSH))
|
||||
{
|
||||
return gimp->brush_factory;
|
||||
}
|
||||
if (g_type_is_a (data_type, GIMP_TYPE_BRUSH_GENERATED))
|
||||
return gimp->brush_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_BRUSH))
|
||||
return gimp->brush_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PATTERN))
|
||||
{
|
||||
return gimp->pattern_factory;
|
||||
}
|
||||
return gimp->pattern_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_GRADIENT))
|
||||
{
|
||||
return gimp->gradient_factory;
|
||||
}
|
||||
return gimp->gradient_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PALETTE))
|
||||
{
|
||||
return gimp->palette_factory;
|
||||
}
|
||||
return gimp->palette_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_FONT))
|
||||
{
|
||||
return gimp->font_factory;
|
||||
}
|
||||
return gimp->font_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_DYNAMICS))
|
||||
return gimp->dynamics_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_MYBRUSH))
|
||||
return gimp->mybrush_factory;
|
||||
|
||||
/* If we reach this, it means we forgot a data factory in our list! */
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
GimpBrush *
|
||||
gimp_pdb_get_brush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
GimpResource *
|
||||
gimp_pdb_get_resource (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpBrush *brush;
|
||||
GimpResource *resource;
|
||||
const gchar *label;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
label = gimp_pdb_get_data_label (data_type);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty brush name"));
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
/* TRANSLATOR: %s is a data label from the
|
||||
* PDB-error-data-label context.
|
||||
*/
|
||||
C_("PDB-error-message", "%s name cannot be empty"),
|
||||
g_type_name (data_type));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
brush = (GimpBrush *) gimp_pdb_get_data_factory_item (gimp->brush_factory, name);
|
||||
resource = gimp_pdb_get_data_factory_item (gimp, data_type, name);
|
||||
|
||||
if (! brush)
|
||||
if (! resource)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Brush '%s' not found"), name);
|
||||
/* TRANSLATOR: the first %s is a data label from the
|
||||
* PDB-error-data-label context. The second %s is a data
|
||||
* name.
|
||||
*/
|
||||
C_("PDB-error-message", "%s '%s' not found"), label, name);
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_WRITE) &&
|
||||
! gimp_data_is_writable (GIMP_DATA (brush)))
|
||||
! gimp_data_is_writable (GIMP_DATA (resource)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Brush '%s' is not editable"), name);
|
||||
/* TRANSLATOR: the first %s is a data label from the
|
||||
* PDB-error-data-label context. The second %s is a data
|
||||
* name.
|
||||
*/
|
||||
C_("PDB-error-message", "%s '%s' is not editable"), label, name);
|
||||
return NULL;
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_RENAME) &&
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (brush)))
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (resource)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Brush '%s' is not renamable"), name);
|
||||
/* TRANSLATOR: the first %s is a data label from the
|
||||
* PDB-error-data-label context. The second %s is a data
|
||||
* name.
|
||||
*/
|
||||
C_("PDB-error-message", "%s '%s' is not renamable"), label, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return brush;
|
||||
return resource;
|
||||
}
|
||||
|
||||
GimpBrush *
|
||||
|
@ -159,12 +212,9 @@ gimp_pdb_get_generated_brush (Gimp *gimp,
|
|||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
brush = gimp_pdb_get_brush (gimp, name, access, error);
|
||||
brush = GIMP_BRUSH (gimp_pdb_get_resource (gimp, GIMP_TYPE_BRUSH_GENERATED, name, access, error));
|
||||
|
||||
if (! brush)
|
||||
return NULL;
|
||||
|
||||
if (! GIMP_IS_BRUSH_GENERATED (brush))
|
||||
if (brush != NULL && ! GIMP_IS_BRUSH_GENERATED (brush))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Brush '%s' is not a generated brush"), name);
|
||||
|
@ -174,234 +224,6 @@ gimp_pdb_get_generated_brush (Gimp *gimp,
|
|||
return brush;
|
||||
}
|
||||
|
||||
GimpDynamics *
|
||||
gimp_pdb_get_dynamics (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpDynamics *dynamics;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty paint dynamics name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dynamics = (GimpDynamics *) gimp_pdb_get_data_factory_item (gimp->dynamics_factory, name);
|
||||
|
||||
if (! dynamics)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Paint dynamics '%s' not found"), name);
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_WRITE) &&
|
||||
! gimp_data_is_writable (GIMP_DATA (dynamics)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Paint dynamics '%s' is not editable"), name);
|
||||
return NULL;
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_RENAME) &&
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (dynamics)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Paint dynamics '%s' is not renamable"), name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dynamics;
|
||||
}
|
||||
|
||||
GimpMybrush *
|
||||
gimp_pdb_get_mybrush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpMybrush *brush;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty MyPaint brush name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
brush = (GimpMybrush *) gimp_pdb_get_data_factory_item (gimp->mybrush_factory, name);
|
||||
|
||||
if (! brush)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("MyPaint brush '%s' not found"), name);
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_WRITE) &&
|
||||
! gimp_data_is_writable (GIMP_DATA (brush)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("MyPaint brush '%s' is not editable"), name);
|
||||
return NULL;
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_RENAME) &&
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (brush)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("MyPaint brush '%s' is not renamable"), name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return brush;
|
||||
}
|
||||
|
||||
GimpPattern *
|
||||
gimp_pdb_get_pattern (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error)
|
||||
{
|
||||
GimpPattern *pattern;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty pattern name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pattern = (GimpPattern *) gimp_pdb_get_data_factory_item (gimp->pattern_factory, name);
|
||||
|
||||
if (! pattern)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Pattern '%s' not found"), name);
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
GimpGradient *
|
||||
gimp_pdb_get_gradient (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpGradient *gradient;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty gradient name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gradient = (GimpGradient *) gimp_pdb_get_data_factory_item (gimp->gradient_factory, name);
|
||||
|
||||
if (! gradient)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Gradient '%s' not found"), name);
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_WRITE) &&
|
||||
! gimp_data_is_writable (GIMP_DATA (gradient)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Gradient '%s' is not editable"), name);
|
||||
return NULL;
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_RENAME) &&
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (gradient)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Gradient '%s' is not renamable"), name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gradient;
|
||||
}
|
||||
|
||||
GimpPalette *
|
||||
gimp_pdb_get_palette (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpPalette *palette;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty palette name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
palette = (GimpPalette *) gimp_pdb_get_data_factory_item (gimp->palette_factory, name);
|
||||
|
||||
if (! palette)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Palette '%s' not found"), name);
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_WRITE) &&
|
||||
! gimp_data_is_writable (GIMP_DATA (palette)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Palette '%s' is not editable"), name);
|
||||
return NULL;
|
||||
}
|
||||
else if ((access & GIMP_PDB_DATA_ACCESS_RENAME) &&
|
||||
! gimp_viewable_is_name_editable (GIMP_VIEWABLE (palette)))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Palette '%s' is not renamable"), name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
GimpFont *
|
||||
gimp_pdb_get_font (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error)
|
||||
{
|
||||
GimpFont *font;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
if (! name || ! strlen (name))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Invalid empty font name"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
font = (GimpFont *) gimp_pdb_get_data_factory_item (gimp->font_factory, name);
|
||||
|
||||
if (! font)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
_("Font '%s' not found"), name);
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
GimpBuffer *
|
||||
gimp_pdb_get_buffer (Gimp *gimp,
|
||||
const gchar *name,
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
GimpDataFactory * gimp_pdb_get_data_factory (Gimp *gimp,
|
||||
GType data_type);
|
||||
|
||||
GimpBrush * gimp_pdb_get_brush (Gimp *gimp,
|
||||
GimpResource * gimp_pdb_get_resource (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
|
@ -30,28 +31,7 @@ GimpBrush * gimp_pdb_get_generated_brush (Gimp *gimp,
|
|||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
GimpDynamics * gimp_pdb_get_dynamics (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
GimpMybrush * gimp_pdb_get_mybrush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
GimpPattern * gimp_pdb_get_pattern (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpGradient * gimp_pdb_get_gradient (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
GimpPalette * gimp_pdb_get_palette (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error);
|
||||
GimpFont * gimp_pdb_get_font (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
|
||||
GimpBuffer * gimp_pdb_get_buffer (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
|
|
|
@ -96,7 +96,8 @@ gradient_get_by_name_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
gradient = gimp_pdb_get_gradient (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
gradient = GIMP_GRADIENT (gimp_pdb_get_resource (gimp, GIMP_TYPE_GRADIENT, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! gradient)
|
||||
success = FALSE;
|
||||
|
|
|
@ -150,7 +150,8 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
|
|||
break;
|
||||
|
||||
case GIMP_CONVERT_PALETTE_CUSTOM:
|
||||
pal = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
pal = GIMP_PALETTE (gimp_pdb_get_resource (gimp, GIMP_TYPE_PALETTE, palette,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
if (! pal)
|
||||
{
|
||||
success = FALSE;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 771 procedures registered total */
|
||||
/* 772 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -93,7 +93,8 @@ palette_get_by_name_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
palette = gimp_pdb_get_palette (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
palette = GIMP_PALETTE (gimp_pdb_get_resource (gimp, GIMP_TYPE_PALETTE, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! palette)
|
||||
success = FALSE;
|
||||
|
|
|
@ -61,7 +61,7 @@ pattern_get_by_name_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
pattern = gimp_pdb_get_pattern (gimp, name, error);
|
||||
pattern = GIMP_PATTERN (gimp_pdb_get_resource (gimp, GIMP_TYPE_PATTERN, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! pattern)
|
||||
success = FALSE;
|
||||
|
|
|
@ -47,6 +47,41 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static GimpValueArray *
|
||||
resource_get_by_name_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GimpValueArray *return_vals;
|
||||
const gchar *type_name;
|
||||
const gchar *resource_name;
|
||||
GimpResource *resource = NULL;
|
||||
|
||||
type_name = g_value_get_string (gimp_value_array_index (args, 0));
|
||||
resource_name = g_value_get_string (gimp_value_array_index (args, 1));
|
||||
|
||||
if (success)
|
||||
{
|
||||
resource = gimp_pdb_get_resource (gimp, g_type_from_name (type_name), resource_name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
|
||||
if (! resource)
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
|
||||
if (success)
|
||||
g_value_set_object (gimp_value_array_index (return_vals, 1), resource);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
resource_id_is_valid_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -397,6 +432,43 @@ register_resource_procs (GimpPDB *pdb)
|
|||
{
|
||||
GimpProcedure *procedure;
|
||||
|
||||
/*
|
||||
* gimp-resource-get-by-name
|
||||
*/
|
||||
procedure = gimp_procedure_new (resource_get_by_name_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"gimp-resource-get-by-name");
|
||||
gimp_procedure_set_static_help (procedure,
|
||||
"Returns a resource with the given name.",
|
||||
"Returns a resource with the given name.",
|
||||
NULL);
|
||||
gimp_procedure_set_static_attribution (procedure,
|
||||
"Jehan",
|
||||
"Jehan",
|
||||
"2023");
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_string ("type-name",
|
||||
"type name",
|
||||
"The name of the resource type",
|
||||
FALSE, FALSE, TRUE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_string ("resource-name",
|
||||
"resource name",
|
||||
"The name of the resource",
|
||||
FALSE, FALSE, TRUE,
|
||||
NULL,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_return_value (procedure,
|
||||
gimp_param_spec_resource ("resource",
|
||||
"resource",
|
||||
"The resource",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-resource-id-is-valid
|
||||
*/
|
||||
|
|
|
@ -268,28 +268,7 @@ gimp_resource_get_by_name (GType resource_type,
|
|||
if (resource_name == NULL)
|
||||
return NULL;
|
||||
|
||||
if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
|
||||
{
|
||||
return (GimpResource *) gimp_brush_get_by_name (resource_name);
|
||||
}
|
||||
else if (g_type_is_a (resource_type, GIMP_TYPE_PATTERN))
|
||||
{
|
||||
return (GimpResource *) gimp_pattern_get_by_name (resource_name);
|
||||
}
|
||||
else if (g_type_is_a (resource_type, GIMP_TYPE_GRADIENT))
|
||||
{
|
||||
return (GimpResource *) gimp_gradient_get_by_name (resource_name);
|
||||
}
|
||||
else if (g_type_is_a (resource_type, GIMP_TYPE_PALETTE))
|
||||
{
|
||||
return (GimpResource *) gimp_palette_get_by_name (resource_name);
|
||||
}
|
||||
else if (g_type_is_a (resource_type, GIMP_TYPE_FONT))
|
||||
{
|
||||
return (GimpResource *) gimp_font_get_by_name (resource_name);
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
return _gimp_resource_get_by_name (g_type_name (resource_type), resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,45 @@
|
|||
**/
|
||||
|
||||
|
||||
/**
|
||||
* _gimp_resource_get_by_name:
|
||||
* @type_name: The name of the resource type.
|
||||
* @resource_name: The name of the resource.
|
||||
*
|
||||
* Returns a resource with the given name.
|
||||
*
|
||||
* Returns a resource with the given name.
|
||||
*
|
||||
* Returns: (transfer none): The resource.
|
||||
*
|
||||
* Since: 3.0
|
||||
**/
|
||||
GimpResource *
|
||||
_gimp_resource_get_by_name (const gchar *type_name,
|
||||
const gchar *resource_name)
|
||||
{
|
||||
GimpValueArray *args;
|
||||
GimpValueArray *return_vals;
|
||||
GimpResource *resource = NULL;
|
||||
|
||||
args = gimp_value_array_new_from_types (NULL,
|
||||
G_TYPE_STRING, type_name,
|
||||
G_TYPE_STRING, resource_name,
|
||||
G_TYPE_NONE);
|
||||
|
||||
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
|
||||
"gimp-resource-get-by-name",
|
||||
args);
|
||||
gimp_value_array_unref (args);
|
||||
|
||||
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
|
||||
resource = GIMP_VALUES_GET_RESOURCE (return_vals, 1);
|
||||
|
||||
gimp_value_array_unref (return_vals);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_resource_id_is_valid:
|
||||
* @resource_id: The resource ID to check.
|
||||
|
|
|
@ -32,18 +32,20 @@ G_BEGIN_DECLS
|
|||
/* For information look into the C source or the html documentation */
|
||||
|
||||
|
||||
gboolean gimp_resource_id_is_valid (gint resource_id);
|
||||
gboolean gimp_resource_id_is_brush (gint resource_id);
|
||||
gboolean gimp_resource_id_is_pattern (gint resource_id);
|
||||
gboolean gimp_resource_id_is_gradient (gint resource_id);
|
||||
gboolean gimp_resource_id_is_palette (gint resource_id);
|
||||
gboolean gimp_resource_id_is_font (gint resource_id);
|
||||
gchar* gimp_resource_get_name (GimpResource *resource);
|
||||
gboolean gimp_resource_is_editable (GimpResource *resource);
|
||||
GimpResource* gimp_resource_duplicate (GimpResource *resource);
|
||||
gboolean gimp_resource_rename (GimpResource *resource,
|
||||
const gchar *new_name);
|
||||
gboolean gimp_resource_delete (GimpResource *resource);
|
||||
G_GNUC_INTERNAL GimpResource* _gimp_resource_get_by_name (const gchar *type_name,
|
||||
const gchar *resource_name);
|
||||
gboolean gimp_resource_id_is_valid (gint resource_id);
|
||||
gboolean gimp_resource_id_is_brush (gint resource_id);
|
||||
gboolean gimp_resource_id_is_pattern (gint resource_id);
|
||||
gboolean gimp_resource_id_is_gradient (gint resource_id);
|
||||
gboolean gimp_resource_id_is_palette (gint resource_id);
|
||||
gboolean gimp_resource_id_is_font (gint resource_id);
|
||||
gchar* gimp_resource_get_name (GimpResource *resource);
|
||||
gboolean gimp_resource_is_editable (GimpResource *resource);
|
||||
GimpResource* gimp_resource_duplicate (GimpResource *resource);
|
||||
gboolean gimp_resource_rename (GimpResource *resource,
|
||||
const gchar *new_name);
|
||||
gboolean gimp_resource_delete (GimpResource *resource);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -71,7 +71,8 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
brush = gimp_pdb_get_brush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
brush = GIMP_BRUSH (gimp_pdb_get_resource (gimp, GIMP_TYPE_BRUSH, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! brush)
|
||||
success = FALSE;
|
||||
|
|
|
@ -1493,7 +1493,7 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GimpDynamics *dynamics = gimp_pdb_get_dynamics (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
GimpDynamics *dynamics = GIMP_DYNAMICS (gimp_pdb_get_resource (gimp, GIMP_TYPE_DYNAMICS, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (dynamics)
|
||||
gimp_context_set_dynamics (context, dynamics);
|
||||
|
@ -1614,7 +1614,8 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GimpMybrush *brush = gimp_pdb_get_mybrush (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
GimpMybrush *brush = GIMP_MYBRUSH (gimp_pdb_get_resource (gimp, GIMP_TYPE_MYBRUSH, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (brush)
|
||||
gimp_context_set_mybrush (context, brush);
|
||||
|
@ -3362,7 +3363,9 @@ CODE
|
|||
"core/gimpcontainer.h"
|
||||
"core/gimpdashpattern.h"
|
||||
"core/gimpdatafactory.h"
|
||||
"core/gimpdynamics.h"
|
||||
"core/gimplist.h"
|
||||
"core/gimpmybrush.h"
|
||||
"core/gimpstrokeoptions.h"
|
||||
"paint/gimppaintoptions.h"
|
||||
"libgimpconfig/gimpconfig.h"
|
||||
|
|
|
@ -38,7 +38,7 @@ sub font_get_by_name {
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
font = gimp_pdb_get_font (gimp, name, error);
|
||||
font = GIMP_FONT (gimp_pdb_get_resource (gimp, GIMP_TYPE_FONT, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! font)
|
||||
success = FALSE;
|
||||
|
|
|
@ -86,7 +86,8 @@ sub gradient_get_by_name {
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
gradient = gimp_pdb_get_gradient (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
gradient = GIMP_GRADIENT (gimp_pdb_get_resource (gimp, GIMP_TYPE_GRADIENT, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! gradient)
|
||||
success = FALSE;
|
||||
|
|
|
@ -141,7 +141,8 @@ HELP
|
|||
break;
|
||||
|
||||
case GIMP_CONVERT_PALETTE_CUSTOM:
|
||||
pal = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
pal = GIMP_PALETTE (gimp_pdb_get_resource (gimp, GIMP_TYPE_PALETTE, palette,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
if (! pal)
|
||||
{
|
||||
success = FALSE;
|
||||
|
|
|
@ -73,7 +73,8 @@ sub palette_get_by_name {
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
palette = gimp_pdb_get_palette (gimp, name, GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
palette = GIMP_PALETTE (gimp_pdb_get_resource (gimp, GIMP_TYPE_PALETTE, name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! palette)
|
||||
success = FALSE;
|
||||
|
|
|
@ -43,7 +43,7 @@ sub pattern_get_by_name {
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
pattern = gimp_pdb_get_pattern (gimp, name, error);
|
||||
pattern = GIMP_PATTERN (gimp_pdb_get_resource (gimp, GIMP_TYPE_PATTERN, name, GIMP_PDB_DATA_ACCESS_READ, error));
|
||||
|
||||
if (! pattern)
|
||||
success = FALSE;
|
||||
|
|
|
@ -16,6 +16,40 @@
|
|||
|
||||
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
|
||||
|
||||
sub resource_get_by_name {
|
||||
$blurb = "Returns a resource with the given name.";
|
||||
$help = "Returns a resource with the given name.";
|
||||
|
||||
&jehan_pdb_misc('2023', '3.0');
|
||||
|
||||
$lib_private = 1;
|
||||
|
||||
@inargs = (
|
||||
{ name => 'type_name', type => 'string', non_empty => 1,
|
||||
desc => 'The name of the resource type' },
|
||||
{ name => 'resource_name', type => 'string', non_empty => 1,
|
||||
desc => 'The name of the resource' }
|
||||
);
|
||||
|
||||
@outargs = (
|
||||
{ name => 'resource',
|
||||
type => 'resource',
|
||||
desc => "The resource" }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
resource = gimp_pdb_get_resource (gimp, g_type_from_name (type_name), resource_name,
|
||||
GIMP_PDB_DATA_ACCESS_READ, error);
|
||||
|
||||
if (! resource)
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub resource_id_is_valid {
|
||||
$blurb = 'Returns TRUE if the resource ID is valid.';
|
||||
|
||||
|
@ -362,7 +396,8 @@ CODE
|
|||
"gimppdberror.h"
|
||||
"gimp-intl.h");
|
||||
|
||||
@procs = qw(resource_id_is_valid
|
||||
@procs = qw(resource_get_by_name
|
||||
resource_id_is_valid
|
||||
resource_id_is_brush
|
||||
resource_id_is_pattern
|
||||
resource_id_is_gradient
|
||||
|
|
Loading…
Reference in New Issue