2012-01-06 04:12:57 +00:00
|
|
|
/* ASEPRITE
|
2012-01-06 03:52:11 +00:00
|
|
|
* Copyright (C) 2001-2012 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "app.h"
|
2012-06-16 02:37:59 +00:00
|
|
|
#include "app/find_widget.h"
|
|
|
|
#include "app/load_widget.h"
|
2012-01-05 22:45:03 +00:00
|
|
|
#include "commands/command.h"
|
|
|
|
#include "document_wrappers.h"
|
|
|
|
#include "ini_file.h"
|
|
|
|
#include "modules/editors.h"
|
|
|
|
#include "raster/sprite.h"
|
2012-06-18 01:49:58 +00:00
|
|
|
#include "ui/gui.h"
|
2012-01-05 22:45:03 +00:00
|
|
|
#include "ui_context.h"
|
|
|
|
|
2012-07-09 20:36:45 +00:00
|
|
|
#include <allegro.h>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2012-06-18 01:02:54 +00:00
|
|
|
using namespace ui;
|
|
|
|
|
2012-01-05 22:45:03 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// duplicate_sprite
|
|
|
|
|
|
|
|
class DuplicateSpriteCommand : public Command
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DuplicateSpriteCommand();
|
|
|
|
Command* clone() { return new DuplicateSpriteCommand(*this); }
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-06-16 03:05:01 +00:00
|
|
|
Widget* src_name, *dst_name, *flatten;
|
2012-01-05 22:45:03 +00:00
|
|
|
const ActiveDocumentReader document(context);
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
/* load the window widget */
|
2012-07-09 02:24:42 +00:00
|
|
|
UniquePtr<Window> window(app::load_widget<Window>("duplicate_sprite.xml", "duplicate_sprite"));
|
2012-01-05 22:45:03 +00:00
|
|
|
|
|
|
|
src_name = window->findChild("src_name");
|
|
|
|
dst_name = window->findChild("dst_name");
|
|
|
|
flatten = window->findChild("flatten");
|
|
|
|
|
|
|
|
src_name->setText(get_filename(document->getFilename()));
|
|
|
|
|
2012-07-09 20:36:45 +00:00
|
|
|
std::sprintf(buf, "%s Copy", document->getFilename());
|
2012-01-05 22:45:03 +00:00
|
|
|
dst_name->setText(buf);
|
|
|
|
|
|
|
|
if (get_config_bool("DuplicateSprite", "Flatten", false))
|
|
|
|
flatten->setSelected(true);
|
|
|
|
|
|
|
|
/* open the window */
|
2012-07-09 02:24:42 +00:00
|
|
|
window->openWindowInForeground();
|
2012-01-05 22:45:03 +00:00
|
|
|
|
|
|
|
if (window->get_killer() == window->findChild("ok")) {
|
|
|
|
set_config_bool("DuplicateSprite", "Flatten", flatten->isSelected());
|
|
|
|
|
|
|
|
// make a copy of the document
|
|
|
|
Document* docCopy;
|
|
|
|
if (flatten->isSelected())
|
|
|
|
docCopy = document->duplicate(DuplicateWithFlattenLayers);
|
|
|
|
else
|
|
|
|
docCopy = document->duplicate(DuplicateExactCopy);
|
|
|
|
|
|
|
|
docCopy->setFilename(dst_name->getText());
|
|
|
|
|
|
|
|
context->addDocument(docCopy);
|
|
|
|
set_document_in_more_reliable_editor(docCopy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// CommandFactory
|
|
|
|
|
|
|
|
Command* CommandFactory::createDuplicateSpriteCommand()
|
|
|
|
{
|
|
|
|
return new DuplicateSpriteCommand;
|
|
|
|
}
|