GimpLayer * gimp_image_merge_down (GimpImage *image, GimpLayer *current_layer, GimpContext *context, GimpMergeType merge_type, GError **error) { GimpLayer *layer; GList *list; GList *layer_list = NULL; GSList *merge_list = NULL; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_LAYER (current_layer), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (current_layer)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); for (list = gimp_item_get_container_iter (GIMP_ITEM (current_layer)); list; list = g_list_next (list)) { layer = list->data; if (layer == current_layer) break; } for (layer_list = g_list_next (list); layer_list; layer_list = g_list_next (layer_list)) { layer = layer_list->data; if (gimp_item_get_visible (GIMP_ITEM (layer))) { if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) { g_set_error_literal (error, 0, 0, _("Cannot merge down to a layer group.")); return NULL; } if (gimp_item_is_content_locked (GIMP_ITEM (layer))) { g_set_error_literal (error, 0, 0, _("The layer to merge down to is locked.")); return NULL; } merge_list = g_slist_append (NULL, layer); break; } } if (! merge_list) { g_set_error_literal (error, 0, 0, _("There is no visible layer to merge down to.")); return NULL; } merge_list = g_slist_prepend (merge_list, current_layer); gimp_set_busy (image->gimp); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE, C_("undo-type", "Merge Down")); layer = gimp_image_merge_layers (image, gimp_item_get_container (GIMP_ITEM (current_layer)), merge_list, context, merge_type); g_slist_free (merge_list); gimp_image_undo_group_end (image); gimp_unset_busy (image->gimp); return layer; }
void layers_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpLayer *layer = NULL; GimpLayerMask *mask = NULL; /* layer mask */ gboolean fs = FALSE; /* floating sel */ gboolean ac = FALSE; /* active channel */ gboolean sel = FALSE; gboolean alpha = FALSE; /* alpha channel present */ gboolean indexed = FALSE; /* is indexed */ gboolean lock_alpha = FALSE; gboolean can_lock_alpha = FALSE; gboolean text_layer = FALSE; gboolean writable = FALSE; gboolean children = FALSE; GList *next = NULL; GList *next_visible = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_get_floating_selection (image) != NULL); ac = (gimp_image_get_active_channel (image) != NULL); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); indexed = (gimp_image_base_type (image) == GIMP_INDEXED); layer = gimp_image_get_active_layer (image); if (layer) { GList *layer_list; GList *list; mask = gimp_layer_get_mask (layer); lock_alpha = gimp_layer_get_lock_alpha (layer); can_lock_alpha = gimp_layer_can_lock_alpha (layer); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); writable = ! gimp_item_is_content_locked (GIMP_ITEM (layer)); if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) children = TRUE; layer_list = gimp_item_get_container_iter (GIMP_ITEM (layer)); list = g_list_find (layer_list, layer); if (list) { prev = g_list_previous (list); next = g_list_next (list); for (next_visible = next; next_visible; next_visible = g_list_next (next_visible)) { if (gimp_item_get_visible (next_visible->data)) { /* "next_visible" is actually "next_visible" and * "writable" and "not group" */ if (gimp_item_is_content_locked (next_visible->data) || gimp_viewable_get_children (next_visible->data)) next_visible = NULL; break; } } } text_layer = gimp_item_is_text_layer (GIMP_ITEM (layer)); } } #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_LABEL(action,label) \ gimp_action_group_set_action_label (group, action, label) SET_VISIBLE ("layers-text-tool", text_layer && !ac); SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac); if (layer && gimp_layer_is_floating_sel (layer)) { SET_LABEL ("layers-new", C_("layers-action", "To _New Layer")); SET_LABEL ("layers-new-last-values", C_("layers-action", "To _New Layer")); } else { SET_LABEL ("layers-new", C_("layers-action", "_New Layer...")); SET_LABEL ("layers-new-last-values", C_("layers-action", "_New Layer")); } SET_SENSITIVE ("layers-new", image); SET_SENSITIVE ("layers-new-last-values", image); SET_SENSITIVE ("layers-new-from-visible", image); SET_SENSITIVE ("layers-new-group", image && !indexed); SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac); SET_SENSITIVE ("layers-delete", layer && !ac); SET_SENSITIVE ("layers-select-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-next", layer && !fs && !ac && next); SET_SENSITIVE ("layers-raise", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-raise-to-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-lower", layer && !fs && !ac && next); SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-anchor", layer && fs && !ac); SET_SENSITIVE ("layers-merge-down", layer && !fs && !ac && next_visible); SET_VISIBLE ("layers-merge-group", children); SET_SENSITIVE ("layers-merge-group", layer && !fs && !ac && children); SET_SENSITIVE ("layers-merge-layers", layer && !fs && !ac); SET_SENSITIVE ("layers-flatten-image", layer && !fs && !ac); SET_VISIBLE ("layers-text-discard", text_layer && !ac); SET_VISIBLE ("layers-text-to-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-along-vectors", text_layer && !ac); SET_SENSITIVE ("layers-resize", writable && !ac); SET_SENSITIVE ("layers-resize-to-image", writable && !ac); SET_SENSITIVE ("layers-scale", writable && !ac); SET_SENSITIVE ("layers-crop", writable && sel); SET_SENSITIVE ("layers-alpha-add", writable && !children && !fs && !alpha); SET_SENSITIVE ("layers-alpha-remove", writable && !children && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha); SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_SENSITIVE ("layers-mask-add", layer && !fs && !ac && !mask && !children); SET_SENSITIVE ("layers-mask-apply", writable && !fs && !ac && mask && !children); SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-edit", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-show", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac && mask); SET_ACTIVE ("layers-mask-edit", mask && gimp_layer_mask_get_edit (mask)); SET_ACTIVE ("layers-mask-show", mask && gimp_layer_mask_get_show (mask)); SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask)); SET_SENSITIVE ("layers-mask-selection-replace", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-add", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-subtract", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-alpha-selection-replace", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-add", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-subtract", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac); #undef SET_VISIBLE #undef SET_SENSITIVE #undef SET_ACTIVE #undef SET_LABEL }
void channels_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpChannel *channel = NULL; gboolean fs = FALSE; gboolean component = FALSE; GList *next = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_get_floating_selection (image) != NULL); if (GIMP_IS_COMPONENT_EDITOR (data)) { if (GIMP_COMPONENT_EDITOR (data)->clicked_component != -1) component = TRUE; } else { channel = gimp_image_get_active_channel (image); if (channel) { GList *channel_list; GList *list; channel_list = gimp_item_get_container_iter (GIMP_ITEM (channel)); list = g_list_find (channel_list, channel); if (list) { prev = g_list_previous (list); next = g_list_next (list); } } } } #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) SET_SENSITIVE ("channels-edit-attributes", !fs && channel); SET_SENSITIVE ("channels-new", !fs && image); SET_SENSITIVE ("channels-new-last-values", !fs && image); SET_SENSITIVE ("channels-duplicate", !fs && (channel || component)); SET_SENSITIVE ("channels-delete", !fs && channel); SET_SENSITIVE ("channels-raise", !fs && channel && prev); SET_SENSITIVE ("channels-raise-to-top", !fs && channel && prev); SET_SENSITIVE ("channels-lower", !fs && channel && next); SET_SENSITIVE ("channels-lower-to-bottom", !fs && channel && next); SET_SENSITIVE ("channels-selection-replace", !fs && (channel || component)); SET_SENSITIVE ("channels-selection-add", !fs && (channel || component)); SET_SENSITIVE ("channels-selection-subtract", !fs && (channel || component)); SET_SENSITIVE ("channels-selection-intersect", !fs && (channel || component)); #undef SET_SENSITIVE items_actions_update (group, "channels", GIMP_ITEM (channel)); }
void vectors_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpVectors *vectors = NULL; GimpDrawable *drawable = NULL; gint n_vectors = 0; gboolean mask_empty = TRUE; gboolean visible = FALSE; gboolean linked = FALSE; gboolean locked = FALSE; gboolean can_lock = FALSE; gboolean locked_pos = FALSE; gboolean can_lock_pos = FALSE; gboolean dr_writable = FALSE; gboolean dr_children = FALSE; GList *next = NULL; GList *prev = NULL; if (image) { n_vectors = gimp_image_get_n_vectors (image); mask_empty = gimp_channel_is_empty (gimp_image_get_mask (image)); vectors = gimp_image_get_active_vectors (image); if (vectors) { GimpItem *item = GIMP_ITEM (vectors); GList *vectors_list; GList *list; visible = gimp_item_get_visible (item); linked = gimp_item_get_linked (item); locked = gimp_item_get_lock_content (item); can_lock = gimp_item_can_lock_content (item); locked_pos = gimp_item_get_lock_position (item); can_lock_pos = gimp_item_can_lock_position (item); vectors_list = gimp_item_get_container_iter (item); list = g_list_find (vectors_list, vectors); if (list) { prev = g_list_previous (list); next = g_list_next (list); } } drawable = gimp_image_get_active_drawable (image); if (drawable) { GimpItem *item = GIMP_ITEM (drawable); dr_writable = ! gimp_item_is_content_locked (item); if (gimp_viewable_get_children (GIMP_VIEWABLE (item))) dr_children = TRUE; } } #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) SET_SENSITIVE ("vectors-path-tool", vectors); SET_SENSITIVE ("vectors-edit-attributes", vectors); SET_SENSITIVE ("vectors-new", image); SET_SENSITIVE ("vectors-new-last-values", image); SET_SENSITIVE ("vectors-duplicate", vectors); SET_SENSITIVE ("vectors-delete", vectors); SET_SENSITIVE ("vectors-merge-visible", n_vectors > 1); SET_SENSITIVE ("vectors-raise", vectors && prev); SET_SENSITIVE ("vectors-raise-to-top", vectors && prev); SET_SENSITIVE ("vectors-lower", vectors && next); SET_SENSITIVE ("vectors-lower-to-bottom", vectors && next); SET_SENSITIVE ("vectors-copy", vectors); SET_SENSITIVE ("vectors-paste", image); SET_SENSITIVE ("vectors-export", vectors); SET_SENSITIVE ("vectors-import", image); SET_SENSITIVE ("vectors-visible", vectors); SET_SENSITIVE ("vectors-linked", vectors); SET_SENSITIVE ("vectors-lock-content", can_lock); SET_SENSITIVE ("vectors-lock-position", can_lock_pos); SET_ACTIVE ("vectors-visible", visible); SET_ACTIVE ("vectors-linked", linked); SET_ACTIVE ("vectors-lock-content", locked); SET_ACTIVE ("vectors-lock-position", locked_pos); SET_SENSITIVE ("vectors-selection-to-vectors", image && !mask_empty); SET_SENSITIVE ("vectors-selection-to-vectors-short", image && !mask_empty); SET_SENSITIVE ("vectors-selection-to-vectors-advanced", image && !mask_empty); SET_SENSITIVE ("vectors-fill", vectors && dr_writable && !dr_children); SET_SENSITIVE ("vectors-fill-last-values", vectors && dr_writable && !dr_children); SET_SENSITIVE ("vectors-stroke", vectors && dr_writable && !dr_children); SET_SENSITIVE ("vectors-stroke-last-values", vectors && dr_writable && !dr_children); SET_SENSITIVE ("vectors-selection-replace", vectors); SET_SENSITIVE ("vectors-selection-from-vectors", vectors); SET_SENSITIVE ("vectors-selection-add", vectors); SET_SENSITIVE ("vectors-selection-subtract", vectors); SET_SENSITIVE ("vectors-selection-intersect", vectors); #undef SET_SENSITIVE #undef SET_ACTIVE }