mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Unified SystemToolkit list directory with dialog file patterns
This commit is contained in:
@@ -43,6 +43,7 @@ using namespace std;
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
#define PATH_SEP '/'
|
#define PATH_SEP '/'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -298,7 +299,7 @@ std::string SystemToolkit::path_directory(const std::string& path)
|
|||||||
return directorypath;
|
return directorypath;
|
||||||
}
|
}
|
||||||
|
|
||||||
list<string> SystemToolkit::list_directory(const string& path, const list<string>& extensions)
|
list<string> SystemToolkit::list_directory(const string& path, const list<string>& patterns)
|
||||||
{
|
{
|
||||||
list<string> ls;
|
list<string> ls;
|
||||||
|
|
||||||
@@ -309,10 +310,12 @@ list<string> SystemToolkit::list_directory(const string& path, const list<string
|
|||||||
while ((ent = readdir (dir)) != NULL) {
|
while ((ent = readdir (dir)) != NULL) {
|
||||||
if ( ent->d_type == DT_REG)
|
if ( ent->d_type == DT_REG)
|
||||||
{
|
{
|
||||||
string filename = string(ent->d_name);
|
int found = FNM_NOMATCH;
|
||||||
string ext = extension_filename(filename);
|
for (auto it = patterns.cbegin(); it != patterns.cend() && found == FNM_NOMATCH; ++it)
|
||||||
if ( extensions.empty() || find(extensions.cbegin(), extensions.cend(), ext) != extensions.cend())
|
// test pattern in CASE insensitive
|
||||||
ls.push_back( full_filename(path, filename) );
|
found = fnmatch( it->c_str(), ent->d_name, FNM_CASEFOLD );
|
||||||
|
if (found != FNM_NOMATCH)
|
||||||
|
ls.push_back( full_filename(path, ent->d_name) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir (dir);
|
closedir (dir);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace SystemToolkit
|
|||||||
std::string path_directory(const std::string& path);
|
std::string path_directory(const std::string& path);
|
||||||
|
|
||||||
// list all files of a directory mathing the given filter extension (if any)
|
// list all files of a directory mathing the given filter extension (if any)
|
||||||
std::list<std::string> list_directory(const std::string& path, const std::list<std::string> &extensions);
|
std::list<std::string> list_directory(const std::string& path, const std::list<std::string> &patterns);
|
||||||
|
|
||||||
// builds a path relative to 'relativeTo' to reach file at 'absolutePath' (e.g. /a/b/c/d rel to /a/b/e -> ../c/d)
|
// builds a path relative to 'relativeTo' to reach file at 'absolutePath' (e.g. /a/b/c/d rel to /a/b/e -> ../c/d)
|
||||||
std::string path_relative_to_path(const std::string& absolutePath, const std::string& relativeTo);
|
std::string path_relative_to_path(const std::string& absolutePath, const std::string& relativeTo);
|
||||||
|
|||||||
@@ -4415,7 +4415,7 @@ void Navigator::RenderMainPannelVimix()
|
|||||||
// selection MODE 1 : LIST FOLDER
|
// selection MODE 1 : LIST FOLDER
|
||||||
else if ( selection_session_mode == 1) {
|
else if ( selection_session_mode == 1) {
|
||||||
// show list of vimix files in folder
|
// show list of vimix files in folder
|
||||||
sessions_list = SystemToolkit::list_directory( Settings::application.recentFolders.path, {"mix", "MIX"});
|
sessions_list = SystemToolkit::list_directory( Settings::application.recentFolders.path, { VIMIX_FILES_PATTERN });
|
||||||
}
|
}
|
||||||
// indicate the list changed (do not change at every frame)
|
// indicate the list changed (do not change at every frame)
|
||||||
selection_session_mode_changed = false;
|
selection_session_mode_changed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user