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