aseprite/src/app/commands/cmd_clear_cel.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.1 KiB
C++
Raw Normal View History

2015-02-12 23:16:25 +08:00
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
2015-02-12 23:16:25 +08:00
//
2016-08-27 04:02:58 +08:00
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/app.h"
#include "app/commands/command.h"
#include "app/context_access.h"
2018-07-07 14:07:16 +08:00
#include "app/doc_api.h"
#include "app/i18n/strings.h"
#include "app/modules/gui.h"
#include "app/tx.h"
#include "app/ui/status_bar.h"
#include "doc/cel.h"
#include "doc/layer.h"
namespace app {
class ClearCelCommand : public Command {
public:
ClearCelCommand();
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
ClearCelCommand::ClearCelCommand() : Command(CommandId::ClearCel())
{
}
bool ClearCelCommand::onEnabled(Context* context)
{
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
}
void ClearCelCommand::onExecute(Context* context)
{
ContextWriter writer(context);
2018-07-07 22:54:44 +08:00
Doc* document(writer.document());
bool nonEditableLayers = false;
{
Tx tx(writer, "Clear Cel");
2015-02-12 23:16:25 +08:00
const Site& site = writer.site();
if (site.inTimeline() && !site.selectedLayers().empty() && !site.selectedFrames().empty()) {
for (Layer* layer : site.selectedLayers()) {
if (!layer->isImage())
continue;
if (!layer->isEditableHierarchy()) {
nonEditableLayers = true;
continue;
}
for (frame_t frame : site.selectedFrames().reversed()) {
if (Cel* cel = layer->cel(frame))
document->getApi(tx).clearCel(cel);
}
}
}
else if (writer.cel()) {
if (writer.layer()->isEditableHierarchy())
document->getApi(tx).clearCel(writer.cel());
else
nonEditableLayers = true;
}
tx.commit();
}
if (context->isUIAvailable() && nonEditableLayers)
StatusBar::instance()->showTip(1000, Strings::statusbar_tips_locked_layers());
update_screen_for_document(document);
}
Command* CommandFactory::createClearCelCommand()
{
return new ClearCelCommand;
}
} // namespace app