[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() :
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)
@@ -115,6 +119,13 @@ char * getFullPath(const std::string &filename)
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
{
public:
@@ -209,6 +220,7 @@ void RadioSdManagerPage::build(FormWindow * window)
std::list<std::string> files;
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()});
FRESULT res = f_opendir(&dir, "."); // Open the directory
@@ -238,7 +250,8 @@ void RadioSdManagerPage::build(FormWindow * window)
for (auto name: directories) {
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();
build(window);
return 0;
@@ -250,6 +263,7 @@ void RadioSdManagerPage::build(FormWindow * window)
for (auto name: files) {
auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t {
auto menu = new Menu(window);
f_chdir(currentPath.c_str());
const char *ext = getFileExtension(name.data());
if (ext) {
if (!strcasecmp(ext, SOUNDS_EXT)) {
@@ -286,14 +300,14 @@ void RadioSdManagerPage::build(FormWindow * window)
dialog->flash(getFullPath(name));
});
}
else if (isExtensionMatching(ext, BITMAPS_EXT)) {
// TODO
}
else if (!strcasecmp(ext, TEXT_EXT)) {
menu->addLine(STR_VIEW_TEXT, [=]() {
// TODO
});
}
// else if (isExtensionMatching(ext, BITMAPS_EXT)) {
// // TODO
// }
// else if (!strcasecmp(ext, TEXT_EXT)) {
// menu->addLine(STR_VIEW_TEXT, [=]() {
// // TODO
// });
// }
if (!READ_ONLY() && !strcasecmp(ext, FIRMWARE_EXT)) {
if (isBootloader(name.data())) {
menu->addLine(STR_FLASH_BOOTLOADER, [=]() {
@@ -328,8 +342,9 @@ void RadioSdManagerPage::build(FormWindow * window)
}
#if defined(LUA)
else if (isExtensionMatching(ext, SCRIPTS_EXT)) {
std::string fullpath = currentPath + "/" + name;
menu->addLine(STR_EXECUTE_FILE, [=]() {
luaExec(getFullPath(name));
luaExec(fullpath.c_str());
//TODO: check 'luaState'
StandaloneLuaWindow::instance()->attach(window);
});
@@ -374,7 +389,8 @@ void RadioSdManagerPage::build(FormWindow * window)
});
}
return 0;
}, 0);
}, OPAQUE);
button->setBgColorHandler([=]() -> LcdFlags { return FIELD_BGCOLOR; });
button->setFocusHandler([=](bool active) {
if (active) {
preview->setFile(getFullPath(name));
+7 -3
View File
@@ -119,10 +119,14 @@ void RadioToolsPage::rebuild(FormWindow * window)
auto b = new TextButton(
window, grid.getFieldSlot(1), label,
[window, path_str]() -> uint8_t {
f_chdir("/SCRIPTS/TOOLS/");
luaExec(path_str.c_str());
// TODO: check 'luaState'
char toolPath[FF_MAX_LFN + 1];
strncpy(toolPath, path_str.c_str(), sizeof(toolPath)-1);
*((char *)getBasename(toolPath)-1) = '\0';
f_chdir(toolPath);
StandaloneLuaWindow::instance()->attach(window);
luaExec(path_str.c_str());
return 0;
},
OPAQUE);
+3 -2
View File
@@ -146,9 +146,10 @@ void TabsGroup::setVisibleTab(PageTab * tab)
Keyboard::hide();
#endif
currentTab = tab;
if (tab->onSetVisible) tab->onSetVisible();
tab->build(&body);
if (!focusWindow)
setFocus(SET_FOCUS_DEFAULT);
if (!focusWindow) setFocus(SET_FOCUS_DEFAULT);
header.setTitle(tab->title.c_str());
invalidate();
}
+3 -11
View File
@@ -50,17 +50,9 @@ class PageTab {
{
}
void destroy()
void setOnSetVisibleHandler(std::function<void()> handler)
{
if (onPageDestroyed) {
onPageDestroyed();
}
delete this;
}
void setOnPageDestroyedHandler(std::function<void()> handler)
{
onPageDestroyed = std::move(handler);
onSetVisible = std::move(handler);
}
void setTitle(std::string value)
@@ -81,7 +73,7 @@ class PageTab {
protected:
std::string title;
unsigned icon = 0;
std::function<void()> onPageDestroyed;
std::function<void()> onSetVisible;
};
class TabsCarousel: public Window {