fix(color): Filter Unix/MacOS dot files from file chooser popup (#4428)

This commit is contained in:
philmoz
2023-12-18 20:00:00 +10:00
committed by GitHub
parent 77e6a7c14f
commit 87e71d0a33
+16 -21
View File
@@ -17,23 +17,24 @@
*/ */
#include "filechoice.h" #include "filechoice.h"
#include <algorithm>
#include "libopenui_file.h" #include "libopenui_file.h"
#include "menu.h" #include "menu.h"
#include "theme.h" #include "theme.h"
#include "message_dialog.h" #include "message_dialog.h"
#include <algorithm>
#if !defined(STR_SDCARD) #if !defined(STR_SDCARD)
#define STR_SDCARD "SD" #define STR_SDCARD "SD"
#endif #endif
#if !defined(STR_NO_FILES_ON_SD) #if !defined(STR_NO_FILES_ON_SD)
#define STR_NO_FILES_ON_SD "No files on SD Card!" #define STR_NO_FILES_ON_SD "No files on SD Card!"
#endif #endif
FileChoice::FileChoice(Window* parent, const rect_t &rect, FileChoice::FileChoice(Window *parent, const rect_t &rect, std::string folder,
std::string folder, const char *extension, int maxlen, const char *extension, int maxlen,
std::function<std::string()> getValue, std::function<std::string()> getValue,
std::function<void(std::string)> setValue, std::function<void(std::string)> setValue,
bool stripExtension) : bool stripExtension) :
@@ -48,11 +49,7 @@ FileChoice::FileChoice(Window* parent, const rect_t &rect,
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
} }
std::string FileChoice::getLabelText() std::string FileChoice::getLabelText() { return getValue(); }
{
return getValue();
}
bool FileChoice::openMenu() bool FileChoice::openMenu()
{ {
@@ -68,10 +65,11 @@ bool FileChoice::openMenu()
for (;;) { for (;;) {
res = sdReadDir(&dir, &fno, firstTime); res = sdReadDir(&dir, &fno, firstTime);
if (res != FR_OK || fno.fname[0] == 0) if (res != FR_OK || fno.fname[0] == 0)
break; // break on error or end of dir break; // break on error or end of dir
if (fno.fattrib & AM_DIR) continue; // skip subfolders if (fno.fattrib & (AM_HID | AM_SYS | AM_DIR))
if (fno.fattrib & AM_HID) continue; // skip hidden files continue; // Ignore subfolders, hidden files and system files
if (fno.fattrib & AM_SYS) continue; // skip system files if (fno.fname[0] == '.' && fno.fname[1] != '.')
continue; // Ignore hidden files under UNIX, but not ..
fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen); fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen);
@@ -101,8 +99,8 @@ bool FileChoice::openMenu()
std::string value = getValue(); std::string value = getValue();
for (const auto &file : files) { for (const auto &file : files) {
menu->addLineBuffered(file, [=]() { menu->addLineBuffered(file, [=]() {
setValue(file); setValue(file);
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
}); });
// TRACE("%s %d %s %d", value.c_str(), value.size(), file.c_str(), // TRACE("%s %d %s %d", value.c_str(), value.size(), file.c_str(),
// file.size()); // file.size());
@@ -132,7 +130,4 @@ bool FileChoice::openMenu()
return false; return false;
} }
void FileChoice::onClicked() void FileChoice::onClicked() { openMenu(); }
{
openMenu();
}