wildcard.h
Go to the documentation of this file.
/*
Copyright (c) 2026 - SD-Innovation S.A.S. - FRANCE
*/
/*
ver: 2.x.x - build: 2026-04-28
*/
/*
The zlib License Copyright (c) 2026 SD-Innovation S.A.S. This software is provided ‘as-is’, without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.
*/
#pragma once
#include <vector>
#include <wx/wx.h>
namespace sdi_toolBox::desktop::wxWidgets
{
//--------------------------------------------------------------
class Wildcard
{
public:
struct WildcardEntry
{
wxString description;
wxString pattern;
};
public:
Wildcard() = default;
virtual ~Wildcard() = default;
Wildcard(const Wildcard &other) = default;
Wildcard(Wildcard &&other) noexcept = default;
Wildcard &operator=(const Wildcard &other) = default;
Wildcard &operator=(Wildcard &&other) noexcept = default;
void clear();
void addEntry(const wxString &description, const wxString &pattern);
[[nodiscard]] wxString getWildcards(bool addAllFiles = false) const;
protected:
std::vector<WildcardEntry> m_wildcards; // List of wildcard strings
};
//--------------------------------------------------------------
/* Clear all wildcard entries */
inline void Wildcard::clear()
{
m_wildcards.clear();
}
//--------------------------------------------------------------
/* Add a wildcard entry */
inline void Wildcard::addEntry(const wxString &description, const wxString &pattern)
{
m_wildcards.push_back({ .description = description, .pattern = pattern });
}
//--------------------------------------------------------------
/* Get wildcard list */
inline wxString Wildcard::getWildcards(const bool addAllFiles) const
{
wxString wildcardList;
// Add wildcard entries to the list
for (const auto &entry : m_wildcards)
{
if (!wildcardList.empty())
wildcardList += _T("|");
wildcardList += entry.description + _T(" (") + entry.pattern + _T(")|") + entry.pattern;
}
// Optionally add "All files" entry
if (addAllFiles)
{
if (!wildcardList.empty())
wildcardList += _T("|");
wildcardList += _("All files") + _T(" (") + _T("*.*") + _T(")|") + _T("*.*");
}
return wildcardList;
}
//--------------------------------------------------------------
} // namespace sdi_toolBox::desktop::wxWidgets
sdi_toolBox::desktop::wxWidgets::Wildcard
Manages a list of file wildcard entries for use in wxWidgets file dialogs.
Definition wildcard.h:43
sdi_toolBox::desktop::wxWidgets::Wildcard::addEntry
void addEntry(const wxString &description, const wxString &pattern)
Adds a new wildcard filter entry.
Definition wildcard.h:122
sdi_toolBox::desktop::wxWidgets::Wildcard::operator=
Wildcard & operator=(Wildcard &&other) noexcept=default
Move assignment operator.
sdi_toolBox::desktop::wxWidgets::Wildcard::getWildcards
wxString getWildcards(bool addAllFiles=false) const
Builds and returns the formatted wildcard string for use in wxWidgets file dialogs.
Definition wildcard.h:128
sdi_toolBox::desktop::wxWidgets::Wildcard::~Wildcard
virtual ~Wildcard()=default
Default destructor.
sdi_toolBox::desktop::wxWidgets::Wildcard::Wildcard
Wildcard(Wildcard &&other) noexcept=default
Move constructor.
sdi_toolBox::desktop::wxWidgets::Wildcard::m_wildcards
std::vector< WildcardEntry > m_wildcards
Definition wildcard.h:112
sdi_toolBox::desktop::wxWidgets::Wildcard::clear
void clear()
Removes all wildcard entries.
Definition wildcard.h:116
sdi_toolBox::desktop::wxWidgets::Wildcard::operator=
Wildcard & operator=(const Wildcard &other)=default
Copy assignment operator.
sdi_toolBox::desktop::wxWidgets::Wildcard::Wildcard
Wildcard()=default
Default constructor.
sdi_toolBox::desktop::wxWidgets::Wildcard::Wildcard
Wildcard(const Wildcard &other)=default
Copy constructor.
sdi_toolBox::desktop::wxWidgets
Namespace containing desktop UI utilities built on top of the wxWidgets framework.
Definition wildcard.h:19
sdi_toolBox::desktop::wxWidgets::Wildcard::WildcardEntry
Represents a single wildcard filter entry.
Definition wildcard.h:50
sdi_toolBox::desktop::wxWidgets::Wildcard::WildcardEntry::pattern
wxString pattern
File pattern used for filtering (e.g., "*.txt").
Definition wildcard.h:52
sdi_toolBox::desktop::wxWidgets::Wildcard::WildcardEntry::description
wxString description
Human-readable description of the file type (e.g., "Text files").
Definition wildcard.h:51