Extract cloud browser item creation helper

This commit is contained in:
2026-06-15 20:48:59 +02:00
parent 0ba7eb8331
commit 45f08ee8e4
5 changed files with 82 additions and 25 deletions

View File

@@ -78,6 +78,36 @@ bool NodeDialogCloud::load_cloud_file_list(CURL* curl, std::string& response, No
return true;
}
std::vector<NodeDialogCloudItem*> NodeDialogCloud::create_cloud_file_items(const std::vector<std::string>& names)
{
std::vector<NodeDialogCloudItem*> nodes;
nodes.reserve(names.size());
for (const auto& name : names)
{
auto node = new NodeDialogCloudItem;
node->set_manager(m_manager);
node->init();
node->m_text->set_text(name.c_str());
node->m_path = App::I->work_path + "/" + name;
node->m_file_name = name;
container->add_child(node);
node->on_selected = [&](NodeDialogCloudItem* target) {
if (target == current)
return;
selected_path = target->m_path;
selected_file = target->m_file_name;
selected_name = selected_file.substr(0, selected_file.length() - strlen(".ppi"));
if (current)
current->m_selected = false;
current = target;
};
nodes.push_back(node);
}
return nodes;
}
void NodeDialogCloud::load_thumbs_thread()
{
#if WITH_CURL
@@ -99,30 +129,7 @@ void NodeDialogCloud::load_thumbs_thread()
LOG("CLOUD LIST: %s", res.c_str());
auto names = split(res, ',');
std::vector<NodeDialogCloudItem*> nodes;
// create slots with name
for (const auto& n : names)
{
auto node = new NodeDialogCloudItem;
node->set_manager(m_manager);
node->init();
node->m_text->set_text(n.c_str());
node->m_path = App::I->work_path + "/" + n;
node->m_file_name = n;
container->add_child(node);
node->on_selected = [&](NodeDialogCloudItem* target) {
if (target == current)
return;
selected_path = target->m_path;
selected_file = target->m_file_name;
selected_name = selected_file.substr(0, selected_file.length() - strlen(".ppi"));
if (current)
current->m_selected = false;
current = target;
};
nodes.push_back(node);
}
auto nodes = create_cloud_file_items(names);
// load the icons
for (int i = 0; i < names.size(); i++)