2016-10-29 22:50:13 +08:00
|
|
|
/* 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-10-29 22:50:13 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2016-10-31 00:02:59 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
2016-10-29 22:50:13 +08:00
|
|
|
#include "actions-types.h"
|
|
|
|
|
2016-10-31 00:02:59 +08:00
|
|
|
#include "config/gimpdialogconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
2016-10-29 22:50:13 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-undo.h"
|
|
|
|
#include "core/gimpitem.h"
|
|
|
|
#include "core/gimpitemundo.h"
|
|
|
|
|
2016-10-31 00:02:59 +08:00
|
|
|
#include "dialogs/dialogs.h"
|
|
|
|
#include "dialogs/fill-dialog.h"
|
|
|
|
#include "dialogs/stroke-dialog.h"
|
|
|
|
|
|
|
|
#include "actions.h"
|
2016-10-29 22:50:13 +08:00
|
|
|
#include "items-commands.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2016-10-31 00:02:59 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void items_fill_callback (GtkWidget *dialog,
|
|
|
|
GimpItem *item,
|
2020-08-01 19:12:21 +08:00
|
|
|
GList *drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpContext *context,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
gpointer user_data);
|
|
|
|
static void items_stroke_callback (GtkWidget *dialog,
|
|
|
|
GimpItem *item,
|
2020-08-01 19:59:21 +08:00
|
|
|
GList *drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpContext *context,
|
|
|
|
GimpStrokeOptions *options,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
2016-10-29 22:50:13 +08:00
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_visible_cmd_callback (GimpAction *action,
|
2019-07-04 07:11:48 +08:00
|
|
|
GVariant *value,
|
2019-07-02 22:12:18 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item)
|
2016-10-29 22:50:13 +08:00
|
|
|
{
|
2019-07-04 07:11:48 +08:00
|
|
|
gboolean visible = g_variant_get_boolean (value);
|
2016-10-29 22:50:13 +08:00
|
|
|
|
|
|
|
if (visible != gimp_item_get_visible (item))
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
|
|
|
|
GIMP_UNDO_ITEM_VISIBILITY);
|
|
|
|
|
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
gimp_item_set_visible (item, visible, push_undo);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_linked_cmd_callback (GimpAction *action,
|
2019-07-04 07:11:48 +08:00
|
|
|
GVariant *value,
|
2019-07-02 22:12:18 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item)
|
2016-10-29 22:50:13 +08:00
|
|
|
{
|
2019-07-04 07:11:48 +08:00
|
|
|
gboolean linked = g_variant_get_boolean (value);
|
2016-10-29 22:50:13 +08:00
|
|
|
|
|
|
|
if (linked != gimp_item_get_linked (item))
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
|
|
|
|
GIMP_UNDO_ITEM_LINKED);
|
|
|
|
|
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
gimp_item_set_linked (item, linked, push_undo);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_lock_content_cmd_callback (GimpAction *action,
|
2019-07-04 07:11:48 +08:00
|
|
|
GVariant *value,
|
2019-07-02 22:12:18 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item)
|
2016-10-29 22:50:13 +08:00
|
|
|
{
|
2019-07-04 07:11:48 +08:00
|
|
|
gboolean locked = g_variant_get_boolean (value);
|
2016-10-29 22:50:13 +08:00
|
|
|
|
|
|
|
if (locked != gimp_item_get_lock_content (item))
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
|
|
|
|
GIMP_UNDO_ITEM_LINKED);
|
|
|
|
|
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
gimp_item_set_lock_content (item, locked, push_undo);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_lock_position_cmd_callback (GimpAction *action,
|
2019-07-04 07:11:48 +08:00
|
|
|
GVariant *value,
|
2019-07-02 22:12:18 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item)
|
2016-10-29 22:50:13 +08:00
|
|
|
{
|
2019-07-04 07:11:48 +08:00
|
|
|
gboolean locked = g_variant_get_boolean (value);
|
2016-10-29 22:50:13 +08:00
|
|
|
|
|
|
|
if (locked != gimp_item_get_lock_position (item))
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
|
|
|
|
GIMP_UNDO_ITEM_LOCK_POSITION);
|
|
|
|
|
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
gimp_item_set_lock_position (item, locked, push_undo);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_color_tag_cmd_callback (GimpAction *action,
|
2016-10-29 22:50:13 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
GimpColorTag color_tag)
|
|
|
|
{
|
|
|
|
if (color_tag != gimp_item_get_color_tag (item))
|
|
|
|
{
|
|
|
|
GimpUndo *undo;
|
|
|
|
gboolean push_undo = TRUE;
|
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
|
|
|
|
GIMP_UNDO_ITEM_COLOR_TAG);
|
|
|
|
|
|
|
|
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
gimp_item_set_color_tag (item, color_tag, push_undo);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
}
|
|
|
|
}
|
2016-10-31 00:02:59 +08:00
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_fill_cmd_callback (GimpAction *action,
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
const gchar *dialog_key,
|
|
|
|
const gchar *dialog_title,
|
|
|
|
const gchar *dialog_icon_name,
|
|
|
|
const gchar *dialog_help_id,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-08-01 19:12:21 +08:00
|
|
|
GList *drawables;
|
2016-10-31 00:02:59 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *widget;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
2016-10-31 00:02:59 +08:00
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
if (! drawables)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
|
2020-08-01 19:12:21 +08:00
|
|
|
_("There are no selected layers or channels to fill."));
|
2016-10-31 00:02:59 +08:00
|
|
|
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,
|
2020-08-01 19:12:21 +08:00
|
|
|
drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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));
|
2020-08-01 19:12:21 +08:00
|
|
|
g_list_free (drawables);
|
2016-10-31 00:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_fill_last_vals_cmd_callback (GimpAction *action,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
gpointer data)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
2020-08-01 19:12:21 +08:00
|
|
|
GList *drawables;
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpDialogConfig *config;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GError *error = NULL;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
2016-10-31 00:02:59 +08:00
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
if (! drawables)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
|
2020-08-01 19:12:21 +08:00
|
|
|
_("There are no selected layers or channels to fill."));
|
2016-10-31 00:02:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
if (! gimp_item_fill (item, drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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);
|
|
|
|
}
|
2020-08-01 19:12:21 +08:00
|
|
|
g_list_free (drawables);
|
2016-10-31 00:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_stroke_cmd_callback (GimpAction *action,
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
const gchar *dialog_key,
|
|
|
|
const gchar *dialog_title,
|
|
|
|
const gchar *dialog_icon_name,
|
|
|
|
const gchar *dialog_help_id,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-08-01 19:59:21 +08:00
|
|
|
GList *drawables;
|
2016-10-31 00:02:59 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *widget;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
2016-10-31 00:02:59 +08:00
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
if (! drawables)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
|
2020-08-01 19:59:21 +08:00
|
|
|
_("There are no selected layers or channels to stroke to."));
|
2016-10-31 00:02:59 +08:00
|
|
|
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,
|
2020-08-01 19:59:21 +08:00
|
|
|
drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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));
|
2020-08-01 19:59:21 +08:00
|
|
|
g_list_free (drawables);
|
2016-10-31 00:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-02 22:12:18 +08:00
|
|
|
items_stroke_last_vals_cmd_callback (GimpAction *action,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpItem *item,
|
|
|
|
gpointer data)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
2020-08-01 19:59:21 +08:00
|
|
|
GList *drawables;
|
2016-10-31 00:02:59 +08:00
|
|
|
GimpDialogConfig *config;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GError *error = NULL;
|
|
|
|
return_if_no_widget (widget, data);
|
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
2016-10-31 00:02:59 +08:00
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
if (! drawables)
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
|
|
|
gimp_message_literal (image->gimp,
|
|
|
|
G_OBJECT (widget), GIMP_MESSAGE_WARNING,
|
2020-08-01 19:59:21 +08:00
|
|
|
_("There are no selected layers or channels to stroke to."));
|
2016-10-31 00:02:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
if (! gimp_item_stroke (item, drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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);
|
|
|
|
}
|
2020-08-01 19:59:21 +08:00
|
|
|
|
|
|
|
g_list_free (drawables);
|
2016-10-31 00:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
items_fill_callback (GtkWidget *dialog,
|
|
|
|
GimpItem *item,
|
2020-08-01 19:12:21 +08:00
|
|
|
GList *drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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);
|
|
|
|
|
2020-08-01 19:12:21 +08:00
|
|
|
if (! gimp_item_fill (item, drawables, options, TRUE, NULL, &error))
|
2016-10-31 00:02:59 +08:00
|
|
|
{
|
|
|
|
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,
|
2020-08-01 19:59:21 +08:00
|
|
|
GList *drawables,
|
2016-10-31 00:02:59 +08:00
|
|
|
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);
|
|
|
|
|
2020-08-01 19:59:21 +08:00
|
|
|
if (! gimp_item_stroke (item, drawables, context, options, NULL,
|
2016-10-31 00:02:59 +08:00
|
|
|
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);
|
|
|
|
}
|