MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / AddFiltersToDialog

Function AddFiltersToDialog

extern/nfd/nfd_gtk.cpp:81–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79};
80
81void AddFiltersToDialog(GtkFileChooser* chooser,
82 const nfdnfilteritem_t* filterList,
83 nfdfiltersize_t filterCount) {
84 if (filterCount) {
85 assert(filterList);
86
87 // we have filters to add ... format and add them
88
89 for (nfdfiltersize_t index = 0; index != filterCount; ++index) {
90 GtkFileFilter* filter = gtk_file_filter_new();
91
92 // count number of file extensions
93 size_t sep = 1;
94 for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) {
95 if (*p_spec == L',') {
96 ++sep;
97 }
98 }
99
100 // friendly name conversions: "png,jpg" -> "Image files
101 // (png, jpg)"
102
103 // calculate space needed (including the trailing '\0')
104 size_t nameSize =
105 sep + strlen(filterList[index].spec) + 3 + strlen(filterList[index].name);
106
107 // malloc the required memory
108 nfdnchar_t* nameBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) * nameSize);
109
110 nfdnchar_t* p_nameBuf = nameBuf;
111 for (const nfdnchar_t* p_filterName = filterList[index].name; *p_filterName;
112 ++p_filterName) {
113 *p_nameBuf++ = *p_filterName;
114 }
115 *p_nameBuf++ = ' ';
116 *p_nameBuf++ = '(';
117 const nfdnchar_t* p_extensionStart = filterList[index].spec;
118 for (const nfdnchar_t* p_spec = filterList[index].spec; true; ++p_spec) {
119 if (*p_spec == ',' || !*p_spec) {
120 if (*p_spec == ',') {
121 *p_nameBuf++ = ',';
122 *p_nameBuf++ = ' ';
123 }
124
125 // +1 for the trailing '\0'
126 nfdnchar_t* extnBuf = NFDi_Malloc<nfdnchar_t>(sizeof(nfdnchar_t) *
127 (p_spec - p_extensionStart + 3));
128 nfdnchar_t* p_extnBufEnd = extnBuf;
129 *p_extnBufEnd++ = '*';
130 *p_extnBufEnd++ = '.';
131 p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd);
132 *p_extnBufEnd++ = '\0';
133 assert((size_t)(p_extnBufEnd - extnBuf) ==
134 sizeof(nfdnchar_t) * (p_spec - p_extensionStart + 3));
135 gtk_file_filter_add_pattern(filter, extnBuf);
136 NFDi_Free(extnBuf);
137
138 if (*p_spec) {

Callers 2

NFD_OpenDialogNFunction · 0.70
NFD_OpenDialogMultipleNFunction · 0.70

Calls 2

copyFunction · 0.70
NFDi_FreeFunction · 0.70

Tested by

no test coverage detected