2015-02-12 15:16:25 +00:00
|
|
|
// Aseprite
|
2016-04-22 16:19:06 +00:00
|
|
|
// Copyright (C) 2001-2016 David Capello
|
2015-02-12 15:16:25 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
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"
|
|
|
|
#include "app/document_api.h"
|
|
|
|
#include "app/modules/gui.h"
|
2013-12-15 23:21:31 +00:00
|
|
|
#include "app/ui/timeline.h"
|
2015-01-19 01:05:33 +00:00
|
|
|
#include "app/transaction.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();
|
2014-08-15 02:07:47 +00:00
|
|
|
Command* clone() const override { return new RemoveFrameCommand(*this); }
|
2012-01-05 22:45:03 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
: Command("RemoveFrame",
|
|
|
|
"Remove Frame",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemoveFrameCommand::onEnabled(Context* context)
|
|
|
|
{
|
2013-03-11 23:29:45 +00:00
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.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);
|
|
|
|
Document* document(writer.document());
|
|
|
|
Sprite* sprite(writer.sprite());
|
2012-01-05 22:45:03 +00:00
|
|
|
{
|
2015-01-19 01:05:33 +00:00
|
|
|
Transaction transaction(writer.context(), "Remove Frame");
|
|
|
|
DocumentApi api = document->getApi(transaction);
|
2013-12-15 23:21:31 +00:00
|
|
|
|
2015-04-20 19:27:09 +00:00
|
|
|
// TODO the range of selected frames should be in doc::Site.
|
2016-04-22 16:19:06 +00:00
|
|
|
auto range = App::instance()->timeline()->range();
|
2013-12-15 23:21:31 +00:00
|
|
|
if (range.enabled()) {
|
2014-12-28 23:39:11 +00:00
|
|
|
for (frame_t frame = range.frameEnd(),
|
|
|
|
begin = range.frameBegin()-1;
|
2013-12-15 23:21:31 +00:00
|
|
|
frame != begin;
|
2014-12-28 23:39:11 +00:00
|
|
|
--frame) {
|
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
|
|
|
}
|
|
|
|
|
2015-01-19 01:05:33 +00:00
|
|
|
transaction.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
|