2013-08-09 00:01:20 +00:00
|
|
|
/* Aseprite
|
2014-07-29 03:53:24 +00:00
|
|
|
* Copyright (C) 2001-2014 David Capello
|
2012-01-05 22:45:03 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-05 22:45:03 +00:00
|
|
|
#include "config.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#endif
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
2012-06-16 02:37:59 +00:00
|
|
|
#include "app/find_widget.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/ini_file.h"
|
2012-06-16 02:37:59 +00:00
|
|
|
#include "app/load_widget.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/ui_context.h"
|
2013-10-14 22:58:11 +00:00
|
|
|
#include "base/path.h"
|
2012-01-05 22:45:03 +00:00
|
|
|
#include "raster/sprite.h"
|
2013-08-06 00:20:19 +00:00
|
|
|
#include "ui/ui.h"
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2014-08-11 09:55:51 +00:00
|
|
|
#include "generated_duplicate_sprite.h"
|
|
|
|
|
2012-07-09 20:36:45 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
namespace app {
|
2012-06-18 01:02:54 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
using namespace ui;
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-08-06 00:20:19 +00:00
|
|
|
class DuplicateSpriteCommand : public Command {
|
2012-01-05 22:45:03 +00:00
|
|
|
public:
|
|
|
|
DuplicateSpriteCommand();
|
2014-03-29 20:08:40 +00:00
|
|
|
Command* clone() const OVERRIDE { return new DuplicateSpriteCommand(*this); }
|
2012-01-05 22:45:03 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
DuplicateSpriteCommand::DuplicateSpriteCommand()
|
|
|
|
: Command("DuplicateSprite",
|
|
|
|
"Duplicate Sprite",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DuplicateSpriteCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsReadable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DuplicateSpriteCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-11 23:29:45 +00:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Document* document = reader.document();
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2014-08-11 09:55:51 +00:00
|
|
|
// Load the window widget
|
|
|
|
app::gen::DuplicateSprite window;
|
2014-07-29 03:53:24 +00:00
|
|
|
std::string fn = document->filename();
|
|
|
|
std::string ext = base::get_file_extension(fn);
|
2014-08-11 09:55:51 +00:00
|
|
|
window.srcName()->setText(base::get_file_name(fn));
|
|
|
|
window.dstName()->setText(base::get_file_title(fn) +
|
|
|
|
" Copy" + (!ext.empty() ? "." + ext: ""));
|
2012-01-05 22:45:03 +00:00
|
|
|
|
|
|
|
if (get_config_bool("DuplicateSprite", "Flatten", false))
|
2014-08-11 09:55:51 +00:00
|
|
|
window.flatten()->setSelected(true);
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-03-11 23:29:45 +00:00
|
|
|
// Open the window
|
2014-08-11 09:55:51 +00:00
|
|
|
window.openWindowInForeground();
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2014-08-11 09:55:51 +00:00
|
|
|
if (window.getKiller() == window.ok()) {
|
|
|
|
set_config_bool("DuplicateSprite", "Flatten", window.flatten()->isSelected());
|
2012-01-05 22:45:03 +00:00
|
|
|
|
2013-03-11 23:29:45 +00:00
|
|
|
// Make a copy of the document
|
2012-01-05 22:45:03 +00:00
|
|
|
Document* docCopy;
|
2014-08-11 09:55:51 +00:00
|
|
|
if (window.flatten()->isSelected())
|
2012-01-05 22:45:03 +00:00
|
|
|
docCopy = document->duplicate(DuplicateWithFlattenLayers);
|
|
|
|
else
|
|
|
|
docCopy = document->duplicate(DuplicateExactCopy);
|
|
|
|
|
2014-08-11 09:55:51 +00:00
|
|
|
docCopy->setFilename(window.dstName()->getText().c_str());
|
2014-07-29 03:53:24 +00:00
|
|
|
docCopy->setContext(context);
|
2012-01-05 22:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createDuplicateSpriteCommand()
|
|
|
|
{
|
|
|
|
return new DuplicateSpriteCommand;
|
|
|
|
}
|
2013-08-06 00:20:19 +00:00
|
|
|
|
|
|
|
} // namespace app
|