File indexing completed on 2024-12-22 04:10:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_deselect_global_selection_command.h"
0008 
0009 #include <klocalizedstring.h>
0010 
0011 #include "kis_image.h"
0012 #include "kis_group_layer.h"
0013 #include "kis_selection_mask.h"
0014 #include "KisImageGlobalSelectionManagementInterface.h"
0015 #include "KisChangeDeselectedMaskCommand.h"
0016 #include "kis_image_layer_remove_command.h"
0017 #include "KisNotifySelectionChangedCommand.h"
0018 
0019 
0020 KisDeselectGlobalSelectionCommand::KisDeselectGlobalSelectionCommand(KisImageWSP image, KUndo2Command * parent)
0021     : KisCommandUtils::AggregateCommand(kundo2_i18n("Deselect"), parent)
0022     , m_image(image)
0023 {
0024 }
0025 
0026 KisDeselectGlobalSelectionCommand::~KisDeselectGlobalSelectionCommand()
0027 {
0028 }
0029 
0030 void KisDeselectGlobalSelectionCommand::populateChildCommands()
0031 {
0032     KisImageSP image = m_image.toStrongRef();
0033     KIS_SAFE_ASSERT_RECOVER_RETURN(image);
0034 
0035     KisSelectionMaskSP selectionMask = image->rootLayer()->selectionMask();
0036     if (selectionMask) {
0037         addCommand(new KisNotifySelectionChangedCommand(image, KisNotifySelectionChangedCommand::INITIALIZING));
0038         addCommand(new KisChangeDeselectedMaskCommand(image, selectionMask));
0039         addCommand(new KisImageLayerRemoveCommand(image, selectionMask, false, false));
0040         addCommand(new KisNotifySelectionChangedCommand(image, KisNotifySelectionChangedCommand::FINALIZING));
0041     }
0042 }