2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2017-11-30 22:57:18 +08:00
|
|
|
// Copyright (C) 2001-2015, 2017 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.
|
2012-02-06 11:17:42 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-02-06 11:17:42 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-02-06 11:17:42 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
2012-02-06 11:17:42 +08:00
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
#include "app/app.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/commands.h"
|
2014-05-02 22:55:44 +08:00
|
|
|
#include "app/commands/params.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context.h"
|
2015-05-10 06:55:33 +08:00
|
|
|
#include "app/ui/input_chain.h"
|
2012-02-06 11:17:42 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
class CancelCommand : public Command {
|
2012-02-06 11:17:42 +08:00
|
|
|
public:
|
2014-05-02 22:55:44 +08:00
|
|
|
enum Type {
|
|
|
|
NoOp,
|
|
|
|
All,
|
|
|
|
};
|
|
|
|
|
2012-02-06 11:17:42 +08:00
|
|
|
CancelCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new CancelCommand(*this); }
|
2012-02-06 11:17:42 +08:00
|
|
|
|
|
|
|
protected:
|
2017-12-01 01:51:13 +08:00
|
|
|
bool onNeedsParams() const override { return true; }
|
2015-03-12 02:40:22 +08:00
|
|
|
void onLoadParams(const Params& params) override;
|
|
|
|
void onExecute(Context* context) override;
|
2014-05-02 22:55:44 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Type m_type;
|
2012-02-06 11:17:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CancelCommand::CancelCommand()
|
|
|
|
: Command("Cancel",
|
2014-10-29 22:58:03 +08:00
|
|
|
"Cancel Current Operation",
|
2012-02-06 11:17:42 +08:00
|
|
|
CmdUIOnlyFlag)
|
2014-05-02 22:55:44 +08:00
|
|
|
, m_type(NoOp)
|
2012-02-06 11:17:42 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-12 02:40:22 +08:00
|
|
|
void CancelCommand::onLoadParams(const Params& params)
|
2014-05-02 22:55:44 +08:00
|
|
|
{
|
2015-03-12 02:40:22 +08:00
|
|
|
std::string type = params.get("type");
|
2014-05-02 22:55:44 +08:00
|
|
|
if (type == "noop") m_type = NoOp;
|
|
|
|
else if (type == "all") m_type = All;
|
|
|
|
}
|
|
|
|
|
2012-02-06 11:17:42 +08:00
|
|
|
void CancelCommand::onExecute(Context* context)
|
|
|
|
{
|
2014-05-02 22:55:44 +08:00
|
|
|
switch (m_type) {
|
|
|
|
|
|
|
|
case NoOp:
|
|
|
|
// Do nothing.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case All:
|
2015-05-10 06:55:33 +08:00
|
|
|
// TODO should the ContextBar be a InputChainElement to intercept onCancel()?
|
2015-04-27 11:08:04 +08:00
|
|
|
// Discard brush
|
|
|
|
{
|
2017-11-30 22:57:18 +08:00
|
|
|
Command* discardBrush = Commands::instance()->byId(CommandId::DiscardBrush);
|
2015-04-27 11:08:04 +08:00
|
|
|
context->executeCommand(discardBrush);
|
|
|
|
}
|
|
|
|
|
2015-05-10 06:55:33 +08:00
|
|
|
App::instance()->inputChain().cancel(context);
|
2014-05-02 22:55:44 +08:00
|
|
|
break;
|
2012-02-06 11:17:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createCancelCommand()
|
|
|
|
{
|
|
|
|
return new CancelCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|