2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
2020-02-05 20:24:21 +00:00
|
|
|
// Copyright (C) 2020 Igara Studio S.A.
|
2018-08-20 19:00:59 +00:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 15:16:25 +00:00
|
|
|
//
|
2016-08-26 20:02:58 +00:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-05 22:45:03 +00:00
|
|
|
#include "config.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#endif
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-12-15 23:21:31 +00:00
|
|
|
#include "app/app.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
2018-07-07 06:07:16 +00:00
|
|
|
#include "app/doc_api.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/modules/gui.h"
|
2018-08-20 19:00:59 +00:00
|
|
|
#include "app/tx.h"
|
2014-10-21 01:21:31 +00:00
|
|
|
#include "doc/sprite.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "ui/ui.h"
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
namespace app {
|
2015-02-12 15:16:25 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
class RemoveFrameCommand : public Command {
|
2012-01-05 22:45:03 +00:00
|
|
|
public:
|
|
|
|
RemoveFrameCommand();
|
|
|
|
|
|
|
|
protected:
|
2015-09-30 19:34:43 +00:00
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-05 22:45:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RemoveFrameCommand::RemoveFrameCommand()
|
2017-12-01 18:10:21 +00:00
|
|
|
: Command(CommandId::RemoveFrame(), CmdRecordableFlag)
|
2012-01-05 22:45:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemoveFrameCommand::onEnabled(Context* context)
|
|
|
|
{
|
2020-02-05 20:24:21 +00:00
|
|
|
if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite(reader.sprite());
|
2012-01-05 22:45:03 +00:00
|
|
|
return
|
|
|
|
sprite &&
|
2014-07-30 04:28:15 +00:00
|
|
|
sprite->totalFrames() > 1;
|
2012-01-05 22:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveFrameCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-11 23:29:45 +00:00
|
|
|
ContextWriter writer(context);
|
2018-07-07 14:54:44 +00:00
|
|
|
Doc* document(writer.document());
|
2013-03-11 23:29:45 +00:00
|
|
|
Sprite* sprite(writer.sprite());
|
2012-01-05 22:45:03 +00:00
|
|
|
{
|
2018-08-20 19:00:59 +00:00
|
|
|
Tx tx(writer.context(), "Remove Frame");
|
|
|
|
DocApi api = document->getApi(tx);
|
2016-06-14 17:17:52 +00:00
|
|
|
const Site* site = writer.site();
|
|
|
|
if (site->inTimeline() &&
|
|
|
|
!site->selectedFrames().empty()) {
|
|
|
|
for (frame_t frame : site->selectedFrames().reversed()) {
|
2015-01-19 01:05:33 +00:00
|
|
|
api.removeFrame(sprite, frame);
|
2013-12-15 23:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-01-19 01:05:33 +00:00
|
|
|
api.removeFrame(sprite, writer.frame());
|
2013-12-15 23:21:31 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 19:00:59 +00:00
|
|
|
tx.commit();
|
2012-01-05 22:45:03 +00:00
|
|
|
}
|
|
|
|
update_screen_for_document(document);
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createRemoveFrameCommand()
|
|
|
|
{
|
|
|
|
return new RemoveFrameCommand;
|
|
|
|
}
|
2013-08-06 00:20:19 +00:00
|
|
|
|
|
|
|
} // namespace app
|