feat: finish FileFilters class in dialog helper.
- finish FileFilters class representing the file types area in popup dialog.
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
#include "WinImportPrefix.hpp"
|
||||
#include <Windows.h>
|
||||
@ -13,6 +15,57 @@
|
||||
|
||||
namespace YYCC::DialogHelper {
|
||||
|
||||
/**
|
||||
* @brief The class represent the file types region in file dialog.
|
||||
*/
|
||||
class FileFilters {
|
||||
public:
|
||||
FileFilters() :
|
||||
m_Filters(),
|
||||
m_WinFilters(), m_WinDataStruct(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Add a filter pair in file types list.
|
||||
* @param filter_name[in] The friendly name of the filter.
|
||||
* @param il[in] A C++ initialize list.
|
||||
* Every entries must be `const char*` represent a single filter pattern.
|
||||
* The list at least should have one valid pattern.
|
||||
* This function will not validate these filter patterns, so please write them carefully.
|
||||
* @return True if added success, otherwise false.
|
||||
* @remarks This function allow you register multiple filter patterns for single friendly name.
|
||||
* For example: `Add("Microsoft Word (*.doc; *.docx)", {"*.doc", "*.docx"})`
|
||||
*/
|
||||
bool Add(const char* filter_name, std::initializer_list<const char*> il);
|
||||
/**
|
||||
* @brief Clear filter pairs for following re-use.
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/**
|
||||
* @brief Generate Windows dialog system used data struct.
|
||||
* @param filter_count[out] The count of generated filter data struct.
|
||||
* @param filter_specs[out] The pointer to generated filter data struct.
|
||||
* @remarks User should not call this function. This function is used by internal functions.
|
||||
* @return True if generation is success, otherwise false.
|
||||
*/
|
||||
bool Generate(UINT& filter_count, COMDLG_FILTERSPEC*& filter_specs);
|
||||
|
||||
protected:
|
||||
using FilterModes = std::vector<std::string>;
|
||||
using FilterName = std::string;
|
||||
using FilterPair = std::pair<FilterName, FilterModes>;
|
||||
|
||||
std::vector<FilterPair> m_Filters;
|
||||
|
||||
using WinFilterModes = std::wstring;
|
||||
using WinFilterName = std::wstring;
|
||||
using WinFilterPair = std::pair<WinFilterName, WinFilterModes>;
|
||||
|
||||
std::vector<WinFilterPair> m_WinFilters;
|
||||
std::unique_ptr<COMDLG_FILTERSPEC[]> m_WinDataStruct;
|
||||
};
|
||||
|
||||
//struct FileDialogParameter {
|
||||
// FileDialogParameter() :
|
||||
// m_Owner(nullptr),
|
||||
|
Reference in New Issue
Block a user