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

app: reduce code duplication in the filling/stroking code

Move most of the fill/stroke callback code to items-commands.[ch] and
call the new functions from the respective selection and vectors
files.
parent 31fcd79d
......@@ -20,18 +20,45 @@
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "actions-types.h"
#include "config/gimpdialogconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimpitem.h"
#include "core/gimpitemundo.h"
#include "dialogs/dialogs.h"
#include "dialogs/fill-dialog.h"
#include "dialogs/stroke-dialog.h"
#include "actions.h"
#include "items-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void items_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer user_data);
static void items_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
/* public functions */
void
......@@ -156,3 +183,241 @@ items_color_tag_cmd_callback (GtkAction *action,
gimp_image_flush (image);
}
}
void
items_fill_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
const gchar *dialog_key,
const gchar *dialog_title,
const gchar *dialog_icon_name,
const gchar *dialog_help_id,
gpointer data)
{
GimpDrawable *drawable;
GtkWidget *dialog;
GtkWidget *widget;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to fill."));
return;
}
dialog = dialogs_get_dialog (G_OBJECT (item), dialog_key);
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = fill_dialog_new (item,
drawable,
action_data_get_context (data),
dialog_title,
dialog_icon_name,
dialog_help_id,
widget,
config->fill_options,
items_fill_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (item), dialog_key, dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
void
items_fill_last_vals_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
gpointer data)
{
GimpDrawable *drawable;
GimpDialogConfig *config;
GtkWidget *widget;
GError *error = NULL;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to fill."));
return;
}
config = GIMP_DIALOG_CONFIG (image->gimp->config);
if (! gimp_item_fill (item, drawable,
config->fill_options, TRUE, NULL, &error))
{
gimp_message_literal (image->gimp, G_OBJECT (widget),
GIMP_MESSAGE_WARNING, error->message);
g_clear_error (&error);
}
else
{
gimp_image_flush (image);
}
}
void
items_stroke_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
const gchar *dialog_key,
const gchar *dialog_title,
const gchar *dialog_icon_name,
const gchar *dialog_help_id,
gpointer data)
{
GimpDrawable *drawable;
GtkWidget *dialog;
GtkWidget *widget;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
return;
}
dialog = dialogs_get_dialog (G_OBJECT (item), dialog_key);
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = stroke_dialog_new (item,
drawable,
action_data_get_context (data),
dialog_title,
dialog_icon_name,
dialog_help_id,
widget,
config->stroke_options,
items_stroke_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (item), dialog_key, dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
}
void
items_stroke_last_vals_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
gpointer data)
{
GimpDrawable *drawable;
GimpDialogConfig *config;
GtkWidget *widget;
GError *error = NULL;
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
return;
}
config = GIMP_DIALOG_CONFIG (image->gimp->config);
if (! gimp_item_stroke (item, drawable,
action_data_get_context (data),
config->stroke_options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (image->gimp, G_OBJECT (widget),
GIMP_MESSAGE_WARNING, error->message);
g_clear_error (&error);
}
else
{
gimp_image_flush (image);
}
}
/* private functions */
static void
items_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer user_data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->fill_options), 0);
if (! gimp_item_fill (item, drawable, options, TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
static void
items_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
......@@ -19,23 +19,50 @@
#define __ITEMS_COMMANDS_H__
void items_visible_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_linked_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_lock_content_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_lock_position_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_color_tag_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
GimpColorTag color_tag);
void items_visible_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_linked_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_lock_content_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_lock_position_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item);
void items_color_tag_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
GimpColorTag color_tag);
void items_fill_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
const gchar *dialog_key,
const gchar *dialog_title,
const gchar *dialog_icon_name,
const gchar *dialog_help_id,
gpointer data);
void items_fill_last_vals_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
gpointer data);
void items_stroke_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
const gchar *dialog_key,
const gchar *dialog_title,
const gchar *dialog_icon_name,
const gchar *dialog_help_id,
gpointer data);
void items_stroke_last_vals_cmd_callback (GtkAction *action,
GimpImage *image,
GimpItem *item,
gpointer data);
#endif /* __ITEMS_COMMANDS_H__ */
......@@ -21,7 +21,6 @@
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
......@@ -32,7 +31,6 @@
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimpselection.h"
#include "core/gimpstrokeoptions.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
......@@ -43,10 +41,9 @@
#include "display/gimpdisplayshell.h"
#include "dialogs/dialogs.h"
#include "dialogs/fill-dialog.h"
#include "dialogs/stroke-dialog.h"
#include "actions.h"
#include "items-commands.h"
#include "select-commands.h"
#include "gimp-intl.h"
......@@ -54,34 +51,22 @@
/* local function prototypes */
static void select_feather_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_border_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_grow_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_shrink_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer data);
static void select_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data);
static void select_feather_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_border_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_grow_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
static void select_shrink_callback (GtkWidget *widget,
gdouble size,
GimpUnit unit,
gpointer data);
/* public functions */
......@@ -397,171 +382,58 @@ void
select_fill_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GtkWidget *widget;
GtkWidget *dialog;
GimpImage *image;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to fill."));
return;
}
#define FILL_DIALOG_KEY "gimp-selection-fill-dialog"
dialog = dialogs_get_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY);
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = fill_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
drawable,
action_data_get_context (data),
_("Fill Selection Outline"),
GIMP_STOCK_TOOL_BUCKET_FILL,
GIMP_HELP_SELECTION_FILL,
widget,
config->fill_options,
select_fill_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY, dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
items_fill_cmd_callback (action,
image, GIMP_ITEM (gimp_image_get_mask (image)),
"gimp-selection-fill-dialog",
_("Fill Selection Outline"),
GIMP_STOCK_TOOL_BUCKET_FILL,
GIMP_HELP_SELECTION_FILL,
data);
}
void
select_fill_last_vals_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GtkWidget *widget;
GimpDialogConfig *config;
GError *error = NULL;
GimpImage *image;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to fill."));
return;
}
config = GIMP_DIALOG_CONFIG (image->gimp->config);
if (! gimp_item_fill (GIMP_ITEM (gimp_image_get_mask (image)),
drawable, config->fill_options, TRUE, NULL, &error))
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
error->message);
g_clear_error (&error);
}
else
{
gimp_image_flush (image);
}
items_fill_last_vals_cmd_callback (action,
image,
GIMP_ITEM (gimp_image_get_mask (image)),
data);
}
void
select_stroke_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GtkWidget *widget;
GtkWidget *dialog;
GimpImage *image;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
return;
}
#define STROKE_DIALOG_KEY "gimp-selection-stroke-dialog"
dialog = dialogs_get_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY);
if (! dialog)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
dialog = stroke_dialog_new (GIMP_ITEM (gimp_image_get_mask (image)),
drawable,
action_data_get_context (data),
_("Stroke Selection"),
GIMP_STOCK_SELECTION_STROKE,
GIMP_HELP_SELECTION_STROKE,
widget,
config->stroke_options,
select_stroke_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (drawable), STROKE_DIALOG_KEY, dialog);
}
gtk_window_present (GTK_WINDOW (dialog));
items_stroke_cmd_callback (action,
image, GIMP_ITEM (gimp_image_get_mask (image)),
"gimp-selection-stroke-dialog",
_("Stroke Selection"),
GIMP_STOCK_SELECTION_STROKE,
GIMP_HELP_SELECTION_STROKE,
data);
}
void
select_stroke_last_vals_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GimpContext *context;
GtkWidget *widget;
GimpDialogConfig *config;
GError *error = NULL;
GimpImage *image;
return_if_no_image (image, data);
return_if_no_context (context, data);
return_if_no_widget (widget, data);
drawable = gimp_image_get_active_drawable (image);
if (! drawable)
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
_("There is no active layer or channel to stroke to."));
return;
}
config = GIMP_DIALOG_CONFIG (image->gimp->config);
if (! gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
drawable, context, config->stroke_options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
error->message);
g_clear_error (&error);
}
else
{
gimp_image_flush (image);
}
items_stroke_last_vals_cmd_callback (action,
image,
GIMP_ITEM (gimp_image_get_mask (image)),
data);
}
......@@ -743,66 +615,3 @@ select_shrink_callback (GtkWidget *widget,
TRUE);
gimp_image_flush (image);
}
static void
select_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->fill_options), 0);
if (! gimp_item_fill (item, drawable, options, TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
static void
select_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer data)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (context->gimp->config);
GimpImage *image = gimp_item_get_image (item);
GError *error = NULL;
gimp_config_sync (G_OBJECT (options),
G_OBJECT (config->stroke_options), 0);
if (! gimp_item_stroke (item, drawable, context, options, NULL,
TRUE, NULL, &error))
{
gimp_message_literal (context->gimp,
G_OBJECT (dialog),
GIMP_MESSAGE_WARNING,
error ? error->message : "NULL");
g_clear_error (&error);
return;
}
gimp_image_flush (image);
gtk_widget_destroy (dialog);
}
......@@ -37,10 +37,8 @@
#include "core/gimpimage.h"
#include "core/gimpimage-merge.h"
#include "core/gimpimage-undo.h"
#include "core/gimpitemundo.h"
#include "core/gimpparamspecs.h"
#include "core/gimpprogress.h"
#include "core/gimpstrokeoptions.h"
#include "core/gimptoolinfo.h"
#include "pdb/gimppdb.h"
......@@ -60,8 +58,6 @@
#include "tools/tool_manager.h"
#include "dialogs/dialogs.h"
#include "dialogs/fill-dialog.h"
#include "dialogs/stroke-dialog.h"
#include "dialogs/vectors-export-dialog.h"
#include "dialogs/vectors-import-dialog.h"
#include "dialogs/vectors-options-dialog.h"
......@@ -75,53 +71,41 @@
/* local function prototypes */
static void vectors_new_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
GimpColorTag vectors_color_tag,
gboolean vectors_lock_content,
gboolean vectors_lock_position,
gpointer user_data);
static void vectors_edit_attributes_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
GimpColorTag vectors_color_tag,