Files
PowerToys/src/modules/NewPlus/NewShellExtensionContextMenu/template_folder.cpp
Christian Gaarden Gaardmark 084402a2bd [New+]Windows 10 support (#35832)
2024-11-27 14:22:05 +00:00

58 lines
1.4 KiB
C++

#include "pch.h"
#include <shellapi.h>
#include "template_folder.h"
using namespace newplus;
template_folder::template_folder(){};
template_folder::template_folder(const std::filesystem::path newplus_template_folder)
{
this->template_folder_path = newplus_template_folder;
}
template_folder::~template_folder()
{
list_of_templates.clear();
}
void template_folder::init()
{
rescan_template_folder();
}
void template_folder::rescan_template_folder()
{
list_of_templates.clear();
std::list<std::pair<std::wstring, template_item*>> dirs;
std::list<std::pair<std::wstring, template_item*>> files;
for (const auto& entry : std::filesystem::directory_iterator(template_folder_path))
{
if (entry.is_directory())
{
dirs.push_back({ entry.path().wstring(), new template_item(entry) });
}
else
{
if (!utilities::is_hidden(entry.path()))
{
files.push_back({ entry.path().wstring(), new template_item(entry) });
}
}
}
// List of templates are sorted, with template-directories/folders first then followed by template-files
dirs.sort();
files.sort();
list_of_templates = dirs;
list_of_templates.splice(list_of_templates.end(), files);
}
template_item* template_folder::get_template_item(const int index) const
{
auto it = list_of_templates.begin();
std::advance(it, index);
return it->second;
}