Commit f3eef8fe authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins, app: port file-pat to GimpProcedureConfig

Exactly the same changes as in file-gbr.
parent 104ddb13
Pipeline #117600 passed with stages
in 12 minutes and 10 seconds
......@@ -21,6 +21,7 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "core/core-types.h"
......@@ -156,13 +157,14 @@ file_pat_pattern_to_image (Gimp *gimp,
GimpImage *image;
GimpLayer *layer;
const Babl *format;
const gchar *name;
GimpImageBaseType base_type;
gboolean alpha;
gint width;
gint height;
GimpTempBuf *mask = gimp_pattern_get_mask (pattern);
GeglBuffer *buffer;
GString *string;
GimpConfigWriter *writer;
GimpParasite *parasite;
format = gimp_temp_buf_get_format (mask);
......@@ -193,22 +195,34 @@ file_pat_pattern_to_image (Gimp *gimp,
g_return_val_if_reached (NULL);
}
name = gimp_object_get_name (pattern);
width = gimp_temp_buf_get_width (mask);
height = gimp_temp_buf_get_height (mask);
image = gimp_image_new (gimp, width, height, base_type,
GIMP_PRECISION_U8_NON_LINEAR);
parasite = gimp_parasite_new ("gimp-pattern-name",
string = g_string_new (NULL);
writer = gimp_config_writer_new_from_string (string);
gimp_config_writer_open (writer, "description");
gimp_config_writer_string (writer, gimp_object_get_name (pattern));
gimp_config_writer_close (writer);
gimp_config_writer_finish (writer, NULL, NULL);
g_object_unref (writer);
parasite = gimp_parasite_new ("GimpProcedureConfig-file-pat-save-last",
GIMP_PARASITE_PERSISTENT,
strlen (name) + 1, name);
string->len + 1, string->str);
gimp_image_parasite_attach (image, parasite, FALSE);
gimp_parasite_free (parasite);
g_string_free (string, TRUE);
format = gimp_image_get_layer_format (image, alpha);
layer = gimp_layer_new (image, width, height, format, name,
layer = gimp_layer_new (image, width, height, format,
gimp_object_get_name (pattern),
1.0, GIMP_LAYER_MODE_NORMAL);
gimp_image_add_layer (image, layer, NULL, 0, FALSE);
......
......@@ -29,7 +29,6 @@
#define SAVE_PROC "file-pat-save"
#define PLUG_IN_BINARY "file-pat"
#define PLUG_IN_ROLE "gimp-file-pat"
typedef struct _Pat Pat;
......@@ -63,15 +62,14 @@ static GimpValueArray * pat_save (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
static gboolean save_dialog (void);
static gboolean save_dialog (GimpProcedure *procedure,
GObject *config);
G_DEFINE_TYPE (Pat, pat, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (PAT_TYPE)
static gchar description[256] = "GIMP Pattern";
static void
pat_class_init (PatClass *klass)
......@@ -147,11 +145,12 @@ pat_save (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data)
{
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpParasite *parasite;
GimpImage *orig_image;
GError *error = NULL;
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpImage *orig_image;
gchar *description;
GError *error = NULL;
INIT_I18N ();
......@@ -172,62 +171,52 @@ pat_save (GimpProcedure *procedure,
if (export == GIMP_EXPORT_CANCEL)
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
NULL);
break;
/* Possibly retrieve data */
gimp_get_data (SAVE_PROC, description);
default:
break;
}
parasite = gimp_image_get_parasite (orig_image, "gimp-pattern-name");
if (parasite)
{
g_strlcpy (description,
gimp_parasite_data (parasite),
MIN (sizeof (description),
gimp_parasite_data_size (parasite)));
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
gimp_parasite_free (parasite);
}
else
{
gchar *name = g_path_get_basename (gimp_file_get_utf8_name (file));
g_object_get (config,
"description", &description,
NULL);
if (g_str_has_suffix (name, ".pat"))
name[strlen (name) - 4] = '\0';
if (! description || ! strlen (description))
{
gchar *name = g_path_get_basename (gimp_file_get_utf8_name (file));
if (strlen (name))
g_strlcpy (description, name, sizeof (description));
if (g_str_has_suffix (name, ".pat"))
name[strlen (name) - 4] = '\0';
g_free (name);
}
break;
if (strlen (name))
g_object_set (config,
"description", name,
NULL);
default:
break;
g_free (name);
}
switch (run_mode)
g_free (description);
if (run_mode == GIMP_RUN_INTERACTIVE)
{
case GIMP_RUN_INTERACTIVE:
if (! save_dialog ())
if (! save_dialog (procedure, G_OBJECT (config)))
{
status = GIMP_PDB_CANCEL;
goto out;
}
break;
case GIMP_RUN_NONINTERACTIVE:
g_strlcpy (description,
GIMP_VALUES_GET_STRING (args, 0),
sizeof (description));
break;
default:
break;
}
if (status == GIMP_PDB_SUCCESS)
{
GimpValueArray *save_retvals;
gchar *uri = g_file_get_uri (file);
g_object_get (config,
"description", &description,
NULL);
save_retvals =
gimp_pdb_run_procedure (gimp_get_pdb (),
......@@ -235,15 +224,13 @@ pat_save (GimpProcedure *procedure,
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
GIMP_TYPE_IMAGE, image,
GIMP_TYPE_DRAWABLE, drawable,
G_TYPE_STRING, uri,
G_TYPE_FILE, file,
G_TYPE_STRING, description,
G_TYPE_NONE);
g_free (uri);
if (GIMP_VALUES_GET_ENUM (save_retvals, 0) == GIMP_PDB_SUCCESS)
{
gimp_set_data (SAVE_PROC, description, sizeof (description));
gimp_procedure_config_end_run (config, orig_image, run_mode);
}
else
{
......@@ -258,23 +245,9 @@ pat_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
if (strlen (description))
{
GimpParasite *parasite;
parasite = gimp_parasite_new ("gimp-pattern-name",
GIMP_PARASITE_PERSISTENT,
strlen (description) + 1,
description);
gimp_image_attach_parasite (orig_image, parasite);
gimp_parasite_free (parasite);
}
else
{
gimp_image_detach_parasite (orig_image, "gimp-pattern-name");
}
out:
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image);
......@@ -282,39 +255,37 @@ pat_save (GimpProcedure *procedure,
}
static gboolean
save_dialog (void)
save_dialog (GimpProcedure *procedure,
GObject *config)
{
GtkWidget *dialog;
GtkWidget *grid;
GtkWidget *entry;
gboolean run;
dialog = gimp_export_dialog_new (_("Pattern"), PLUG_IN_BINARY, SAVE_PROC);
dialog = gimp_procedure_dialog_new (procedure,
GIMP_PROCEDURE_CONFIG (config),
_("Export Image as Pattern"));
/* The main grid */
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)),
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
grid, TRUE, TRUE, 0);
gtk_widget_show (grid);
entry = gtk_entry_new ();
entry = gimp_prop_entry_new (config, "description", 256);
gtk_entry_set_width_chars (GTK_ENTRY (entry), 20);
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
gtk_entry_set_text (GTK_ENTRY (entry), description);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
_("_Description:"), 1.0, 0.5,
entry, 1);
gtk_widget_show (entry);
gtk_widget_show (dialog);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
if (run)
g_strlcpy (description, gtk_entry_get_text (GTK_ENTRY (entry)),
sizeof (description));
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
gtk_widget_destroy (dialog);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment