mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
app: move functions to look up GimpData into core.
These functions should not be for the PDB only. The core will soon need these too (e.g. to load resources linked from a XCF file). So gimp_pdb_get_data_factory() is moved to gimp_get_data_factory() in Gimp class. And gimp_pdb_get_data_factory_item() is moved to gimp_data_factory_get_data() in GimpDataFactory class.
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include "gimp-units.h"
|
||||
#include "gimp-utils.h"
|
||||
#include "gimpbrush.h"
|
||||
#include "gimpbrushgenerated.h"
|
||||
#include "gimpbuffer.h"
|
||||
#include "gimpcontext.h"
|
||||
#include "gimpdynamics.h"
|
||||
@@ -75,6 +76,8 @@
|
||||
#include "gimptoolinfo.h"
|
||||
#include "gimptreeproxy.h"
|
||||
|
||||
#include "text/gimpfont.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
@@ -1269,6 +1272,34 @@ gimp_get_temp_file (Gimp *gimp,
|
||||
return file;
|
||||
}
|
||||
|
||||
GimpDataFactory *
|
||||
gimp_get_data_factory (Gimp *gimp,
|
||||
GType data_type)
|
||||
{
|
||||
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_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;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_GRADIENT))
|
||||
return gimp->gradient_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PALETTE))
|
||||
return gimp->palette_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_FONT))
|
||||
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);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_exit_idle_cleanup_stray_images (Gimp *gimp)
|
||||
{
|
||||
|
@@ -251,3 +251,7 @@ void gimp_image_opened (Gimp *gimp,
|
||||
|
||||
GFile * gimp_get_temp_file (Gimp *gimp,
|
||||
const gchar *extension);
|
||||
|
||||
GimpDataFactory *
|
||||
gimp_get_data_factory (Gimp *gimp,
|
||||
GType data_type);
|
||||
|
@@ -77,6 +77,14 @@ struct _GimpDataFactoryPrivate
|
||||
GimpAsyncSet *async_set;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar *name;
|
||||
const gchar *collection;
|
||||
gboolean is_internal;
|
||||
} SearchData;
|
||||
|
||||
|
||||
#define GET_PRIVATE(obj) (((GimpDataFactory *) (obj))->priv)
|
||||
|
||||
|
||||
@@ -109,6 +117,9 @@ static void gimp_data_factory_path_notify (GObject *ob
|
||||
static GFile * gimp_data_factory_get_save_dir (GimpDataFactory *factory,
|
||||
GError **error);
|
||||
|
||||
static gboolean gimp_data_factory_search_in_container (GimpData *data,
|
||||
SearchData *search_data);
|
||||
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GimpDataFactory, gimp_data_factory,
|
||||
GIMP_TYPE_OBJECT)
|
||||
@@ -650,6 +661,47 @@ gimp_data_factory_data_cancel (GimpDataFactory *factory)
|
||||
GIMP_DATA_FACTORY_GET_CLASS (factory)->data_cancel (factory);
|
||||
}
|
||||
|
||||
GimpData *
|
||||
gimp_data_factory_get_data (GimpDataFactory *factory,
|
||||
const gchar *name,
|
||||
const gchar *collection,
|
||||
gboolean is_internal)
|
||||
{
|
||||
GimpContainer *container;
|
||||
GimpObject *data;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
||||
|
||||
container = gimp_data_factory_get_container (factory);
|
||||
|
||||
if (collection == NULL)
|
||||
{
|
||||
data = gimp_container_get_child_by_name (container, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
SearchData *search_data = g_new (SearchData, 1);
|
||||
|
||||
search_data->name = name;
|
||||
search_data->collection = collection;
|
||||
search_data->is_internal = is_internal;
|
||||
data = gimp_container_search (container,
|
||||
(GimpContainerSearchFunc) gimp_data_factory_search_in_container,
|
||||
search_data);
|
||||
g_free (search_data);
|
||||
}
|
||||
|
||||
if (! data)
|
||||
data = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (factory),
|
||||
name);
|
||||
|
||||
if (! data && ! strcmp (name, "Standard"))
|
||||
data = (GimpObject *) gimp_data_factory_data_get_standard (factory,
|
||||
gimp_get_user_context (factory->priv->gimp));
|
||||
|
||||
return (GimpData *) data;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_data_factory_has_data_new_func (GimpDataFactory *factory)
|
||||
{
|
||||
@@ -1038,3 +1090,10 @@ gimp_data_factory_get_save_dir (GimpDataFactory *factory,
|
||||
|
||||
return writable_dir;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_data_factory_search_in_container (GimpData *data,
|
||||
SearchData *search_data)
|
||||
{
|
||||
return gimp_data_identify (data, search_data->name, search_data->collection, search_data->is_internal);
|
||||
}
|
||||
|
@@ -87,6 +87,11 @@ GimpAsyncSet * gimp_data_factory_get_async_set (GimpDataFactory *factory);
|
||||
gboolean gimp_data_factory_data_wait (GimpDataFactory *factory);
|
||||
void gimp_data_factory_data_cancel (GimpDataFactory *factory);
|
||||
|
||||
GimpData * gimp_data_factory_get_data (GimpDataFactory *factory,
|
||||
const gchar *name,
|
||||
const gchar *collection,
|
||||
gboolean is_internal);
|
||||
|
||||
gboolean gimp_data_factory_has_data_new_func (GimpDataFactory *factory);
|
||||
GimpData * gimp_data_factory_data_new (GimpDataFactory *factory,
|
||||
GimpContext *context,
|
||||
|
@@ -54,52 +54,9 @@
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar *name;
|
||||
const gchar *collection;
|
||||
gboolean is_internal;
|
||||
} SearchData;
|
||||
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,
|
||||
const gchar *collection,
|
||||
gboolean is_internal);
|
||||
const gchar * gimp_pdb_get_data_label (GType data_type);
|
||||
|
||||
static gboolean gimp_pdb_search_in_data_container (GimpData *data,
|
||||
SearchData *search_data);;
|
||||
|
||||
|
||||
GimpDataFactory *
|
||||
gimp_pdb_get_data_factory (Gimp *gimp,
|
||||
GType data_type)
|
||||
{
|
||||
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_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;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_GRADIENT))
|
||||
return gimp->gradient_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_PALETTE))
|
||||
return gimp->palette_factory;
|
||||
else if (g_type_is_a (data_type, GIMP_TYPE_FONT))
|
||||
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);
|
||||
}
|
||||
|
||||
GList *
|
||||
gimp_pdb_get_resources (Gimp *gimp,
|
||||
@@ -129,7 +86,7 @@ gimp_pdb_get_resources (Gimp *gimp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, data_type);
|
||||
factory = gimp_get_data_factory (gimp, data_type);
|
||||
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
||||
|
||||
container = gimp_data_factory_get_container (factory);
|
||||
@@ -193,8 +150,9 @@ gimp_pdb_get_resource (Gimp *gimp,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpResource *resource;
|
||||
const gchar *label;
|
||||
GimpDataFactory *factory;
|
||||
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);
|
||||
@@ -212,7 +170,8 @@ gimp_pdb_get_resource (Gimp *gimp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
resource = gimp_pdb_get_data_factory_item (gimp, data_type, name, NULL, TRUE);
|
||||
factory = gimp_get_data_factory (gimp, data_type);
|
||||
resource = GIMP_RESOURCE (gimp_data_factory_get_data (factory, name, NULL, TRUE));
|
||||
|
||||
if (! resource)
|
||||
{
|
||||
@@ -258,8 +217,9 @@ gimp_pdb_get_resource_by_id (Gimp *gimp,
|
||||
GimpPDBDataAccess access,
|
||||
GError **error)
|
||||
{
|
||||
GimpResource *resource;
|
||||
const gchar *label;
|
||||
GimpDataFactory *factory;
|
||||
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);
|
||||
@@ -277,7 +237,8 @@ gimp_pdb_get_resource_by_id (Gimp *gimp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
resource = gimp_pdb_get_data_factory_item (gimp, data_type, name, collection, is_internal);
|
||||
factory = gimp_get_data_factory (gimp, data_type);
|
||||
resource = GIMP_RESOURCE (gimp_data_factory_get_data (factory, name, collection, is_internal));
|
||||
|
||||
if (! resource)
|
||||
{
|
||||
@@ -836,50 +797,6 @@ gimp_pdb_is_canonical_procedure (const gchar *procedure_name,
|
||||
|
||||
/* Private functions. */
|
||||
|
||||
static GimpResource *
|
||||
gimp_pdb_get_data_factory_item (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name,
|
||||
const gchar *collection,
|
||||
gboolean is_internal)
|
||||
{
|
||||
GimpDataFactory *factory;
|
||||
GimpContainer *container;
|
||||
GimpObject *resource;
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, data_type);
|
||||
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
||||
|
||||
container = gimp_data_factory_get_container (factory);
|
||||
|
||||
if (collection == NULL)
|
||||
{
|
||||
resource = gimp_container_get_child_by_name (container, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
SearchData *data = g_new (SearchData, 1);
|
||||
|
||||
data->name = name;
|
||||
data->collection = collection;
|
||||
data->is_internal = is_internal;
|
||||
resource = gimp_container_search (container,
|
||||
(GimpContainerSearchFunc) gimp_pdb_search_in_data_container,
|
||||
data);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
if (! resource)
|
||||
resource = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (factory),
|
||||
name);
|
||||
|
||||
if (! resource && ! strcmp (name, "Standard"))
|
||||
resource = (GimpObject *) gimp_data_factory_data_get_standard (factory,
|
||||
gimp_get_user_context (gimp));
|
||||
|
||||
return (GimpResource *) resource;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gimp_pdb_get_data_label (GType data_type)
|
||||
{
|
||||
@@ -905,10 +822,3 @@ gimp_pdb_get_data_label (GType data_type)
|
||||
/* If we reach this, it means we forgot a data type in our list! */
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_pdb_search_in_data_container (GimpData *data,
|
||||
SearchData *search_data)
|
||||
{
|
||||
return gimp_data_identify (data, search_data->name, search_data->collection, search_data->is_internal);
|
||||
}
|
||||
|
@@ -18,9 +18,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
GimpDataFactory * gimp_pdb_get_data_factory (Gimp *gimp,
|
||||
GType data_type);
|
||||
|
||||
GList * gimp_pdb_get_resources (Gimp *gimp,
|
||||
GType data_type,
|
||||
const gchar *name,
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "pdb-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpbrush.h"
|
||||
#include "core/gimpdatafactory.h"
|
||||
#include "core/gimpgradient.h"
|
||||
@@ -422,7 +423,7 @@ resource_duplicate_invoker (GimpProcedure *procedure,
|
||||
{
|
||||
GimpDataFactory *factory;
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
|
||||
resource_copy = (GimpResource *)
|
||||
gimp_data_factory_data_duplicate (factory, GIMP_DATA (resource));
|
||||
@@ -491,7 +492,7 @@ resource_delete_invoker (GimpProcedure *procedure,
|
||||
{
|
||||
GimpDataFactory *factory;
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
|
||||
if (gimp_data_is_deletable (GIMP_DATA (resource)))
|
||||
success = gimp_data_factory_data_delete (factory, GIMP_DATA (resource),
|
||||
|
@@ -406,7 +406,7 @@ sub resource_duplicate {
|
||||
{
|
||||
GimpDataFactory *factory;
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
|
||||
resource_copy = (GimpResource *)
|
||||
gimp_data_factory_data_duplicate (factory, GIMP_DATA (resource));
|
||||
@@ -473,7 +473,7 @@ HELP
|
||||
{
|
||||
GimpDataFactory *factory;
|
||||
|
||||
factory = gimp_pdb_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
|
||||
|
||||
if (gimp_data_is_deletable (GIMP_DATA (resource)))
|
||||
success = gimp_data_factory_data_delete (factory, GIMP_DATA (resource),
|
||||
@@ -486,7 +486,8 @@ CODE
|
||||
}
|
||||
|
||||
|
||||
@headers = qw("core/gimpbrush.h"
|
||||
@headers = qw("core/gimp.h"
|
||||
"core/gimpbrush.h"
|
||||
"core/gimpdatafactory.h"
|
||||
"core/gimpgradient.h"
|
||||
"core/gimppalette.h"
|
||||
|
Reference in New Issue
Block a user