Extract cloud browser item creation helper
This commit is contained in:
@@ -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++)
|
||||
|
||||
Reference in New Issue
Block a user