From b81b60950bcc1463882d70b1e07a725fdc628e1e Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 26 Oct 2016 16:51:56 +0200 Subject: [PATCH] app: bring the "Switches" column to the channel and path properties dialogs Introduce item-options-dialog.[ch] which abstracts this away and use it from the layer, channel, vectors options dialogs. This is all pretty ugly but better than duplicating that code three times. The vector-options-dialog is now completely pointless but I kept it anyway for now, let's see what unique path options we come up with. --- app/actions/channels-commands.c | 83 ++++-- app/actions/layers-commands.c | 12 + app/actions/quick-mask-commands.c | 19 +- app/actions/vectors-commands.c | 65 ++++- app/dialogs/Makefile.am | 2 + app/dialogs/channel-options-dialog.c | 218 ++++++-------- app/dialogs/channel-options-dialog.h | 12 +- app/dialogs/item-options-dialog.c | 417 +++++++++++++++++++++++++++ app/dialogs/item-options-dialog.h | 72 +++++ app/dialogs/layer-options-dialog.c | 331 +++++++-------------- app/dialogs/layer-options-dialog.h | 7 +- app/dialogs/vectors-options-dialog.c | 142 ++++----- app/dialogs/vectors-options-dialog.h | 9 + po/POTFILES.in | 1 + 14 files changed, 920 insertions(+), 470 deletions(-) create mode 100644 app/dialogs/item-options-dialog.c create mode 100644 app/dialogs/item-options-dialog.h diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c index 202faef8f7..8d6214bc96 100644 --- a/app/actions/channels-commands.c +++ b/app/actions/channels-commands.c @@ -62,6 +62,10 @@ static void channels_new_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data); static void channels_edit_attributes_callback (GtkWidget *dialog, GimpImage *image, @@ -70,6 +74,10 @@ static void channels_edit_attributes_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data); @@ -92,6 +100,8 @@ channels_edit_attributes_cmd_callback (GtkAction *action, if (! dialog) { + GimpItem *item = GIMP_ITEM (channel); + dialog = channel_options_dialog_new (image, channel, action_data_get_context (data), widget, @@ -100,11 +110,15 @@ channels_edit_attributes_cmd_callback (GtkAction *action, "gtk-edit", _("Edit Channel Attributes"), GIMP_HELP_CHANNEL_EDIT, + _("Edit Channel Color"), + _("_Fill opacity:"), + FALSE, gimp_object_get_name (channel), &channel->color, - _("Edit Channel Color"), - _("_Fill opacity"), - FALSE, + gimp_item_get_visible (item), + gimp_item_get_linked (item), + gimp_item_get_lock_content (item), + gimp_item_get_lock_position (item), channels_edit_attributes_callback, NULL); @@ -140,11 +154,15 @@ channels_new_cmd_callback (GtkAction *action, GIMP_STOCK_CHANNEL, _("Create a New Channel"), GIMP_HELP_CHANNEL_NEW, + _("New Channel Color"), + _("_Fill opacity:"), + TRUE, config->channel_new_name, &config->channel_new_color, - _("New Channel Color"), - _("_Fill opacity"), TRUE, + FALSE, + FALSE, + FALSE, channels_new_callback, NULL); @@ -355,6 +373,10 @@ channels_new_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data) { GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config); @@ -387,6 +409,11 @@ channels_new_callback (GtkWidget *dialog, GIMP_FILL_TRANSPARENT); } + gimp_item_set_visible (GIMP_ITEM (channel), channel_visible, FALSE); + gimp_item_set_linked (GIMP_ITEM (channel), channel_linked, FALSE); + gimp_item_set_lock_content (GIMP_ITEM (channel), channel_lock_content, FALSE); + gimp_item_set_lock_position (GIMP_ITEM (channel), channel_lock_position, FALSE); + gimp_image_add_channel (image, channel, GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE); gimp_image_flush (image); @@ -402,32 +429,44 @@ channels_edit_attributes_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data) { - gboolean name_changed = FALSE; - gboolean color_changed = FALSE; + GimpItem *item = GIMP_ITEM (channel); - if (strcmp (channel_name, gimp_object_get_name (channel))) - name_changed = TRUE; - - if (gimp_rgba_distance (channel_color, &channel->color) > 0.0001) - color_changed = TRUE; - - if (name_changed || color_changed) + if (strcmp (channel_name, gimp_object_get_name (channel)) || + gimp_rgba_distance (channel_color, &channel->color) > 0.0001 || + channel_visible != gimp_item_get_visible (item) || + channel_linked != gimp_item_get_linked (item) || + channel_lock_content != gimp_item_get_lock_content (item) || + channel_lock_position != gimp_item_get_lock_position (item)) { - if (name_changed && color_changed) - gimp_image_undo_group_start (image, - GIMP_UNDO_GROUP_ITEM_PROPERTIES, - _("Channel Attributes")); + gimp_image_undo_group_start (image, + GIMP_UNDO_GROUP_ITEM_PROPERTIES, + _("Channel Attributes")); - if (name_changed) + if (strcmp (channel_name, gimp_object_get_name (channel))) gimp_item_rename (GIMP_ITEM (channel), channel_name, NULL); - if (color_changed) + if (gimp_rgba_distance (channel_color, &channel->color) > 0.0001) gimp_channel_set_color (channel, channel_color, TRUE); - if (name_changed && color_changed) - gimp_image_undo_group_end (image); + if (channel_visible != gimp_item_get_visible (item)) + gimp_item_set_visible (item, channel_visible, TRUE); + + if (channel_linked != gimp_item_get_linked (item)) + gimp_item_set_linked (item, channel_linked, TRUE); + + if (channel_lock_content != gimp_item_get_lock_content (item)) + gimp_item_set_lock_content (item, channel_lock_content, TRUE); + + if (channel_lock_position != gimp_item_get_lock_position (item)) + gimp_item_set_lock_position (item, channel_lock_position, TRUE); + + gimp_image_undo_group_end (image); gimp_image_flush (image); } diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c index 814f40149b..d3dc4e4668 100644 --- a/app/actions/layers-commands.c +++ b/app/actions/layers-commands.c @@ -243,6 +243,8 @@ layers_edit_attributes_cmd_callback (GtkAction *action, if (! dialog) { + GimpItem *item = GIMP_ITEM (layer); + dialog = layer_options_dialog_new (gimp_item_get_image (GIMP_ITEM (layer)), layer, action_data_get_context (data), @@ -256,6 +258,11 @@ layers_edit_attributes_cmd_callback (GtkAction *action, gimp_layer_get_mode (layer), gimp_layer_get_opacity (layer), 0 /* unused */, + gimp_item_get_visible (item), + gimp_item_get_linked (item), + gimp_item_get_lock_content (item), + gimp_item_get_lock_position (item), + gimp_layer_get_lock_alpha (layer), layers_edit_attributes_callback, NULL); @@ -316,6 +323,11 @@ layers_new_cmd_callback (GtkAction *action, config->layer_new_mode, config->layer_new_opacity, config->layer_new_fill_type, + TRUE, + FALSE, + FALSE, + FALSE, + FALSE, layers_new_callback, NULL); diff --git a/app/actions/quick-mask-commands.c b/app/actions/quick-mask-commands.c index d2dab279a0..252af5034e 100644 --- a/app/actions/quick-mask-commands.c +++ b/app/actions/quick-mask-commands.c @@ -34,6 +34,7 @@ #include "dialogs/dialogs.h" #include "dialogs/channel-options-dialog.h" +#include "dialogs/item-options-dialog.h" #include "actions.h" #include "quick-mask-commands.h" @@ -50,6 +51,10 @@ static void quick_mask_configure_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data); @@ -118,14 +123,20 @@ quick_mask_configure_cmd_callback (GtkAction *action, GIMP_STOCK_QUICK_MASK_ON, _("Edit Quick Mask Attributes"), GIMP_HELP_QUICK_MASK_EDIT, + _("Edit Quick Mask Color"), + _("_Mask opacity:"), + FALSE, NULL, &color, - _("Edit Quick Mask Color"), - _("_Mask opacity"), + FALSE, + FALSE, + FALSE, FALSE, quick_mask_configure_callback, NULL); + item_options_dialog_set_switches_visible (dialog, FALSE); + dialogs_attach_dialog (G_OBJECT (image), CONFIGURE_DIALOG_KEY, dialog); } @@ -143,6 +154,10 @@ quick_mask_configure_callback (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data) { GimpRGB old_color; diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c index 008e0bb6bc..71583875a0 100644 --- a/app/actions/vectors-commands.c +++ b/app/actions/vectors-commands.c @@ -77,12 +77,22 @@ static void vectors_new_callback (GtkWidget *dialog, GimpImage *image, GimpVectors *vectors, + GimpContext *context, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + 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, + gboolean vectors_lock_content, + gboolean vectors_lock_position, gpointer user_data); static void vectors_fill_callback (GtkWidget *dialog, GimpItem *item, @@ -150,6 +160,8 @@ vectors_edit_attributes_cmd_callback (GtkAction *action, if (! dialog) { + GimpItem *item = GIMP_ITEM (vectors); + dialog = vectors_options_dialog_new (image, vectors, action_data_get_context (data), widget, @@ -159,6 +171,10 @@ vectors_edit_attributes_cmd_callback (GtkAction *action, _("Edit Path Attributes"), GIMP_HELP_PATH_EDIT, gimp_object_get_name (vectors), + gimp_item_get_visible (item), + gimp_item_get_linked (item), + gimp_item_get_lock_content (item), + gimp_item_get_lock_position (item), vectors_edit_attributes_callback, NULL); @@ -195,6 +211,10 @@ vectors_new_cmd_callback (GtkAction *action, _("Create a New Path"), GIMP_HELP_PATH_NEW, config->vectors_new_name, + FALSE, + FALSE, + FALSE, + FALSE, vectors_new_callback, NULL); @@ -816,7 +836,12 @@ static void vectors_new_callback (GtkWidget *dialog, GimpImage *image, GimpVectors *vectors, + GimpContext *context, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + gboolean vectors_lock_content, + gboolean vectors_lock_position, gpointer user_data) { GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config); @@ -826,6 +851,11 @@ vectors_new_callback (GtkWidget *dialog, NULL); vectors = gimp_vectors_new (image, config->vectors_new_name); + gimp_item_set_visible (GIMP_ITEM (vectors), vectors_visible, FALSE); + gimp_item_set_linked (GIMP_ITEM (vectors), vectors_linked, FALSE); + gimp_item_set_lock_content (GIMP_ITEM (vectors), vectors_lock_content, FALSE); + gimp_item_set_lock_position (GIMP_ITEM (vectors), vectors_lock_position, FALSE); + gimp_image_add_vectors (image, vectors, GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE); gimp_image_flush (image); @@ -837,12 +867,43 @@ static void vectors_edit_attributes_callback (GtkWidget *dialog, GimpImage *image, GimpVectors *vectors, + GimpContext *context, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + gboolean vectors_lock_content, + gboolean vectors_lock_position, gpointer user_data) { - if (strcmp (vectors_name, gimp_object_get_name (vectors))) + GimpItem *item = GIMP_ITEM (vectors); + + if (strcmp (vectors_name, gimp_object_get_name (vectors)) || + vectors_visible != gimp_item_get_visible (item) || + vectors_linked != gimp_item_get_linked (item) || + vectors_lock_content != gimp_item_get_lock_content (item) || + vectors_lock_position != gimp_item_get_lock_position (item)) { - gimp_item_rename (GIMP_ITEM (vectors), vectors_name, NULL); + gimp_image_undo_group_start (image, + GIMP_UNDO_GROUP_ITEM_PROPERTIES, + _("Path Attributes")); + + if (strcmp (vectors_name, gimp_object_get_name (vectors))) + gimp_item_rename (GIMP_ITEM (vectors), vectors_name, NULL); + + if (vectors_visible != gimp_item_get_visible (item)) + gimp_item_set_visible (item, vectors_visible, TRUE); + + if (vectors_linked != gimp_item_get_linked (item)) + gimp_item_set_linked (item, vectors_linked, TRUE); + + if (vectors_lock_content != gimp_item_get_lock_content (item)) + gimp_item_set_lock_content (item, vectors_lock_content, TRUE); + + if (vectors_lock_position != gimp_item_get_lock_position (item)) + gimp_item_set_lock_position (item, vectors_lock_position, TRUE); + + gimp_image_undo_group_end (image); + gimp_image_flush (image); } diff --git a/app/dialogs/Makefile.am b/app/dialogs/Makefile.am index 72c8fcc91d..e2b399a9f9 100644 --- a/app/dialogs/Makefile.am +++ b/app/dialogs/Makefile.am @@ -57,6 +57,8 @@ libappdialogs_a_sources = \ image-scale-dialog.h \ input-devices-dialog.c \ input-devices-dialog.h \ + item-options-dialog.c \ + item-options-dialog.h \ keyboard-shortcuts-dialog.c \ keyboard-shortcuts-dialog.h \ layer-add-mask-dialog.c \ diff --git a/app/dialogs/channel-options-dialog.c b/app/dialogs/channel-options-dialog.c index b8474cc0eb..7109a050e4 100644 --- a/app/dialogs/channel-options-dialog.c +++ b/app/dialogs/channel-options-dialog.c @@ -34,6 +34,7 @@ #include "widgets/gimpviewabledialog.h" #include "channel-options-dialog.h" +#include "item-options-dialog.h" #include "gimp-intl.h" @@ -42,28 +43,31 @@ typedef struct _ChannelOptionsDialog ChannelOptionsDialog; struct _ChannelOptionsDialog { - GimpImage *image; - GimpContext *context; - GimpChannel *channel; GimpChannelOptionsCallback callback; gpointer user_data; - GtkWidget *name_entry; GtkWidget *color_panel; - GtkWidget *save_sel_checkbutton; + GtkWidget *save_sel_toggle; }; /* local function prototypes */ -static void channel_options_dialog_response (GtkWidget *dialog, - gint response_id, - ChannelOptionsDialog *private); -static void channel_options_opacity_update (GtkAdjustment *adjustment, +static void channel_options_dialog_free (ChannelOptionsDialog *private); +static void channel_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data); +static void channel_options_opacity_changed (GtkAdjustment *adjustment, GimpColorButton *color_button); static void channel_options_color_changed (GimpColorButton *color_button, GtkAdjustment *adjustment); -static void channel_options_dialog_free (ChannelOptionsDialog *private); /* public functions */ @@ -78,19 +82,20 @@ channel_options_dialog_new (GimpImage *image, const gchar *icon_name, const gchar *desc, const gchar *help_id, - const gchar *channel_name, - const GimpRGB *channel_color, const gchar *color_label, const gchar *opacity_label, gboolean show_from_sel, + const gchar *channel_name, + const GimpRGB *channel_color, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, GimpChannelOptionsCallback callback, gpointer user_data) { ChannelOptionsDialog *private; GtkWidget *dialog; - GimpViewable *viewable; - GtkWidget *hbox; - GtkWidget *vbox; GtkAdjustment *opacity_adj; GtkWidget *scale; @@ -110,108 +115,60 @@ channel_options_dialog_new (GimpImage *image, private = g_slice_new0 (ChannelOptionsDialog); - private->image = image; - private->channel = channel; - private->context = context; private->callback = callback; private->user_data = user_data; - if (channel) - viewable = GIMP_VIEWABLE (channel); - else - viewable = GIMP_VIEWABLE (image); - - dialog = gimp_viewable_dialog_new (viewable, context, - title, role, icon_name, desc, - parent, - gimp_standard_help_func, help_id, - - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - - NULL); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); + dialog = item_options_dialog_new (image, GIMP_ITEM (channel), context, + parent, title, role, + icon_name, desc, help_id, + channel_name ? _("Channel _name:") : NULL, + GIMP_STOCK_TOOL_PAINTBRUSH, + _("Lock _pixels"), + _("Lock position and _size"), + channel_name, + channel_visible, + channel_linked, + channel_lock_content, + channel_lock_position, + channel_options_dialog_callback, + private); g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) channel_options_dialog_free, private); - g_signal_connect (dialog, "response", - G_CALLBACK (channel_options_dialog_response), - private); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - if (channel_name) - { - GtkWidget *vbox2; - GtkWidget *label; - - vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); - gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0); - gtk_widget_show (vbox2); - - label = gtk_label_new_with_mnemonic (_("Channel _name:")); - gtk_label_set_xalign (GTK_LABEL (label), 0.0); - gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); - gtk_widget_show (label); - - private->name_entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (private->name_entry), channel_name); - gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE); - gtk_box_pack_start (GTK_BOX (vbox2), private->name_entry, - FALSE, FALSE, 0); - gtk_widget_show (private->name_entry); - - gtk_label_set_mnemonic_widget (GTK_LABEL (label), private->name_entry); - } - opacity_adj = (GtkAdjustment *) gtk_adjustment_new (channel_color->a * 100.0, 0.0, 100.0, 1.0, 10.0, 0); - scale = gimp_spin_scale_new (opacity_adj, opacity_label, 1); + scale = gimp_spin_scale_new (opacity_adj, NULL, 1); gtk_widget_set_size_request (scale, 200, -1); - gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); - gtk_widget_show (scale); + item_options_dialog_add_widget (dialog, + opacity_label, scale); private->color_panel = gimp_color_panel_new (color_label, channel_color, GIMP_COLOR_AREA_LARGE_CHECKS, - 48, 48); + 24, 24); gimp_color_panel_set_context (GIMP_COLOR_PANEL (private->color_panel), context); g_signal_connect (opacity_adj, "value-changed", - G_CALLBACK (channel_options_opacity_update), + G_CALLBACK (channel_options_opacity_changed), private->color_panel); - gtk_box_pack_start (GTK_BOX (hbox), private->color_panel, - FALSE, FALSE, 0); - gtk_widget_show (private->color_panel); - g_signal_connect (private->color_panel, "color-changed", G_CALLBACK (channel_options_color_changed), opacity_adj); + item_options_dialog_add_widget (dialog, + NULL, private->color_panel); + if (show_from_sel) { - private->save_sel_checkbutton = + private->save_sel_toggle = gtk_check_button_new_with_mnemonic (_("Initialize from _selection")); - gtk_box_pack_start (GTK_BOX (vbox), private->save_sel_checkbutton, - FALSE, FALSE, 0); - gtk_widget_show (private->save_sel_checkbutton); + item_options_dialog_add_widget (dialog, + NULL, private->save_sel_toggle); } return dialog; @@ -221,46 +178,53 @@ channel_options_dialog_new (GimpImage *image, /* private functions */ static void -channel_options_dialog_response (GtkWidget *dialog, - gint response_id, - ChannelOptionsDialog *private) +channel_options_dialog_free (ChannelOptionsDialog *private) { - if (response_id == GTK_RESPONSE_OK) - { - const gchar *name = NULL; - GimpRGB color; - gboolean save_selection = FALSE; - - if (private->name_entry) - name = gtk_entry_get_text (GTK_ENTRY (private->name_entry)); - - gimp_color_button_get_color (GIMP_COLOR_BUTTON (private->color_panel), - &color); - - if (private->save_sel_checkbutton) - save_selection = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (private->save_sel_checkbutton)); - - private->callback (dialog, - private->image, - private->channel, - private->context, - name, - &color, - save_selection, - private->user_data); - } - else - { - gtk_widget_destroy (dialog); - } + g_slice_free (ChannelOptionsDialog, private); } static void -channel_options_opacity_update (GtkAdjustment *adjustment, - GimpColorButton *color_button) +channel_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data) { - GimpRGB color; + ChannelOptionsDialog *private = user_data; + GimpRGB color; + gboolean save_selection = FALSE; + + gimp_color_button_get_color (GIMP_COLOR_BUTTON (private->color_panel), + &color); + + if (private->save_sel_toggle) + save_selection = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (private->save_sel_toggle)); + + private->callback (dialog, + image, + GIMP_CHANNEL (item), + context, + item_name, + &color, + save_selection, + item_visible, + item_linked, + item_lock_content, + item_lock_position, + private->user_data); +} + +static void +channel_options_opacity_changed (GtkAdjustment *adjustment, + GimpColorButton *color_button) +{ + GimpRGB color; gimp_color_button_get_color (color_button, &color); gimp_rgb_set_alpha (&color, gtk_adjustment_get_value (adjustment) / 100.0); @@ -271,14 +235,8 @@ static void channel_options_color_changed (GimpColorButton *button, GtkAdjustment *adjustment) { - GimpRGB color; + GimpRGB color; gimp_color_button_get_color (button, &color); gtk_adjustment_set_value (adjustment, color.a * 100.0); } - -static void -channel_options_dialog_free (ChannelOptionsDialog *options) -{ - g_slice_free (ChannelOptionsDialog, options); -} diff --git a/app/dialogs/channel-options-dialog.h b/app/dialogs/channel-options-dialog.h index a4952a8aaf..b02a95db58 100644 --- a/app/dialogs/channel-options-dialog.h +++ b/app/dialogs/channel-options-dialog.h @@ -26,6 +26,10 @@ typedef void (* GimpChannelOptionsCallback) (GtkWidget *dialog, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, gpointer user_data); @@ -38,11 +42,15 @@ GtkWidget * channel_options_dialog_new (GimpImage *image, const gchar *icon_name, const gchar *desc, const gchar *help_id, - const gchar *channel_name, - const GimpRGB *channel_color, const gchar *color_label, const gchar *opacity_label, gboolean show_from_sel, + const gchar *channel_name, + const GimpRGB *channel_color, + gboolean channel_visible, + gboolean channel_linked, + gboolean channel_lock_content, + gboolean channel_lock_position, GimpChannelOptionsCallback callback, gpointer user_data); diff --git a/app/dialogs/item-options-dialog.c b/app/dialogs/item-options-dialog.c new file mode 100644 index 0000000000..1e1d0c83a7 --- /dev/null +++ b/app/dialogs/item-options-dialog.c @@ -0,0 +1,417 @@ +/* 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 . + */ + +#include "config.h" + +#include +#include + +#include "libgimpbase/gimpbase.h" +#include "libgimpwidgets/gimpwidgets.h" + +#include "dialogs-types.h" + +#include "core/gimpcontext.h" +#include "core/gimpimage.h" +#include "core/gimpitem.h" + +#include "widgets/gimpviewabledialog.h" + +#include "item-options-dialog.h" + +#include "gimp-intl.h" + + +typedef struct _ItemOptionsDialog ItemOptionsDialog; + +struct _ItemOptionsDialog +{ + GimpImage *image; + GimpItem *item; + GimpContext *context; + gboolean visible; + gboolean linked; + gboolean lock_content; + gboolean lock_position; + GimpItemOptionsCallback callback; + gpointer user_data; + + GtkWidget *left_vbox; + GtkWidget *left_table; + gint table_row; + GtkWidget *name_entry; + GtkWidget *right_frame; + GtkWidget *right_vbox; + GtkWidget *lock_position_toggle; +}; + + +/* local function prototypes */ + +static void item_options_dialog_free (ItemOptionsDialog *private); +static void item_options_dialog_response (GtkWidget *dialog, + gint response_id, + ItemOptionsDialog *private); +static GtkWidget * check_button_with_icon_new (const gchar *label, + const gchar *icon_name, + GtkBox *vbox); + + +/* public functions */ + +GtkWidget * +item_options_dialog_new (GimpImage *image, + GimpItem *item, + GimpContext *context, + GtkWidget *parent, + const gchar *title, + const gchar *role, + const gchar *icon_name, + const gchar *desc, + const gchar *help_id, + const gchar *name_label, + const gchar *lock_content_icon_name, + const gchar *lock_content_label, + const gchar *lock_position_label, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + GimpItemOptionsCallback callback, + gpointer user_data) +{ + ItemOptionsDialog *private; + GtkWidget *dialog; + GimpViewable *viewable; + GtkWidget *main_hbox; + GtkWidget *table; + GtkWidget *button; + + g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); + g_return_val_if_fail (item == NULL || GIMP_IS_ITEM (item), NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); + g_return_val_if_fail (title != NULL, NULL); + g_return_val_if_fail (role != NULL, NULL); + g_return_val_if_fail (icon_name != NULL, NULL); + g_return_val_if_fail (desc != NULL, NULL); + g_return_val_if_fail (help_id != NULL, NULL); + g_return_val_if_fail (callback != NULL, NULL); + + private = g_slice_new0 (ItemOptionsDialog); + + private->image = image; + private->item = item; + private->context = context; + private->visible = item_visible; + private->linked = item_linked; + private->lock_content = item_lock_content; + private->lock_position = item_lock_position; + private->callback = callback; + private->user_data = user_data; + + if (item) + viewable = GIMP_VIEWABLE (item); + else + viewable = GIMP_VIEWABLE (image); + + dialog = gimp_viewable_dialog_new (viewable, context, + title, role, icon_name, desc, + parent, + gimp_standard_help_func, help_id, + + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + + NULL); + + gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + GTK_RESPONSE_CANCEL, + -1); + + g_signal_connect (dialog, "response", + G_CALLBACK (item_options_dialog_response), + private); + + g_object_weak_ref (G_OBJECT (dialog), + (GWeakNotify) item_options_dialog_free, private); + + g_object_set_data (G_OBJECT (dialog), "item-options-dialog-private", private); + + main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), + main_hbox, TRUE, TRUE, 0); + gtk_widget_show (main_hbox); + + private->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); + gtk_box_pack_start (GTK_BOX (main_hbox), private->left_vbox, TRUE, TRUE, 0); + gtk_widget_show (private->left_vbox); + + private->left_table = table = gtk_table_new (1, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 6); + gtk_table_set_row_spacings (GTK_TABLE (table), 6); + gtk_box_pack_start (GTK_BOX (private->left_vbox), table, FALSE, FALSE, 0); + gtk_widget_show (table); + + /* The name label and entry */ + if (name_label) + { + private->name_entry = gtk_entry_new (); + gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE); + gtk_entry_set_text (GTK_ENTRY (private->name_entry), item_name); + gimp_table_attach_aligned (GTK_TABLE (table), 0, private->table_row++, + name_label, 0.0, 0.5, + private->name_entry, 1, FALSE); + } + + /* The switches frame & vbox */ + + private->right_frame = gimp_frame_new (_("Switches")); + gtk_box_pack_start (GTK_BOX (main_hbox), private->right_frame, + FALSE, FALSE, 0); + gtk_widget_show (private->right_frame); + + private->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_container_add (GTK_CONTAINER (private->right_frame), private->right_vbox); + gtk_widget_show (private->right_vbox); + + button = check_button_with_icon_new (_("_Visible"), + GIMP_STOCK_VISIBLE, + GTK_BOX (private->right_vbox)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + private->visible); + g_signal_connect (button, "toggled", + G_CALLBACK (gimp_toggle_button_update), + &private->visible); + + button = check_button_with_icon_new (_("_Linked"), + GIMP_STOCK_LINKED, + GTK_BOX (private->right_vbox)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + private->linked); + g_signal_connect (button, "toggled", + G_CALLBACK (gimp_toggle_button_update), + &private->linked); + + button = check_button_with_icon_new (lock_content_label, + lock_content_icon_name, + GTK_BOX (private->right_vbox)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + private->lock_content); + g_signal_connect (button, "toggled", + G_CALLBACK (gimp_toggle_button_update), + &private->lock_content); + + button = check_button_with_icon_new (lock_position_label, + GIMP_STOCK_TOOL_MOVE, + GTK_BOX (private->right_vbox)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + private->lock_position); + g_signal_connect (button, "toggled", + G_CALLBACK (gimp_toggle_button_update), + &private->lock_position); + + private->lock_position_toggle = button; + + return dialog; +} + +GtkWidget * +item_options_dialog_get_vbox (GtkWidget *dialog) +{ + ItemOptionsDialog *private; + + g_return_val_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog), NULL); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_val_if_fail (private != NULL, NULL); + + return private->left_vbox; +} + +GtkWidget * +item_options_dialog_get_table (GtkWidget *dialog, + gint *next_row) +{ + ItemOptionsDialog *private; + + g_return_val_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog), NULL); + g_return_val_if_fail (next_row != NULL, NULL); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_val_if_fail (private != NULL, NULL); + + *next_row = private->table_row; + + return private->left_table; +} + +GtkWidget * +item_options_dialog_get_name_entry (GtkWidget *dialog) +{ + ItemOptionsDialog *private; + + g_return_val_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog), NULL); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_val_if_fail (private != NULL, NULL); + + return private->name_entry; +} + +GtkWidget * +item_options_dialog_get_lock_position (GtkWidget *dialog) +{ + ItemOptionsDialog *private; + + g_return_val_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog), NULL); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_val_if_fail (private != NULL, NULL); + + return private->lock_position_toggle; +} + +void +item_options_dialog_add_widget (GtkWidget *dialog, + const gchar *label, + GtkWidget *widget) +{ + ItemOptionsDialog *private; + + g_return_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_if_fail (private != NULL); + + gimp_table_attach_aligned (GTK_TABLE (private->left_table), + 0, private->table_row++, + label, 0.0, 0.5, + widget, 1, FALSE); +} + +GtkWidget * +item_options_dialog_add_switch (GtkWidget *dialog, + const gchar *icon_name, + const gchar *label) +{ + ItemOptionsDialog *private; + + g_return_val_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog), NULL); + g_return_val_if_fail (icon_name != NULL, NULL); + g_return_val_if_fail (label != NULL, NULL); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_val_if_fail (private != NULL, NULL); + + return check_button_with_icon_new (label, icon_name, + GTK_BOX (private->right_vbox)); +} + +void +item_options_dialog_set_switches_visible (GtkWidget *dialog, + gboolean visible) +{ + ItemOptionsDialog *private; + + g_return_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog)); + + private = g_object_get_data (G_OBJECT (dialog), + "item-options-dialog-private"); + + g_return_if_fail (private != NULL); + + gtk_widget_set_visible (private->right_frame, visible); +} + + +/* private functions */ + +static void +item_options_dialog_free (ItemOptionsDialog *private) +{ + g_slice_free (ItemOptionsDialog, private); +} + +static void +item_options_dialog_response (GtkWidget *dialog, + gint response_id, + ItemOptionsDialog *private) +{ + if (response_id == GTK_RESPONSE_OK) + { + const gchar *name = NULL; + + if (private->name_entry) + name = gtk_entry_get_text (GTK_ENTRY (private->name_entry)); + + private->callback (dialog, + private->image, + private->item, + private->context, + name, + private->visible, + private->linked, + private->lock_content, + private->lock_position, + private->user_data); + } + else + { + gtk_widget_destroy (dialog); + } +} + +static GtkWidget * +check_button_with_icon_new (const gchar *label, + const gchar *icon_name, + GtkBox *vbox) +{ + GtkWidget *hbox; + GtkWidget *button; + GtkWidget *image; + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_widget_show (image); + + button = gtk_check_button_new_with_mnemonic (label); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + return button; +} diff --git a/app/dialogs/item-options-dialog.h b/app/dialogs/item-options-dialog.h new file mode 100644 index 0000000000..b09fc4b976 --- /dev/null +++ b/app/dialogs/item-options-dialog.h @@ -0,0 +1,72 @@ +/* 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 . + */ + +#ifndef __ITEM_OPTIONS_DIALOG_H__ +#define __ITEM_OPTIONS_DIALOG_H__ + + +typedef void (* GimpItemOptionsCallback) (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data); + + +GtkWidget * item_options_dialog_new (GimpImage *image, + GimpItem *item, + GimpContext *context, + GtkWidget *parent, + const gchar *title, + const gchar *role, + const gchar *icon_name, + const gchar *desc, + const gchar *help_id, + const gchar *name_label, + const gchar *lock_content_icon_name, + const gchar *lock_content_label, + const gchar *lock_position_label, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + GimpItemOptionsCallback callback, + gpointer user_data); + +GtkWidget * item_options_dialog_get_vbox (GtkWidget *dialog); +GtkWidget * item_options_dialog_get_table (GtkWidget *dialog, + gint *next_row); +GtkWidget * item_options_dialog_get_name_entry (GtkWidget *dialog); +GtkWidget * item_options_dialog_get_lock_position (GtkWidget *dialog); + +void item_options_dialog_add_widget (GtkWidget *dialog, + const gchar *label, + GtkWidget *widget); +GtkWidget * item_options_dialog_add_switch (GtkWidget *dialog, + const gchar *icon_name, + const gchar *label); + +void item_options_dialog_set_switches_visible (GtkWidget *dialog, + gboolean visible); + + +#endif /* __ITEM_OPTIONS_DIALOG_H__ */ diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c index 1b35440fd2..e501a8ae19 100644 --- a/app/dialogs/layer-options-dialog.c +++ b/app/dialogs/layer-options-dialog.c @@ -39,6 +39,7 @@ #include "widgets/gimpviewabledialog.h" #include "widgets/gimpwidgets-constructors.h" +#include "item-options-dialog.h" #include "layer-options-dialog.h" #include "gimp-intl.h" @@ -48,22 +49,15 @@ typedef struct _LayerOptionsDialog LayerOptionsDialog; struct _LayerOptionsDialog { - GimpImage *image; GimpLayer *layer; - GimpContext *context; GimpLayerModeEffects mode; gdouble opacity; GimpFillType fill_type; - gboolean visible; - gboolean linked; - gboolean lock_pixels; - gboolean lock_position; gboolean lock_alpha; gboolean rename_text_layers; GimpLayerOptionsCallback callback; gpointer user_data; - GtkWidget *name_entry; GtkWidget *size_se; GtkWidget *offset_se; }; @@ -72,14 +66,18 @@ struct _LayerOptionsDialog /* local function prototypes */ static void layer_options_dialog_free (LayerOptionsDialog *private); -static void layer_options_dialog_response (GtkWidget *dialog, - gint response_id, - LayerOptionsDialog *private); +static void layer_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data); static void layer_options_dialog_toggle_rename (GtkWidget *widget, LayerOptionsDialog *private); -static GtkWidget * check_button_with_icon_new (const gchar *label, - const gchar *icon_name, - GtkBox *vbox); /* public functions */ @@ -98,23 +96,22 @@ layer_options_dialog_new (GimpImage *image, GimpLayerModeEffects layer_mode, gdouble layer_opacity, GimpFillType layer_fill_type, + gboolean layer_visible, + gboolean layer_linked, + gboolean layer_lock_content, + gboolean layer_lock_position, + gboolean layer_lock_alpha, GimpLayerOptionsCallback callback, gpointer user_data) { LayerOptionsDialog *private; GtkWidget *dialog; - GimpViewable *viewable; - GtkWidget *main_hbox; - GtkWidget *left_vbox; - GtkWidget *right_vbox; GtkWidget *table; GtkWidget *combo; GtkWidget *scale; GtkWidget *label; GtkAdjustment *adjustment; GtkWidget *spinbutton; - GtkWidget *frame; - GtkWidget *vbox; GtkWidget *button; gdouble xres; gdouble yres; @@ -127,93 +124,38 @@ layer_options_dialog_new (GimpImage *image, private = g_slice_new0 (LayerOptionsDialog); - private->image = image; private->layer = layer; - private->context = context; private->mode = layer_mode; private->opacity = layer_opacity * 100.0; private->fill_type = layer_fill_type; - private->visible = TRUE; - private->linked = FALSE; - private->lock_pixels = FALSE; - private->lock_position = FALSE; - private->lock_alpha = FALSE; + private->lock_alpha = layer_lock_alpha; private->rename_text_layers = FALSE; private->callback = callback; private->user_data = user_data; - if (layer) - { - viewable = GIMP_VIEWABLE (layer); + if (layer && gimp_item_is_text_layer (GIMP_ITEM (layer))) + private->rename_text_layers = GIMP_TEXT_LAYER (layer)->auto_rename; - private->visible = gimp_item_get_visible (GIMP_ITEM (layer)); - private->linked = gimp_item_get_linked (GIMP_ITEM (layer)); - private->lock_pixels = gimp_item_get_lock_content (GIMP_ITEM (layer)); - private->lock_position = gimp_item_get_lock_position (GIMP_ITEM (layer)); - private->lock_alpha = gimp_layer_get_lock_alpha (layer); - - if (gimp_item_is_text_layer (GIMP_ITEM (layer))) - private->rename_text_layers = GIMP_TEXT_LAYER (layer)->auto_rename; - } - else - { - viewable = GIMP_VIEWABLE (image); - } - - dialog = gimp_viewable_dialog_new (viewable, context, - title, role, icon_name, desc, - parent, - gimp_standard_help_func, help_id, - - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - - NULL); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - - g_signal_connect (dialog, "response", - G_CALLBACK (layer_options_dialog_response), - private); + dialog = item_options_dialog_new (image, GIMP_ITEM (layer), context, + parent, title, role, + icon_name, desc, help_id, + _("Layer _name:"), + GIMP_STOCK_TOOL_PAINTBRUSH, + _("Lock _pixels"), + _("Lock position and _size"), + layer_name, + layer_visible, + layer_linked, + layer_lock_content, + layer_lock_position, + layer_options_dialog_callback, + private); g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) layer_options_dialog_free, private); - main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - main_hbox, TRUE, TRUE, 0); - gtk_widget_show (main_hbox); - - left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_box_pack_start (GTK_BOX (main_hbox), left_vbox, TRUE, TRUE, 0); - gtk_widget_show (left_vbox); - - table = gtk_table_new (layer ? 5 : 8, 2, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), 6); - gtk_table_set_row_spacings (GTK_TABLE (table), 6); - gtk_table_set_row_spacing (GTK_TABLE (table), 3, 4); - if (! layer) - gtk_table_set_row_spacing (GTK_TABLE (table), 5, 4); - gtk_box_pack_start (GTK_BOX (left_vbox), table, FALSE, FALSE, 0); - gtk_widget_show (table); - - /* The name label and entry */ - private->name_entry = gtk_entry_new (); - gimp_table_attach_aligned (GTK_TABLE (table), 0, row++, - _("Layer _name:"), 0.0, 0.5, - private->name_entry, 1, FALSE); - - gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE); - gtk_entry_set_text (GTK_ENTRY (private->name_entry), layer_name); - combo = gimp_paint_mode_menu_new (FALSE, FALSE); - gimp_table_attach_aligned (GTK_TABLE (table), 0, row++, - _("_Mode:"), 0.0, 0.5, - combo, 1, FALSE); + item_options_dialog_add_widget (dialog, _("_Mode:"), combo); gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), private->mode, G_CALLBACK (gimp_int_combo_box_get_active), @@ -222,14 +164,14 @@ layer_options_dialog_new (GimpImage *image, adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (private->opacity, 0.0, 100.0, 1.0, 10.0, 0.0)); scale = gimp_spin_scale_new (adjustment, NULL, 1); - gimp_table_attach_aligned (GTK_TABLE (table), 0, row++, - _("_Opacity:"), 0.0, 0.5, - scale, 1, FALSE); + item_options_dialog_add_widget (dialog, _("_Opacity:"), scale); g_signal_connect (adjustment, "value-changed", G_CALLBACK (gimp_double_adjustment_update), &private->opacity); + table = item_options_dialog_get_table (dialog, &row); + gimp_image_get_resolution (image, &xres, &yres); if (! layer) @@ -369,6 +311,11 @@ layer_options_dialog_new (GimpImage *image, row += 2; + /* set the spacings after adding widgets or GtkTable will warn */ + gtk_table_set_row_spacing (GTK_TABLE (table), 3, 4); + if (! layer) + gtk_table_set_row_spacing (GTK_TABLE (table), 5, 4); + if (! layer) { /* The fill type */ @@ -384,6 +331,8 @@ layer_options_dialog_new (GimpImage *image, if (layer) { + GtkWidget *left_vbox = item_options_dialog_get_vbox (dialog); + GtkWidget *frame; GimpContainer *filters; GtkWidget *view; @@ -399,53 +348,7 @@ layer_options_dialog_new (GimpImage *image, gtk_widget_show (view); } - right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, FALSE, FALSE, 0); - gtk_widget_show (right_vbox); - - frame = gimp_frame_new (_("Switches")); - gtk_box_pack_start (GTK_BOX (right_vbox), frame, FALSE, FALSE, 0); - gtk_widget_show (frame); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - button = check_button_with_icon_new (_("_Visible"), - GIMP_STOCK_VISIBLE, - GTK_BOX (vbox)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), - private->visible); - g_signal_connect (button, "toggled", - G_CALLBACK (gimp_toggle_button_update), - &private->visible); - - button = check_button_with_icon_new (_("_Linked"), - GIMP_STOCK_LINKED, - GTK_BOX (vbox)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), - private->linked); - g_signal_connect (button, "toggled", - G_CALLBACK (gimp_toggle_button_update), - &private->linked); - - button = check_button_with_icon_new (_("Lock _pixels"), - GIMP_STOCK_TOOL_PAINTBRUSH, - GTK_BOX (vbox)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), - private->lock_pixels); - g_signal_connect (button, "toggled", - G_CALLBACK (gimp_toggle_button_update), - &private->lock_pixels); - - button = check_button_with_icon_new (_("Lock position and _size"), - GIMP_STOCK_TOOL_MOVE, - GTK_BOX (vbox)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), - private->lock_position); - g_signal_connect (button, "toggled", - G_CALLBACK (gimp_toggle_button_update), - &private->lock_position); + button = item_options_dialog_get_lock_position (dialog); if (private->size_se) g_object_bind_property (G_OBJECT (button), "active", @@ -458,9 +361,9 @@ layer_options_dialog_new (GimpImage *image, G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); - button = check_button_with_icon_new (_("Lock _alpha"), - GIMP_STOCK_TRANSPARENCY, - GTK_BOX (vbox)); + button = item_options_dialog_add_switch (dialog, + GIMP_STOCK_TRANSPARENCY, + _("Lock _alpha")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), private->lock_alpha); g_signal_connect (button, "toggled", @@ -470,9 +373,9 @@ layer_options_dialog_new (GimpImage *image, /* For text layers add a toggle to control "auto-rename" */ if (layer && gimp_item_is_text_layer (GIMP_ITEM (layer))) { - button = check_button_with_icon_new (_("Set name from _text"), - GIMP_STOCK_TOOL_TEXT, - GTK_BOX (vbox)); + button = item_options_dialog_add_switch (dialog, + GIMP_STOCK_TOOL_TEXT, + _("Set name from _text")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), private->rename_text_layers); g_signal_connect (button, "toggled", @@ -497,61 +400,59 @@ layer_options_dialog_free (LayerOptionsDialog *private) } static void -layer_options_dialog_response (GtkWidget *dialog, - gint response_id, - LayerOptionsDialog *private) +layer_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data) { - if (response_id == GTK_RESPONSE_OK) + LayerOptionsDialog *private = user_data; + gint width = 0; + gint height = 0; + gint offset_x; + gint offset_y; + + if (item) { - const gchar *name; - gint width = 0; - gint height = 0; - gint offset_x; - gint offset_y; - - name = gtk_entry_get_text (GTK_ENTRY (private->name_entry)); - - if (! private->layer) - { - width = - RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->size_se), - 0)); - height = - RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->size_se), - 1)); - } - - offset_x = - RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), + width = + RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->size_se), 0)); - offset_y = - RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), + height = + RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->size_se), 1)); + } - private->callback (dialog, - private->image, - private->layer, - private->context, - name, - private->mode, - private->opacity / 100.0, - private->fill_type, - width, - height, - offset_x, - offset_y, - private->visible, - private->linked, - private->lock_pixels, - private->lock_position, - private->lock_alpha, - private->rename_text_layers, - private->user_data); - } - else - { - gtk_widget_destroy (dialog); - } + offset_x = + RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), + 0)); + offset_y = + RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), + 1)); + + private->callback (dialog, + image, + GIMP_LAYER (item), + context, + item_name, + private->mode, + private->opacity / 100.0, + private->fill_type, + width, + height, + offset_x, + offset_y, + item_visible, + item_linked, + item_lock_content, + item_lock_position, + private->lock_alpha, + private->rename_text_layers, + private->user_data); } static void @@ -566,35 +467,17 @@ layer_options_dialog_toggle_rename (GtkWidget *widget, if (text && text->text) { - gchar *name = gimp_utf8_strtrim (text->text, 30); + GtkWidget *dialog; + GtkWidget *name_entry; + gchar *name = gimp_utf8_strtrim (text->text, 30); - gtk_entry_set_text (GTK_ENTRY (private->name_entry), name); + dialog = gtk_widget_get_toplevel (widget); + + name_entry = item_options_dialog_get_name_entry (dialog); + + gtk_entry_set_text (GTK_ENTRY (name_entry), name); g_free (name); } } } - -static GtkWidget * -check_button_with_icon_new (const gchar *label, - const gchar *icon_name, - GtkBox *vbox) -{ - GtkWidget *hbox; - GtkWidget *button; - GtkWidget *image; - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - gtk_widget_show (image); - - button = gtk_check_button_new_with_mnemonic (label); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - - return button; -} diff --git a/app/dialogs/layer-options-dialog.h b/app/dialogs/layer-options-dialog.h index 9103c948e4..34160195bc 100644 --- a/app/dialogs/layer-options-dialog.h +++ b/app/dialogs/layer-options-dialog.h @@ -33,7 +33,7 @@ typedef void (* GimpLayerOptionsCallback) (GtkWidget *dialog, gint layer_offset_y, gboolean layer_visible, gboolean layer_linked, - gboolean layer_lock_pixels, + gboolean layer_lock_content, gboolean layer_lock_position, gboolean layer_lock_alpha, gboolean rename_text_layer, @@ -53,6 +53,11 @@ GtkWidget * layer_options_dialog_new (GimpImage *image, GimpLayerModeEffects layer_mode, gdouble layer_opacity, GimpFillType layer_fill_type, + gboolean layer_visible, + gboolean layer_linked, + gboolean layer_lock_content, + gboolean layer_lock_position, + gboolean layer_lock_alpha, GimpLayerOptionsCallback callback, gpointer user_data); diff --git a/app/dialogs/vectors-options-dialog.c b/app/dialogs/vectors-options-dialog.c index b1057b69c0..4af580dda9 100644 --- a/app/dialogs/vectors-options-dialog.c +++ b/app/dialogs/vectors-options-dialog.c @@ -17,8 +17,6 @@ #include "config.h" -#include - #include #include @@ -31,8 +29,7 @@ #include "vectors/gimpvectors.h" -#include "widgets/gimpviewabledialog.h" - +#include "item-options-dialog.h" #include "vectors-options-dialog.h" #include "gimp-intl.h" @@ -42,21 +39,24 @@ typedef struct _VectorsOptionsDialog VectorsOptionsDialog; struct _VectorsOptionsDialog { - GimpImage *image; - GimpVectors *vectors; GimpVectorsOptionsCallback callback; gpointer user_data; - - GtkWidget *name_entry; }; /* local function prototypes */ -static void vectors_options_dialog_response (GtkWidget *dialog, - gint response_id, - VectorsOptionsDialog *private); static void vectors_options_dialog_free (VectorsOptionsDialog *private); +static void vectors_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data); /* public functions */ @@ -72,15 +72,15 @@ vectors_options_dialog_new (GimpImage *image, const gchar *desc, const gchar *help_id, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + gboolean vectors_lock_content, + gboolean vectors_lock_position, GimpVectorsOptionsCallback callback, gpointer user_data) { VectorsOptionsDialog *private; GtkWidget *dialog; - GimpViewable *viewable; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *table; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors), NULL); @@ -95,90 +95,58 @@ vectors_options_dialog_new (GimpImage *image, private = g_slice_new0 (VectorsOptionsDialog); - private->image = image; - private->vectors = vectors; private->callback = callback; private->user_data = user_data; - if (vectors) - viewable = GIMP_VIEWABLE (vectors); - else - viewable = GIMP_VIEWABLE (image); - - dialog = gimp_viewable_dialog_new (viewable, context, - title, role, icon_name, desc, - parent, - gimp_standard_help_func, - help_id, - - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - - NULL); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); + dialog = item_options_dialog_new (image, GIMP_ITEM (vectors), context, + parent, title, role, + icon_name, desc, help_id, + _("Path _name:"), + GIMP_STOCK_TOOL_PATH, + _("Lock path _strokes"), + _("Lock path _position"), + vectors_name, + vectors_visible, + vectors_linked, + vectors_lock_content, + vectors_lock_position, + vectors_options_dialog_callback, + private); g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) vectors_options_dialog_free, private); - g_signal_connect (dialog, "response", - G_CALLBACK (vectors_options_dialog_response), - private); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - hbox, TRUE, TRUE, 0); - gtk_widget_show (hbox); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - table = gtk_table_new (1, 2, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), 6); - gtk_table_set_row_spacings (GTK_TABLE (table), 6); - gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - gtk_widget_show (table); - - private->name_entry = gtk_entry_new (); - gtk_widget_set_size_request (private->name_entry, 150, -1); - gtk_entry_set_activates_default (GTK_ENTRY (private->name_entry), TRUE); - gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, - _("Path name:"), 0.0, 0.5, - private->name_entry, 1, FALSE); - - gtk_entry_set_text (GTK_ENTRY (private->name_entry), vectors_name); - return dialog; } -static void -vectors_options_dialog_response (GtkWidget *dialog, - gint response_id, - VectorsOptionsDialog *private) -{ - if (response_id == GTK_RESPONSE_OK) - { - const gchar *name = gtk_entry_get_text (GTK_ENTRY (private->name_entry)); - - private->callback (dialog, - private->image, - private->vectors, - name, - private->user_data); - } - else - { - gtk_widget_destroy (dialog); - } -} - static void vectors_options_dialog_free (VectorsOptionsDialog *private) { g_slice_free (VectorsOptionsDialog, private); } + +static void +vectors_options_dialog_callback (GtkWidget *dialog, + GimpImage *image, + GimpItem *item, + GimpContext *context, + const gchar *item_name, + gboolean item_visible, + gboolean item_linked, + gboolean item_lock_content, + gboolean item_lock_position, + gpointer user_data) +{ + VectorsOptionsDialog *private = user_data; + + private->callback (dialog, + image, + GIMP_VECTORS (item), + context, + item_name, + item_visible, + item_linked, + item_lock_content, + item_lock_position, + private->user_data); +} diff --git a/app/dialogs/vectors-options-dialog.h b/app/dialogs/vectors-options-dialog.h index db8012e84b..1c6a213dad 100644 --- a/app/dialogs/vectors-options-dialog.h +++ b/app/dialogs/vectors-options-dialog.h @@ -22,7 +22,12 @@ typedef void (* GimpVectorsOptionsCallback) (GtkWidget *dialog, GimpImage *image, GimpVectors *vectors, + GimpContext *context, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + gboolean vectors_lock_content, + gboolean vectors_lock_position, gpointer user_data); @@ -36,6 +41,10 @@ GtkWidget * vectors_options_dialog_new (GimpImage *image, const gchar *desc, const gchar *help_id, const gchar *vectors_name, + gboolean vectors_visible, + gboolean vectors_linked, + gboolean vectors_lock_content, + gboolean vectors_lock_position, GimpVectorsOptionsCallback callback, gpointer user_data); diff --git a/po/POTFILES.in b/po/POTFILES.in index 630e3ab03d..5d72d07b34 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -212,6 +212,7 @@ app/dialogs/image-new-dialog.c app/dialogs/image-properties-dialog.c app/dialogs/image-scale-dialog.c app/dialogs/input-devices-dialog.c +app/dialogs/item-options-dialog.c app/dialogs/keyboard-shortcuts-dialog.c app/dialogs/layer-add-mask-dialog.c app/dialogs/layer-options-dialog.c