diff --git a/src/commands/cmd_deselect_mask.cpp b/src/commands/cmd_deselect_mask.cpp index 4112dd7bf..62bf959b0 100644 --- a/src/commands/cmd_deselect_mask.cpp +++ b/src/commands/cmd_deselect_mask.cpp @@ -22,8 +22,8 @@ #include "modules/gui.h" #include "raster/mask.h" #include "raster/sprite.h" -#include "raster/undo.h" #include "sprite_wrappers.h" +#include "undoable.h" ////////////////////////////////////////////////////////////////////// // deselect_mask @@ -46,38 +46,20 @@ DeselectMaskCommand::DeselectMaskCommand() { } -bool DeselectMaskCommand::enabled(Context* context) -{ - const CurrentSpriteReader sprite(context); - return sprite && !sprite->mask->is_empty(); -} - -void DeselectMaskCommand::execute(Context* context) +bool DeselectMaskCommand::enabled(Context* context) +{ + const CurrentSpriteReader sprite(context); + return sprite && !sprite->mask->is_empty(); +} + +void DeselectMaskCommand::execute(Context* context) { CurrentSpriteWriter sprite(context); - Mask *mask; - - /* destroy the *deselected* mask */ - mask = sprite_request_mask(sprite, "*deselected*"); - if (mask) { - sprite_remove_mask(sprite, mask); - mask_free(mask); + { + Undoable undoable(sprite, "Mask Deselection"); + undoable.deselect_mask(); + undoable.commit(); } - - /* save the selection in the repository */ - mask = mask_new_copy(sprite->mask); - mask_set_name(mask, "*deselected*"); - sprite_add_mask(sprite, mask); - - /* undo */ - if (undo_is_enabled(sprite->undo)) { - undo_set_label(sprite->undo, "Mask Deselection"); - undo_set_mask(sprite->undo, sprite); - } - - /* deselect the mask */ - mask_none(sprite->mask); - sprite_generate_mask_boundaries(sprite); update_screen_for_sprite(sprite); } diff --git a/src/undoable.cpp b/src/undoable.cpp index 5ee885105..4777336d3 100644 --- a/src/undoable.cpp +++ b/src/undoable.cpp @@ -1051,3 +1051,24 @@ void Undoable::set_mask_position(int x, int y) m_sprite->mask->x = x; m_sprite->mask->y = y; } + +void Undoable::deselect_mask() +{ + // Destroy the *deselected* mask + Mask* mask = sprite_request_mask(m_sprite, "*deselected*"); + if (mask) { + sprite_remove_mask(m_sprite, mask); + mask_free(mask); + } + + // Save the selection in the repository + mask = mask_new_copy(m_sprite->mask); + mask_set_name(mask, "*deselected*"); + sprite_add_mask(m_sprite, mask); + + if (undo_is_enabled(m_sprite->undo)) + undo_set_mask(m_sprite->undo, m_sprite); + + /// Deselect the mask + mask_none(m_sprite->mask); +} diff --git a/src/undoable.h b/src/undoable.h index 1c71d6b30..3ecd6a6e8 100644 --- a/src/undoable.h +++ b/src/undoable.h @@ -102,6 +102,7 @@ public: // for mask void copy_to_current_mask(Mask* mask); void set_mask_position(int x, int y); + void deselect_mask(); };