extensions: update the 5 goat-exercise extensions to multi-drawable API.

This commit is contained in:
Jehan 2021-04-06 01:55:52 +02:00
parent fa16152757
commit 931f44e54a
5 changed files with 62 additions and 7 deletions

View File

@ -64,7 +64,8 @@ static GimpProcedure * goat_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray * goat_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GimpDrawable *drawable,
gint n_drawables,
GimpDrawable **drawables,
const GimpValueArray *args,
gpointer run_data);
@ -107,6 +108,8 @@ goat_create_procedure (GimpPlugIn *plug_in,
goat_run, NULL, NULL);
gimp_procedure_set_image_types (procedure, "*");
gimp_procedure_set_sensitivity_mask (procedure,
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
gimp_procedure_set_menu_label (procedure, N_("Exercise in _C minor"));
gimp_procedure_set_icon_name (procedure, GIMP_ICON_GEGL);
@ -130,15 +133,34 @@ static GimpValueArray *
goat_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GimpDrawable *drawable,
gint n_drawables,
GimpDrawable **drawables,
const GimpValueArray *args,
gpointer run_data)
{
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint x, y, width, height;
GimpDrawable *drawable;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint x, y, width, height;
INIT_I18N();
if (n_drawables != 1)
{
GError *error = NULL;
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
_("Procedure '%s' only works with one drawable."),
PLUG_IN_PROC);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
error);
}
else
{
drawable = drawables[0];
}
/* In interactive mode, display a dialog to advertise the exercise. */
if (run_mode == GIMP_RUN_INTERACTIVE)
{

View File

@ -56,6 +56,7 @@ var Goat = GObject.registerClass({
let procedure = Gimp.ImageProcedure.new(this, name, Gimp.PDBProcType.PLUGIN, this.run);
procedure.set_image_types("*");
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE);
procedure.set_menu_label("Exercise a JavaScript goat");
procedure.set_icon_name(GimpUi.ICON_GEGL);
@ -69,9 +70,17 @@ var Goat = GObject.registerClass({
return procedure;
}
run(procedure, run_mode, image, drawable, args, run_data) {
run(procedure, run_mode, image, drawables, args, run_data) {
/* TODO: localization. */
if (drawables.length != 1) {
let msg = `Procedure '${procedure.get_name()}' only works with one drawable.`;
let error = GLib.Error.new_literal(Gimp.PlugIn.error_quark(), 0, msg);
return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, error)
}
let drawable = drawables[0];
if (run_mode == Gimp.RunMode.INTERACTIVE) {
GimpUi.init("goat-exercise-gjs");
/* TODO: help function and ID. */

View File

@ -33,10 +33,24 @@ local Gdk = lgi.Gdk
local Goat = lgi.package 'Goat'
local Goat = lgi.Goat
function run(procedure, run_mode, image, drawable, args, run_data)
function run(procedure, run_mode, image, drawables, args, run_data)
-- procedure:new_return_values() crashes LGI so we construct the
-- GimpValueArray manually.
local retval = Gimp.ValueArray(1)
if table.getn(drawables) ~= 1 then
local calling_err = GObject.Value(Gimp.PDBStatusType, Gimp.PDBStatusType.CALLING_ERROR)
local msg = "Procedure '%s' only works with one drawable."
msg = string.format(msg, procedure:get_name())
retval:append(calling_err)
retval:append(GObject.Value(GObject.Type.STRING, msg))
return retval
end
local drawable = drawables[1]
-- Not sure why run_mode has become a string instead of testing
-- against Gimp.RunMode.INTERACTIVE.
if run_mode == "INTERACTIVE" then
@ -145,6 +159,7 @@ function Goat.Exercise:do_create_procedure(name)
run, nil)
procedure:set_image_types("*");
procedure:set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE);
procedure:set_menu_label("Exercise a Lua goat");
procedure:set_icon_name(GimpUi.ICON_GEGL);

View File

@ -55,6 +55,7 @@ class Goat (Gimp.PlugIn):
self.run, None)
procedure.set_image_types("*")
procedure.set_sensitivity_mask (Gimp.ProcedureSensitivityMask.DRAWABLE)
procedure.set_menu_label(N_("Exercise a goat and a python"))
procedure.set_icon_name(GimpUi.ICON_GEGL)
@ -67,7 +68,14 @@ class Goat (Gimp.PlugIn):
return procedure
def run(self, procedure, run_mode, image, drawable, args, run_data):
def run(self, procedure, run_mode, image, n_drawables, drawables, args, run_data):
if n_drawables != 1:
msg = _("Procedure '{}' only works with one drawable.").format(procedure.get_name())
error = GLib.Error.new_literal(Gimp.PlugIn.error_quark(), msg, 0)
return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, error)
else:
drawable = drawables[0]
if run_mode == Gimp.RunMode.INTERACTIVE:
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

View File

@ -41,6 +41,7 @@ public class Goat : Gimp.PlugIn {
var procedure = new Gimp.ImageProcedure(this, name, Gimp.PDBProcType.PLUGIN, this.run);
procedure.set_image_types("RGB*, INDEXED*, GRAY*");
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE);
procedure.set_menu_label("Exercise a Vala goat");
procedure.set_documentation("Exercise a goat in the Vala language",
"Takes a goat for a walk in Vala",