app: move some code in actions/ to new utility file procedure-commands.c

This commit is contained in:
Michael Natterer 2016-01-02 00:33:45 +01:00
parent 926dd1dffb
commit dda06ac065
6 changed files with 350 additions and 273 deletions

View File

@ -133,6 +133,8 @@ libappactions_a_SOURCES = \
plug-in-actions.h \
plug-in-commands.c \
plug-in-commands.h \
procedure-commands.c \
procedure-commands.h \
quick-mask-actions.c \
quick-mask-actions.h \
quick-mask-commands.c \

View File

@ -28,16 +28,17 @@
#include "core/gimp-filter-history.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpprogress.h"
#include "core/gimptoolinfo.h"
#include "pdb/gimpprocedure.h" /* FIXME history */
#include "pdb/gimpprocedure.h"
#include "tools/gimpoperationtool.h"
#include "tools/tool_manager.h"
#include "actions.h"
#include "filters-commands.h"
#include "plug-in-commands.h" /* FIXME history */
#include "procedure-commands.h"
#include "gimp-intl.h"
@ -117,19 +118,34 @@ filters_repeat_cmd_callback (GtkAction *action,
if (procedure)
{
GimpValueArray *args;
gint n_args;
args = gimp_procedure_get_arguments (procedure);
args = procedure_commands_get_display_args (procedure, display);
g_value_set_int (gimp_value_array_index (args, 0), run_mode);
if (args)
{
GError *error = NULL;
n_args = plug_in_collect_display_args (action, display,
procedure->args,
args, 1);
g_value_set_int (gimp_value_array_index (args, 0), run_mode);
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
gimp_procedure_execute_async (procedure, gimp,
gimp_get_user_context (gimp),
GIMP_PROGRESS (display), args,
GIMP_OBJECT (display), &error);
gimp_value_array_unref (args);
if (error)
{
gimp_message_literal (gimp,
G_OBJECT (display), GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
else
{
gimp_filter_history_add (gimp, procedure);
}
gimp_value_array_unref (args);
}
}
}
@ -141,19 +157,34 @@ filters_history_cmd_callback (GtkAction *action,
Gimp *gimp;
GimpDisplay *display;
GimpValueArray *args;
gint n_args;
return_if_no_gimp (gimp, data);
return_if_no_display (display, data);
args = gimp_procedure_get_arguments (procedure);
args = procedure_commands_get_display_args (procedure, display);
g_value_set_int (gimp_value_array_index (args, 0), GIMP_RUN_INTERACTIVE);
if (args)
{
GError *error = NULL;
n_args = plug_in_collect_display_args (action, display,
procedure->args,
args, 1);
g_value_set_int (gimp_value_array_index (args, 0), GIMP_RUN_INTERACTIVE);
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
gimp_procedure_execute_async (procedure, gimp,
gimp_get_user_context (gimp),
GIMP_PROGRESS (display), args,
GIMP_OBJECT (display), &error);
gimp_value_array_unref (args);
if (error)
{
gimp_message_literal (gimp,
G_OBJECT (display), GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
else
{
gimp_filter_history_add (gimp, procedure);
}
gimp_value_array_unref (args);
}
}

View File

@ -38,11 +38,11 @@
#include "core/gimpparamspecs.h"
#include "core/gimpprogress.h"
#include "pdb/gimpprocedure.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginmanager-data.h"
#include "pdb/gimpprocedure.h"
#include "widgets/gimpbufferview.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpdatafactoryview.h"
@ -57,46 +57,16 @@
#include "actions.h"
#include "plug-in-commands.h"
#include "procedure-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
#if 0
static void plug_in_procedure_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpDisplay *display,
GimpValueArray *args,
gint n_args);
#endif
static gint plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
#if 0
static gint plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
#endif
static void plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp);
static void plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp);
/* public functions */
@ -107,18 +77,10 @@ plug_in_run_cmd_callback (GtkAction *action,
gpointer data)
{
Gimp *gimp;
GimpValueArray *args;
gint n_args = 0;
GimpDisplay *display = NULL;
GimpValueArray *args = NULL;
GimpDisplay *display = NULL;
return_if_no_gimp (gimp, data);
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
switch (procedure->proc_type)
{
case GIMP_EXTENSION:
@ -141,9 +103,7 @@ plug_in_run_cmd_callback (GtkAction *action,
object = gimp_context_get_by_type (context,
gimp_container_get_children_type (container));
n_args = plug_in_collect_data_args (action, object,
procedure->args,
args, n_args);
args = procedure_commands_get_data_args (procedure, object);
}
else if (GIMP_IS_IMAGE_EDITOR (data))
{
@ -152,9 +112,7 @@ plug_in_run_cmd_callback (GtkAction *action,
image = gimp_image_editor_get_image (editor);
n_args = plug_in_collect_image_args (action, image,
procedure->args,
args, n_args);
args = procedure_commands_get_image_args (procedure, image);
}
else if (GIMP_IS_ITEM_TREE_VIEW (data))
{
@ -169,31 +127,52 @@ plug_in_run_cmd_callback (GtkAction *action,
else
item = NULL;
n_args = plug_in_collect_item_args (action, image, item,
procedure->args,
args, n_args);
args = procedure_commands_get_item_args (procedure, image, item);
}
else
{
display = action_data_get_display (data);
n_args = plug_in_collect_display_args (action,
display,
procedure->args,
args, n_args);
args = procedure_commands_get_display_args (procedure, display);
}
break;
case GIMP_INTERNAL:
g_warning ("Unhandled procedure type.");
n_args = -1;
break;
}
if (n_args >= 1)
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
if (args)
{
GError *error = NULL;
gimp_value_array_unref (args);
g_value_set_int (gimp_value_array_index (args, 0),
GIMP_RUN_INTERACTIVE);
gimp_procedure_execute_async (procedure, gimp,
gimp_get_user_context (gimp),
GIMP_PROGRESS (display), args,
GIMP_OBJECT (display), &error);
if (error)
{
gimp_message_literal (gimp,
G_OBJECT (display), GIMP_MESSAGE_ERROR,
error->message);
g_error_free (error);
}
else
{
/* remember only image plug-ins */
if (procedure->num_args >= 2 &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]))
{
gimp_filter_history_add (gimp, procedure);
}
}
gimp_value_array_unref (args);
}
}
void
@ -229,193 +208,6 @@ plug_in_reset_all_cmd_callback (GtkAction *action,
gtk_widget_show (dialog);
}
/* private functions */
/* FIXME history */
void
plug_in_procedure_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpDisplay *display,
GimpValueArray *args,
gint n_args)
{
GError *error = NULL;
gimp_value_array_truncate (args, n_args);
/* run the plug-in procedure */
gimp_procedure_execute_async (procedure, gimp,
gimp_get_user_context (gimp),
GIMP_PROGRESS (display), args,
GIMP_OBJECT (display), &error);
if (error)
{
gimp_message_literal (gimp,
G_OBJECT (display), GIMP_MESSAGE_ERROR,
error->message);
g_error_free (error);
}
else
{
/* remember only image plug-ins */
if (procedure->num_args >= 2 &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]))
{
gimp_filter_history_add (gimp, procedure);
}
}
}
static gint
plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_STRING (pspecs[n_args]))
{
if (object)
{
g_value_set_string (gimp_value_array_index (args, n_args),
gimp_object_get_name (object));
n_args++;
}
else
{
g_warning ("Uh-oh, no active data object for the plug-in!");
return -1;
}
}
return n_args;
}
static gint
plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
}
else
{
g_warning ("Uh-oh, no active image for the plug-in!");
return -1;
}
}
return n_args;
}
static gint
plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_ITEM_ID (pspecs[n_args]))
{
if (item &&
g_type_is_a (G_TYPE_FROM_INSTANCE (item),
GIMP_PARAM_SPEC_ITEM_ID (pspecs[n_args])->item_type))
{
gimp_value_set_item (gimp_value_array_index (args, n_args),
item);
n_args++;
}
else
{
g_warning ("Uh-oh, no active item for the plug-in!");
return -1;
}
}
}
}
return n_args;
}
/* FIXME history */
gint
plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DISPLAY_ID (pspecs[n_args]))
{
if (display)
{
gimp_value_set_display (gimp_value_array_index (args, n_args),
GIMP_OBJECT (display));
n_args++;
}
else
{
g_warning ("Uh-oh, no active display for the plug-in!");
return -1;
}
}
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
GimpImage *image = display ? gimp_display_get_image (display) : NULL;
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args),
image);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DRAWABLE_ID (pspecs[n_args]))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (drawable)
{
gimp_value_set_drawable (gimp_value_array_index (args, n_args),
drawable);
n_args++;
}
else
{
g_warning ("Uh-oh, no active drawable for the plug-in!");
return -1;
}
}
}
}
return n_args;
}
static void
plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,

View File

@ -28,11 +28,6 @@ void plug_in_reset_all_cmd_callback (GtkAction *action,
/* FIXME history */
void plug_in_procedure_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpDisplay *display,
GimpValueArray *args,
gint n_args);
gint plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,

View File

@ -0,0 +1,224 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "actions-types.h"
#include "core/gimpimage.h"
#include "core/gimpparamspecs.h"
#include "pdb/gimpprocedure.h"
#include "display/gimpdisplay.h"
#include "procedure-commands.h"
GimpValueArray *
procedure_commands_get_data_args (GimpProcedure *procedure,
GimpObject *object)
{
GimpValueArray *args;
gint n_args = 0;
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_STRING (procedure->args[n_args]))
{
if (object)
{
g_value_set_string (gimp_value_array_index (args, n_args),
gimp_object_get_name (object));
n_args++;
}
else
{
g_warning ("Uh-oh, no active data object for the plug-in!");
gimp_value_array_unref (args);
return NULL;
}
}
gimp_value_array_truncate (args, n_args);
return args;
}
GimpValueArray *
procedure_commands_get_image_args (GimpProcedure *procedure,
GimpImage *image)
{
GimpValueArray *args;
gint n_args = 0;
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
{
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
}
else
{
g_warning ("Uh-oh, no active image for the plug-in!");
gimp_value_array_unref (args);
return NULL;
}
}
gimp_value_array_truncate (args, n_args);
return args;
}
GimpValueArray *
procedure_commands_get_item_args (GimpProcedure *procedure,
GimpImage *image,
GimpItem *item)
{
GimpValueArray *args;
gint n_args = 0;
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
{
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_ITEM_ID (procedure->args[n_args]))
{
if (item &&
g_type_is_a (G_TYPE_FROM_INSTANCE (item),
GIMP_PARAM_SPEC_ITEM_ID (procedure->args[n_args])->item_type))
{
gimp_value_set_item (gimp_value_array_index (args, n_args),
item);
n_args++;
}
else
{
g_warning ("Uh-oh, no active item for the plug-in!");
gimp_value_array_unref (args);
return NULL;
}
}
}
}
gimp_value_array_truncate (args, n_args);
return args;
}
GimpValueArray *
procedure_commands_get_display_args (GimpProcedure *procedure,
GimpDisplay *display)
{
GimpValueArray *args;
gint n_args = 0;
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DISPLAY_ID (procedure->args[n_args]))
{
if (display)
{
gimp_value_set_display (gimp_value_array_index (args, n_args),
GIMP_OBJECT (display));
n_args++;
}
else
{
g_warning ("Uh-oh, no active display for the plug-in!");
gimp_value_array_unref (args);
return NULL;
}
}
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
{
GimpImage *image = display ? gimp_display_get_image (display) : NULL;
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args),
image);
n_args++;
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[n_args]))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (drawable)
{
gimp_value_set_drawable (gimp_value_array_index (args, n_args),
drawable);
n_args++;
}
else
{
g_warning ("Uh-oh, no active drawable for the plug-in!");
gimp_value_array_unref (args);
return NULL;
}
}
}
}
gimp_value_array_truncate (args, n_args);
return args;
}

View File

@ -0,0 +1,33 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROCEDURE_COMMANDS_H__
#define __PROCEDURE_COMMANDS_H__
GimpValueArray * procedure_commands_get_data_args (GimpProcedure *procedure,
GimpObject *object);
GimpValueArray * procedure_commands_get_image_args (GimpProcedure *procedure,
GimpImage *image);
GimpValueArray * procedure_commands_get_item_args (GimpProcedure *procedure,
GimpImage *image,
GimpItem *item);
GimpValueArray * procedure_commands_get_display_args (GimpProcedure *procedure,
GimpDisplay *display);
#endif /* __PROCEDURE_COMMANDS_H__ */