Skip to content

Commit 9414308

Browse files
authored
fix(color): file picker may not work in Lua scripts (#6828)
1 parent b05fb4a commit 9414308

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

radio/src/gui/colorlcd/libui/filechoice.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ class FileChoiceMenuToolbar : public MenuToolbar
9292
protected:
9393
};
9494

95-
FileChoice::FileChoice(Window *parent, const rect_t &rect, std::string folder,
96-
const char *extension, int maxlen,
95+
FileChoice::FileChoice(Window *parent, const rect_t &rect, const std::string folder,
96+
const std::string extension, int maxlen,
9797
std::function<std::string()> getValue,
9898
std::function<void(std::string)> setValue,
9999
bool stripExtension, const char *title) :
100100
Choice(
101101
parent, rect, 0, 0, [=]() { return selectedIdx; },
102102
[=](int val) { setValue(getString(val)); selectedIdx = val; }, title, CHOICE_TYPE_FOLDER),
103103
folder(std::move(folder)),
104-
extension(extension),
104+
extension(std::move(extension)),
105105
maxlen(maxlen),
106106
getValue(std::move(getValue)),
107107
stripExtension(stripExtension)
@@ -113,9 +113,9 @@ std::string FileChoice::getLabelText() { return getValue(); }
113113

114114
void FileChoice::loadFiles()
115115
{
116-
if (loaded) return;
116+
if (filesLoaded) return;
117117

118-
loaded = true;
118+
filesLoaded = true;
119119

120120
FILINFO fno;
121121
DIR dir;
@@ -137,7 +137,7 @@ void FileChoice::loadFiles()
137137

138138
fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen);
139139

140-
if (extension && (!fnExt || !isExtensionMatching(fnExt, extension)))
140+
if (!extension.empty() && (!fnExt || !isExtensionMatching(fnExt, extension.c_str())))
141141
continue; // wrong extension
142142

143143
if (stripExtension) fnLen -= extLen;

radio/src/gui/colorlcd/libui/filechoice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
class FileChoice : public Choice
2525
{
2626
public:
27-
FileChoice(Window* parent, const rect_t& rect, std::string folder,
28-
const char* extension, int maxlen,
27+
FileChoice(Window* parent, const rect_t& rect, const std::string folder,
28+
const std::string extension, int maxlen,
2929
std::function<std::string()> getValue,
3030
std::function<void(std::string)> setValue,
3131
bool stripExtension = false,
@@ -36,12 +36,13 @@ class FileChoice : public Choice
3636
#endif
3737

3838
protected:
39+
bool filesLoaded = false;
3940
int fileCount = 0;
4041
int selectedIdx = -1;
4142
Menu* menu = nullptr;
4243
std::string getLabelText() override;
4344
std::string folder;
44-
const char* extension;
45+
std::string extension;
4546
int maxlen;
4647
std::function<std::string()> getValue;
4748
bool stripExtension;

radio/src/gui/colorlcd/mainview/widget_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ WidgetSettings::WidgetSettings(Widget* w) :
198198
break;
199199

200200
case WidgetOption::File:
201-
new FileChoice(line, rect_t{}, opt->fileSelectPath, nullptr, FF_MAX_LFN,
201+
new FileChoice(line, rect_t{}, opt->fileSelectPath, "", FF_MAX_LFN,
202202
[=]() {
203203
return widgetData->getString(optIdx);
204204
},

radio/src/lua/lua_lvgl_widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ void LvglWidgetFilePicker::build(lua_State *L)
26902690
if (h == LV_SIZE_CONTENT) h = 0;
26912691
auto c = new FileChoice(
26922692
lvglManager->getCurrentParent(), {x, y, w, h},
2693-
folder.c_str(), extension.c_str(), maxLen,
2693+
folder, extension, maxLen,
26942694
[=]() { return pcallGetStringVal(L, getFunction); },
26952695
[=](std::string val) { pcallSetStringVal(L, setFunction, val.c_str()); },
26962696
hideExtension, title.txt.c_str());

0 commit comments

Comments
 (0)