mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Use generated widget app::gen::DuplicateSprite in DuplicateSpriteCommand
This commit is contained in:
parent
7550db81ba
commit
d11900cdef
@ -32,6 +32,8 @@
|
||||
#include "raster/sprite.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#include "generated_duplicate_sprite.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace app {
|
||||
@ -62,39 +64,34 @@ bool DuplicateSpriteCommand::onEnabled(Context* context)
|
||||
|
||||
void DuplicateSpriteCommand::onExecute(Context* context)
|
||||
{
|
||||
Widget* src_name, *dst_name, *flatten;
|
||||
const ContextReader reader(context);
|
||||
const Document* document = reader.document();
|
||||
|
||||
/* load the window widget */
|
||||
base::UniquePtr<Window> window(app::load_widget<Window>("duplicate_sprite.xml", "duplicate_sprite"));
|
||||
|
||||
src_name = window->findChild("src_name");
|
||||
dst_name = window->findChild("dst_name");
|
||||
flatten = window->findChild("flatten");
|
||||
|
||||
// Load the window widget
|
||||
app::gen::DuplicateSprite window;
|
||||
std::string fn = document->filename();
|
||||
std::string ext = base::get_file_extension(fn);
|
||||
src_name->setText(base::get_file_name(fn));
|
||||
dst_name->setText(base::get_file_title(fn) + " Copy" + (!ext.empty() ? "." + ext: ""));
|
||||
window.srcName()->setText(base::get_file_name(fn));
|
||||
window.dstName()->setText(base::get_file_title(fn) +
|
||||
" Copy" + (!ext.empty() ? "." + ext: ""));
|
||||
|
||||
if (get_config_bool("DuplicateSprite", "Flatten", false))
|
||||
flatten->setSelected(true);
|
||||
window.flatten()->setSelected(true);
|
||||
|
||||
// Open the window
|
||||
window->openWindowInForeground();
|
||||
window.openWindowInForeground();
|
||||
|
||||
if (window->getKiller() == window->findChild("ok")) {
|
||||
set_config_bool("DuplicateSprite", "Flatten", flatten->isSelected());
|
||||
if (window.getKiller() == window.ok()) {
|
||||
set_config_bool("DuplicateSprite", "Flatten", window.flatten()->isSelected());
|
||||
|
||||
// Make a copy of the document
|
||||
Document* docCopy;
|
||||
if (flatten->isSelected())
|
||||
if (window.flatten()->isSelected())
|
||||
docCopy = document->duplicate(DuplicateWithFlattenLayers);
|
||||
else
|
||||
docCopy = document->duplicate(DuplicateExactCopy);
|
||||
|
||||
docCopy->setFilename(dst_name->getText().c_str());
|
||||
docCopy->setFilename(window.dstName()->getText().c_str());
|
||||
docCopy->setContext(context);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user