2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
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-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"
|
2016-11-02 06:14:05 +08:00
|
|
|
#include "base/fs.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()
|
2017-12-02 02:10:21 +08:00
|
|
|
: Command(CommandId::DuplicateSprite(), CmdUIOnlyFlag)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-12-05 01:54:15 +08:00
|
|
|
if (window.closer() == window.ok()) {
|
2014-08-11 17:55:51 +08:00
|
|
|
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);
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
docCopy->setFilename(window.dstName()->text().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
|