sdi_toolBox
wildcard.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026 - SD-Innovation S.A.S. - FRANCE
3*/
4
5/*
6ver: 2.x.x - build: 2026-04-28
7*/
8
9/*
10The 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.
11*/
12
13#pragma once
14
15#include <vector>
16#include <wx/wx.h>
17
19{
20//--------------------------------------------------------------
43{
44 public:
50 {
51 wxString description;
52 wxString pattern;
53 };
54
55 public:
59 Wildcard() = default;
60
64 virtual ~Wildcard() = default;
65
70 Wildcard(const Wildcard &other) = default;
71
76 Wildcard(Wildcard &&other) noexcept = default;
77
83 Wildcard &operator=(const Wildcard &other) = default;
84
90 Wildcard &operator=(Wildcard &&other) noexcept = default;
91
95 void clear();
96
102 void addEntry(const wxString &description, const wxString &pattern);
103
109 [[nodiscard]] wxString getWildcards(bool addAllFiles = false) const;
110
111 protected:
112 std::vector<WildcardEntry> m_wildcards; // List of wildcard strings
113};
114//--------------------------------------------------------------
115/* Clear all wildcard entries */
116inline void Wildcard::clear()
117{
118 m_wildcards.clear();
119}
120//--------------------------------------------------------------
121/* Add a wildcard entry */
122inline void Wildcard::addEntry(const wxString &description, const wxString &pattern)
123{
124 m_wildcards.push_back({ .description = description, .pattern = pattern });
125}
126//--------------------------------------------------------------
127/* Get wildcard list */
128inline wxString Wildcard::getWildcards(const bool addAllFiles) const
129{
130 wxString wildcardList;
131
132 // Add wildcard entries to the list
133 for (const auto &entry : m_wildcards)
134 {
135 if (!wildcardList.empty())
136 wildcardList += _T("|");
137
138 wildcardList += entry.description + _T(" (") + entry.pattern + _T(")|") + entry.pattern;
139 }
140
141 // Optionally add "All files" entry
142 if (addAllFiles)
143 {
144 if (!wildcardList.empty())
145 wildcardList += _T("|");
146
147 wildcardList += _("All files") + _T(" (") + _T("*.*") + _T(")|") + _T("*.*");
148 }
149
150 return wildcardList;
151}
152//--------------------------------------------------------------
153} // namespace sdi_toolBox::desktop::wxWidgets
Manages a list of file wildcard entries for use in wxWidgets file dialogs.
Definition wildcard.h:43
void addEntry(const wxString &description, const wxString &pattern)
Adds a new wildcard filter entry.
Definition wildcard.h:122
Wildcard & operator=(Wildcard &&other) noexcept=default
Move assignment operator.
wxString getWildcards(bool addAllFiles=false) const
Builds and returns the formatted wildcard string for use in wxWidgets file dialogs.
Definition wildcard.h:128
virtual ~Wildcard()=default
Default destructor.
Wildcard(Wildcard &&other) noexcept=default
Move constructor.
std::vector< WildcardEntry > m_wildcards
Definition wildcard.h:112
void clear()
Removes all wildcard entries.
Definition wildcard.h:116
Wildcard & operator=(const Wildcard &other)=default
Copy assignment operator.
Wildcard()=default
Default constructor.
Wildcard(const Wildcard &other)=default
Copy constructor.
Namespace containing desktop UI utilities built on top of the wxWidgets framework.
Definition wildcard.h:19
Represents a single wildcard filter entry.
Definition wildcard.h:50
wxString pattern
File pattern used for filtering (e.g., "*.txt").
Definition wildcard.h:52
wxString description
Human-readable description of the file type (e.g., "Text files").
Definition wildcard.h:51