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
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/ini_file.h"
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/ui_context.h"
|
2013-10-15 06:58:11 +08:00
|
|
|
#include "base/path.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-09-23 03:33:49 +08:00
|
|
|
#include "duplicate_sprite.xml.h"
|
2014-08-11 17:55:51 +08:00
|
|
|
|
2012-07-10 04:36:45 +08:00
|
|
|
#include <cstdio>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-06-18 09:02:54 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace ui;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class DuplicateSpriteCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
DuplicateSpriteCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new DuplicateSpriteCommand(*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
|
|
|
};
|
|
|
|
|
|
|
|
DuplicateSpriteCommand::DuplicateSpriteCommand()
|
|
|
|
: Command("DuplicateSprite",
|
|
|
|
"Duplicate Sprite",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DuplicateSpriteCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsReadable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DuplicateSpriteCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Document* document = reader.document();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-11 17:55:51 +08:00
|
|
|
// Load the window widget
|
|
|
|
app::gen::DuplicateSprite window;
|
2014-07-29 11:53:24 +08:00
|
|
|
std::string fn = document->filename();
|
|
|
|
std::string ext = base::get_file_extension(fn);
|
2014-08-11 17:55:51 +08:00
|
|
|
window.srcName()->setText(base::get_file_name(fn));
|
|
|
|
window.dstName()->setText(base::get_file_title(fn) +
|
|
|
|
" Copy" + (!ext.empty() ? "." + ext: ""));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (get_config_bool("DuplicateSprite", "Flatten", false))
|
2014-08-11 17:55:51 +08:00
|
|
|
window.flatten()->setSelected(true);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
// Open the window
|
2014-08-11 17:55:51 +08:00
|
|
|
window.openWindowInForeground();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-11 17:55:51 +08:00
|
|
|
if (window.getKiller() == window.ok()) {
|
|
|
|
set_config_bool("DuplicateSprite", "Flatten", window.flatten()->isSelected());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
// Make a copy of the document
|
2012-01-06 06:45:03 +08:00
|
|
|
Document* docCopy;
|
2014-08-11 17:55:51 +08:00
|
|
|
if (window.flatten()->isSelected())
|
2012-01-06 06:45:03 +08:00
|
|
|
docCopy = document->duplicate(DuplicateWithFlattenLayers);
|
|
|
|
else
|
|
|
|
docCopy = document->duplicate(DuplicateExactCopy);
|
|
|
|
|
2014-08-11 17:55:51 +08:00
|
|
|
docCopy->setFilename(window.dstName()->getText().c_str());
|
2014-07-29 11:53:24 +08:00
|
|
|
docCopy->setContext(context);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createDuplicateSpriteCommand()
|
|
|
|
{
|
|
|
|
return new DuplicateSpriteCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|