2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// 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-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
|
|
|
|
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"
|
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:
|
2014-05-02 22:55:44 +08:00
|
|
|
void onLoadParams(Params* params);
|
2012-02-06 11:17:42 +08:00
|
|
|
void onExecute(Context* context);
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-02 22:55:44 +08:00
|
|
|
void CancelCommand::onLoadParams(Params* params)
|
|
|
|
{
|
|
|
|
std::string type = params->get("type");
|
|
|
|
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:
|
|
|
|
if (context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasVisibleMask)) {
|
|
|
|
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::DeselectMask);
|
|
|
|
context->executeCommand(cmd);
|
|
|
|
}
|
|
|
|
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
|