[Color] Some SD manager fixes

This commit is contained in:
Raphael Coeffic
2021-06-15 17:37:13 +02:00
parent 60517df349
commit 8b92b3be98
4 changed files with 40 additions and 27 deletions
+27 -11
View File
@@ -92,6 +92,10 @@ class FileNameEditWindow : public Page
RadioSdManagerPage::RadioSdManagerPage() : RadioSdManagerPage::RadioSdManagerPage() :
PageTab(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, ICON_RADIO_SD_MANAGER) PageTab(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, ICON_RADIO_SD_MANAGER)
{ {
setOnSetVisibleHandler([]() {
TRACE("f_chdir(ROOT_PATH)");
f_chdir(ROOT_PATH);
});
} }
void RadioSdManagerPage::rebuild(FormWindow * window) void RadioSdManagerPage::rebuild(FormWindow * window)
@@ -115,6 +119,13 @@ char * getFullPath(const std::string &filename)
return full_path; return full_path;
} }
char * getCurrentPath()
{
static char path[FF_MAX_LFN + 1]; // TODO optimize that!
f_getcwd((TCHAR*)path, FF_MAX_LFN);
return path;
}
class FilePreview : public Window class FilePreview : public Window
{ {
public: public:
@@ -209,6 +220,7 @@ void RadioSdManagerPage::build(FormWindow * window)
std::list<std::string> files; std::list<std::string> files;
std::list<std::string> directories; std::list<std::string> directories;
std::string currentPath(getCurrentPath());
auto preview = new FilePreview(window, {LCD_W / 2 + 6, 0, LCD_W / 2 - 16, window->height()}); auto preview = new FilePreview(window, {LCD_W / 2 + 6, 0, LCD_W / 2 - 16, window->height()});
FRESULT res = f_opendir(&dir, "."); // Open the directory FRESULT res = f_opendir(&dir, "."); // Open the directory
@@ -238,7 +250,8 @@ void RadioSdManagerPage::build(FormWindow * window)
for (auto name: directories) { for (auto name: directories) {
auto b = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t { auto b = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t {
f_chdir(name.data()); std::string fullpath = currentPath + "/" + name;
f_chdir(fullpath.c_str());
window->clear(); window->clear();
build(window); build(window);
return 0; return 0;
@@ -250,6 +263,7 @@ void RadioSdManagerPage::build(FormWindow * window)
for (auto name: files) { for (auto name: files) {
auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t { auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t {
auto menu = new Menu(window); auto menu = new Menu(window);
f_chdir(currentPath.c_str());
const char *ext = getFileExtension(name.data()); const char *ext = getFileExtension(name.data());
if (ext) { if (ext) {
if (!strcasecmp(ext, SOUNDS_EXT)) { if (!strcasecmp(ext, SOUNDS_EXT)) {
@@ -286,14 +300,14 @@ void RadioSdManagerPage::build(FormWindow * window)
dialog->flash(getFullPath(name)); dialog->flash(getFullPath(name));
}); });
} }
else if (isExtensionMatching(ext, BITMAPS_EXT)) { // else if (isExtensionMatching(ext, BITMAPS_EXT)) {
// TODO // // TODO
} // }
else if (!strcasecmp(ext, TEXT_EXT)) { // else if (!strcasecmp(ext, TEXT_EXT)) {
menu->addLine(STR_VIEW_TEXT, [=]() { // menu->addLine(STR_VIEW_TEXT, [=]() {
// TODO // // TODO
}); // });
} // }
if (!READ_ONLY() && !strcasecmp(ext, FIRMWARE_EXT)) { if (!READ_ONLY() && !strcasecmp(ext, FIRMWARE_EXT)) {
if (isBootloader(name.data())) { if (isBootloader(name.data())) {
menu->addLine(STR_FLASH_BOOTLOADER, [=]() { menu->addLine(STR_FLASH_BOOTLOADER, [=]() {
@@ -328,8 +342,9 @@ void RadioSdManagerPage::build(FormWindow * window)
} }
#if defined(LUA) #if defined(LUA)
else if (isExtensionMatching(ext, SCRIPTS_EXT)) { else if (isExtensionMatching(ext, SCRIPTS_EXT)) {
std::string fullpath = currentPath + "/" + name;
menu->addLine(STR_EXECUTE_FILE, [=]() { menu->addLine(STR_EXECUTE_FILE, [=]() {
luaExec(getFullPath(name)); luaExec(fullpath.c_str());
//TODO: check 'luaState' //TODO: check 'luaState'
StandaloneLuaWindow::instance()->attach(window); StandaloneLuaWindow::instance()->attach(window);
}); });
@@ -374,7 +389,8 @@ void RadioSdManagerPage::build(FormWindow * window)
}); });
} }
return 0; return 0;
}, 0); }, OPAQUE);
button->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; });
button->setFocusHandler([=](bool active) { button->setFocusHandler([=](bool active) {
if (active) { if (active) {
preview->setFile(getFullPath(name)); preview->setFile(getFullPath(name));
+7 -3
View File
@@ -119,10 +119,14 @@ void RadioToolsPage::rebuild(FormWindow * window)
auto b = new TextButton( auto b = new TextButton(
window, grid.getFieldSlot(1), label, window, grid.getFieldSlot(1), label,
[window, path_str]() -> uint8_t { [window, path_str]() -> uint8_t {
f_chdir("/SCRIPTS/TOOLS/");
luaExec(path_str.c_str()); char toolPath[FF_MAX_LFN + 1];
// TODO: check 'luaState' strncpy(toolPath, path_str.c_str(), sizeof(toolPath)-1);
*((char *)getBasename(toolPath)-1) = '\0';
f_chdir(toolPath);
StandaloneLuaWindow::instance()->attach(window); StandaloneLuaWindow::instance()->attach(window);
luaExec(path_str.c_str());
return 0; return 0;
}, },
OPAQUE); OPAQUE);
+3 -2
View File
@@ -146,9 +146,10 @@ void TabsGroup::setVisibleTab(PageTab * tab)
Keyboard::hide(); Keyboard::hide();
#endif #endif
currentTab = tab; currentTab = tab;
if (tab->onSetVisible) tab->onSetVisible();
tab->build(&body); tab->build(&body);
if (!focusWindow) if (!focusWindow) setFocus(SET_FOCUS_DEFAULT);
setFocus(SET_FOCUS_DEFAULT);
header.setTitle(tab->title.c_str()); header.setTitle(tab->title.c_str());
invalidate(); invalidate();
} }
+3 -11
View File
@@ -50,17 +50,9 @@ class PageTab {
{ {
} }
void destroy() void setOnSetVisibleHandler(std::function<void()> handler)
{ {
if (onPageDestroyed) { onSetVisible = std::move(handler);
onPageDestroyed();
}
delete this;
}
void setOnPageDestroyedHandler(std::function<void()> handler)
{
onPageDestroyed = std::move(handler);
} }
void setTitle(std::string value) void setTitle(std::string value)
@@ -81,7 +73,7 @@ class PageTab {
protected: protected:
std::string title; std::string title;
unsigned icon = 0; unsigned icon = 0;
std::function<void()> onPageDestroyed; std::function<void()> onSetVisible;
}; };
class TabsCarousel: public Window { class TabsCarousel: public Window {