File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55//
66
77#include " interface_derived.hpp"
8- #if defined _WIN32
9- #include " dirent.h"
10- #else
11- #include < dirent.h>
12- #endif
8+ #include < filesystem>
139#include < wx/msgdlg.h>
1410#include < fmt/format.h>
1511#include < wx/choicdlg.h>
@@ -173,27 +169,20 @@ void CreateProjectDialogD::loadTemplates(const editor& e){
173169
174170 // open the folder
175171 auto templatesFolder = e.path /e.name / templatesDir;
176- DIR* dir = opendir (templatesFolder.string ().c_str ());
177- struct dirent *entry = readdir (dir);
178- // loop over the contents
179- while (entry != NULL )
180- {
181- // does the file start with the correct prefix?
182- if (string (entry->d_name ).rfind (templatePrefix,0 )==0 ){
183- // add it to the UI
184- wxListItem i;
185- i.SetId (0 );
186- string label = entry->d_name ;
187- i.SetText (label.substr (templatePrefix.length ()+1 ));
188-
189- templateCtrl->InsertItem (i);
190- }
191- // advance to next item in folder
192- entry = readdir (dir);
193- }
194- // free resources
195- closedir (dir);
196- free (entry);
172+
173+ for (const auto & entry : std::filesystem::directory_iterator{templatesFolder}){
174+ // does the file start with the correct prefix?
175+ auto path = entry.path ();
176+ if (path.filename ().string ().rfind (templatePrefix,0 )==0 ){
177+ // add it to the UI
178+ wxListItem i;
179+ i.SetId (0 );
180+ string label = path.filename ();
181+ i.SetText (label.substr (templatePrefix.length ()+1 ));
182+
183+ templateCtrl->InsertItem (i);
184+ }
185+ }
197186}
198187
199188void CreateProjectDialogD::OnChoiceChanged (wxCommandEvent& event){
You can’t perform that action at this time.
0 commit comments