#include "pch.h"
#include "log.h"
#include "node_dialog_layer_rename.h"
#include "canvas.h"
#include "node_image_texture.h"

Node* NodeDialogLayerRename::clone_instantiate() const
{
    return new NodeDialogLayerRename();
}

void NodeDialogLayerRename::clone_finalize(Node* dest) const
{
    NodeDialogLayerRename* n = static_cast<NodeDialogLayerRename*>(dest);
    n->init_controls();
}

void NodeDialogLayerRename::init()
{
    init_template_file("data/dialogs/layer-rename.xml", "dialog-layer-rename");
    init_controls();
}

void NodeDialogLayerRename::init_controls()
{
    btn_ok = find<NodeButton>("btn-ok");
    btn_cancel = find<NodeButton>("btn-cancel");
    input = find<NodeTextInput>("txt-input");
}

void NodeDialogLayerRename::loaded()
{
//    Image thumb = Canvas::I->thumbnail_read(data_path);
//    auto image_tex = find<NodeImageTexture>("thumb-tex");
//    image_tex->tex.create(thumb);
}

std::string NodeDialogLayerRename::get_name()
{
    return input ? input->m_text : "";
}

void NodeDialogLayerRename::added(Node* parent)
{
    Node::added(parent);
    if (added_to_root())
        input->key_capture();
}
