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-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
|
#include "app/console.h"
|
|
|
|
|
#include "app/context_access.h"
|
|
|
|
|
#include "app/document_api.h"
|
|
|
|
|
#include "app/document_undo.h"
|
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
|
#include "app/ui/editor/editor.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/layer.h"
|
|
|
|
|
#include "doc/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class DuplicateLayerCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
|
DuplicateLayerCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new DuplicateLayerCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 03:34:43 +08:00
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DuplicateLayerCommand::DuplicateLayerCommand()
|
|
|
|
|
: Command("DuplicateLayer",
|
|
|
|
|
"Duplicate Layer",
|
|
|
|
|
CmdRecordableFlag)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DuplicateLayerCommand::onEnabled(Context* context)
|
|
|
|
|
{
|
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
|
ContextFlags::HasActiveLayer |
|
|
|
|
|
ContextFlags::ActiveLayerIsImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DuplicateLayerCommand::onExecute(Context* context)
|
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
|
|
|
|
Document* document = writer.document();
|
2014-04-10 08:56:06 +08:00
|
|
|
|
|
|
|
|
{
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Layer Duplication");
|
2014-04-10 08:56:06 +08:00
|
|
|
LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer());
|
2015-01-19 09:05:33 +08:00
|
|
|
DocumentApi api = document->getApi(transaction);
|
2014-08-08 07:19:31 +08:00
|
|
|
api.duplicateLayerAfter(sourceLayer, sourceLayer);
|
2015-01-19 09:05:33 +08:00
|
|
|
transaction.commit();
|
2014-04-10 08:56:06 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
update_screen_for_document(document);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Command* CommandFactory::createDuplicateLayerCommand()
|
|
|
|
|
{
|
|
|
|
|
return new DuplicateLayerCommand;
|
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
} // namespace app
|