2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-04-27 13:55:26 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2015-12-31 17:05:35 +01:00
|
|
|
* gimpprocedureaction.c
|
|
|
|
* Copyright (C) 2004-2016 Michael Natterer <mitch@gimp.org>
|
2004-04-27 13:55:26 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-04-27 13:55:26 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-04-27 13:55:26 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-04-27 13:55:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2016-01-01 19:37:10 +01:00
|
|
|
#include <gegl.h>
|
2004-04-27 13:55:26 +00:00
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2019-07-31 10:16:21 +02:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2016-01-01 19:37:10 +01:00
|
|
|
#include "pdb/gimpprocedure.h"
|
2004-05-18 21:19:43 +00:00
|
|
|
|
2019-07-02 03:54:38 +02:00
|
|
|
#include "gimpaction.h"
|
2019-07-04 01:11:48 +02:00
|
|
|
#include "gimpaction-history.h"
|
2015-12-31 17:05:35 +01:00
|
|
|
#include "gimpprocedureaction.h"
|
2018-06-05 16:07:23 +02:00
|
|
|
#include "gimpwidgets-utils.h"
|
2004-04-27 13:55:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2006-04-05 08:38:33 +00:00
|
|
|
PROP_PROCEDURE
|
2004-04-27 13:55:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-29 23:29:36 +01:00
|
|
|
static void gimp_procedure_action_g_action_iface_init (GActionInterface *iface);
|
2004-04-27 13:55:26 +00:00
|
|
|
|
2023-01-29 23:29:36 +01:00
|
|
|
static void gimp_procedure_action_finalize (GObject *object);
|
|
|
|
static void gimp_procedure_action_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_procedure_action_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-04-27 13:55:26 +00:00
|
|
|
|
2023-02-26 20:23:16 +01:00
|
|
|
static void gimp_procedure_action_activate (GAction *action,
|
2023-01-29 23:29:36 +01:00
|
|
|
GVariant *parameter);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProcedureAction, gimp_procedure_action, GIMP_TYPE_ACTION_IMPL,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, gimp_procedure_action_g_action_iface_init))
|
2004-04-27 13:55:26 +00:00
|
|
|
|
2015-12-31 17:05:35 +01:00
|
|
|
#define parent_class gimp_procedure_action_parent_class
|
2005-12-19 22:37:49 +00:00
|
|
|
|
2004-04-27 13:55:26 +00:00
|
|
|
|
|
|
|
static void
|
2015-12-31 17:05:35 +01:00
|
|
|
gimp_procedure_action_class_init (GimpProcedureActionClass *klass)
|
2004-04-27 13:55:26 +00:00
|
|
|
{
|
2023-02-26 20:23:16 +01:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-04-27 13:55:26 +00:00
|
|
|
|
2015-12-31 17:05:35 +01:00
|
|
|
object_class->finalize = gimp_procedure_action_finalize;
|
|
|
|
object_class->set_property = gimp_procedure_action_set_property;
|
|
|
|
object_class->get_property = gimp_procedure_action_get_property;
|
2004-04-27 13:55:26 +00:00
|
|
|
|
2006-04-05 08:38:33 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_PROCEDURE,
|
2006-04-27 12:48:12 +00:00
|
|
|
g_param_spec_object ("procedure",
|
|
|
|
NULL, NULL,
|
2015-12-31 17:05:35 +01:00
|
|
|
GIMP_TYPE_PROCEDURE,
|
2006-04-27 12:48:12 +00:00
|
|
|
GIMP_PARAM_READWRITE));
|
2004-04-27 13:55:26 +00:00
|
|
|
}
|
|
|
|
|
2023-01-29 23:29:36 +01:00
|
|
|
static void
|
|
|
|
gimp_procedure_action_g_action_iface_init (GActionInterface *iface)
|
|
|
|
{
|
2023-02-26 20:23:16 +01:00
|
|
|
iface->activate = gimp_procedure_action_activate;
|
2023-01-29 23:29:36 +01:00
|
|
|
}
|
|
|
|
|
2004-04-27 13:55:26 +00:00
|
|
|
static void
|
2015-12-31 17:05:35 +01:00
|
|
|
gimp_procedure_action_init (GimpProcedureAction *action)
|
2004-04-27 13:55:26 +00:00
|
|
|
{
|
2006-04-27 12:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-31 17:05:35 +01:00
|
|
|
gimp_procedure_action_finalize (GObject *object)
|
2006-04-27 12:48:12 +00:00
|
|
|
{
|
2015-12-31 17:05:35 +01:00
|
|
|
GimpProcedureAction *action = GIMP_PROCEDURE_ACTION (object);
|
2006-04-27 12:48:12 +00:00
|
|
|
|
2017-07-15 18:38:01 +02:00
|
|
|
g_clear_object (&action->procedure);
|
2006-04-27 12:48:12 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2004-04-27 13:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-31 17:05:35 +01:00
|
|
|
gimp_procedure_action_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2004-04-27 13:55:26 +00:00
|
|
|
{
|
2015-12-31 17:05:35 +01:00
|
|
|
GimpProcedureAction *action = GIMP_PROCEDURE_ACTION (object);
|
2004-04-27 13:55:26 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2006-04-05 08:38:33 +00:00
|
|
|
case PROP_PROCEDURE:
|
2006-04-27 12:48:12 +00:00
|
|
|
g_value_set_object (value, action->procedure);
|
2004-04-27 13:55:26 +00:00
|
|
|
break;
|
2006-04-27 12:48:12 +00:00
|
|
|
|
2004-04-27 13:55:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-31 17:05:35 +01:00
|
|
|
gimp_procedure_action_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2004-04-27 13:55:26 +00:00
|
|
|
{
|
2015-12-31 17:05:35 +01:00
|
|
|
GimpProcedureAction *action = GIMP_PROCEDURE_ACTION (object);
|
2004-04-27 13:55:26 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2006-04-05 08:38:33 +00:00
|
|
|
case PROP_PROCEDURE:
|
2006-04-27 12:48:12 +00:00
|
|
|
if (action->procedure)
|
|
|
|
g_object_unref (action->procedure);
|
2008-07-23 07:47:10 +00:00
|
|
|
action->procedure = g_value_dup_object (value);
|
2004-04-27 13:55:26 +00:00
|
|
|
break;
|
2006-04-27 12:48:12 +00:00
|
|
|
|
2004-04-27 13:55:26 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-18 21:19:43 +00:00
|
|
|
static void
|
2023-02-26 20:23:16 +01:00
|
|
|
gimp_procedure_action_activate (GAction *action,
|
|
|
|
GVariant *parameter)
|
2023-01-29 23:29:36 +01:00
|
|
|
{
|
|
|
|
GimpProcedureAction *procedure_action = GIMP_PROCEDURE_ACTION (action);
|
|
|
|
|
|
|
|
/* Not all actions have procedures associated with them, for example
|
|
|
|
* unused "filters-recent-[N]" actions, so check for NULL before we
|
|
|
|
* invoke the action
|
|
|
|
*/
|
|
|
|
if (procedure_action->procedure)
|
|
|
|
{
|
|
|
|
gsize hack = GPOINTER_TO_SIZE (procedure_action->procedure);
|
|
|
|
|
|
|
|
gimp_action_emit_activate (GIMP_ACTION (action),
|
|
|
|
g_variant_new_uint64 (hack));
|
|
|
|
|
|
|
|
gimp_action_history_action_activated (GIMP_ACTION (action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-18 21:19:43 +00:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2015-12-31 17:05:35 +01:00
|
|
|
GimpProcedureAction *
|
|
|
|
gimp_procedure_action_new (const gchar *name,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *tooltip,
|
|
|
|
const gchar *icon_name,
|
2019-07-02 03:54:38 +02:00
|
|
|
const gchar *help_id,
|
2023-02-03 01:15:33 +01:00
|
|
|
GimpProcedure *procedure,
|
|
|
|
GimpContext *context)
|
2004-04-27 13:55:26 +00:00
|
|
|
{
|
2019-07-02 03:54:38 +02:00
|
|
|
GimpProcedureAction *action;
|
|
|
|
|
|
|
|
action = g_object_new (GIMP_TYPE_PROCEDURE_ACTION,
|
|
|
|
"name", name,
|
|
|
|
"label", label,
|
|
|
|
"tooltip", tooltip,
|
|
|
|
"icon-name", icon_name,
|
|
|
|
"procedure", procedure,
|
2023-02-03 01:15:33 +01:00
|
|
|
"context", context,
|
2019-07-02 03:54:38 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_action_set_help_id (GIMP_ACTION (action), help_id);
|
|
|
|
|
|
|
|
return action;
|
2004-04-27 13:55:26 +00:00
|
|
|
}
|