2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2024-08-29 20:57:17 +08:00
|
|
|
// Copyright (C) 2024 Igara Studio S.A.
|
2017-12-01 10:41:45 +08:00
|
|
|
// Copyright (C) 2001-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();
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2025-08-06 02:59:31 +08:00
|
|
|
CancelCommand::CancelCommand() : Command(CommandId::Cancel()), 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;
|
2024-08-29 20:57:17 +08:00
|
|
|
// TODO: add specific types for selection/ranges during scripting.
|
|
|
|
else
|
|
|
|
m_type = All;
|
2014-05-02 22:55:44 +08:00
|
|
|
}
|
|
|
|
|
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
|
2024-09-05 03:34:32 +08:00
|
|
|
if (context->isUIAvailable()) {
|
2017-12-02 02:10:21 +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
|