2025-09-18 05:11:56 -05:00
|
|
|
/**
|
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
|
|
|
|
* Copyright (C) 2021-2025 tildearrow and contributors
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
// this is the code to a new file picker using Dear ImGui.
|
|
|
|
|
// this will eventually replace ImGuiFileDialog as the built-in file picker.
|
2025-09-18 05:11:56 -05:00
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
#include "newFilePicker.h"
|
2025-09-23 01:31:49 -05:00
|
|
|
#include "IconsFontAwesome4.h"
|
|
|
|
|
#include "misc/cpp/imgui_stdlib.h"
|
2025-09-23 05:20:52 -05:00
|
|
|
#include "../ta-log.h"
|
|
|
|
|
#include <algorithm>
|
2025-09-26 05:14:29 -05:00
|
|
|
#include <chrono>
|
2025-09-21 05:48:30 -05:00
|
|
|
#include <dirent.h>
|
2025-09-26 05:14:29 -05:00
|
|
|
#include <fcntl.h>
|
2025-09-21 17:45:06 -05:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <time.h>
|
2025-09-26 05:14:29 -05:00
|
|
|
#include <unistd.h>
|
2025-09-21 05:48:30 -05:00
|
|
|
|
2025-09-25 20:49:40 -05:00
|
|
|
static const char* sizeSuffixes=".KMGTPEZ";
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
static void _fileThread(void* item) {
|
|
|
|
|
((FurnaceFilePicker*)item)->readDirectorySub();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FurnaceFilePicker::readDirectorySub() {
|
|
|
|
|
/// STAGE 1: get file list
|
|
|
|
|
DIR* dir=opendir(path.c_str());
|
|
|
|
|
|
|
|
|
|
if (dir==NULL) {
|
|
|
|
|
failMessage=strerror(errno);
|
|
|
|
|
haveFiles=true;
|
|
|
|
|
haveStat=true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct dirent* entry=NULL;
|
|
|
|
|
while (true) {
|
|
|
|
|
entry=readdir(dir);
|
|
|
|
|
if (entry==NULL) break;
|
|
|
|
|
if (strcmp(entry->d_name,".")==0) continue;
|
|
|
|
|
if (strcmp(entry->d_name,"..")==0) continue;
|
|
|
|
|
|
|
|
|
|
FileEntry* newEntry=new FileEntry;
|
2025-09-26 05:14:29 -05:00
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
newEntry->name=entry->d_name;
|
2025-09-26 05:14:29 -05:00
|
|
|
newEntry->nameLower=entry->d_name;
|
|
|
|
|
for (char& i: newEntry->nameLower) {
|
|
|
|
|
if (i>='A' && i<='Z') i+='a'-'A';
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
switch (entry->d_type) {
|
|
|
|
|
case DT_REG:
|
|
|
|
|
newEntry->type=FP_TYPE_NORMAL;
|
|
|
|
|
break;
|
|
|
|
|
case DT_DIR:
|
|
|
|
|
newEntry->type=FP_TYPE_DIR;
|
2025-09-23 01:31:49 -05:00
|
|
|
newEntry->isDir=true;
|
2025-09-21 05:48:30 -05:00
|
|
|
break;
|
2025-09-26 05:14:29 -05:00
|
|
|
case DT_LNK: {
|
2025-09-21 05:48:30 -05:00
|
|
|
newEntry->type=FP_TYPE_LINK;
|
2025-09-26 05:14:29 -05:00
|
|
|
// resolve link to determine whether this is a directory
|
|
|
|
|
String readLinkPath;
|
|
|
|
|
DIR* readLinkDir=NULL;
|
|
|
|
|
if (*path.rbegin()=='/') {
|
|
|
|
|
readLinkPath=path+newEntry->name;
|
|
|
|
|
} else {
|
|
|
|
|
readLinkPath=path+'/'+newEntry->name;
|
|
|
|
|
}
|
|
|
|
|
// silly, but works.
|
|
|
|
|
logV("Read a symlink...");
|
|
|
|
|
readLinkDir=opendir(readLinkPath.c_str());
|
|
|
|
|
if (readLinkDir!=NULL) {
|
|
|
|
|
logV("Is file");
|
|
|
|
|
newEntry->isDir=true;
|
|
|
|
|
closedir(readLinkDir);
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
break;
|
2025-09-26 05:14:29 -05:00
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
case DT_SOCK:
|
|
|
|
|
newEntry->type=FP_TYPE_SOCKET;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
newEntry->type=FP_TYPE_UNKNOWN;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
if (!newEntry->isDir) {
|
|
|
|
|
size_t extPos=newEntry->name.rfind('.');
|
|
|
|
|
if (extPos!=String::npos) {
|
|
|
|
|
newEntry->ext=newEntry->name.substr(extPos);
|
|
|
|
|
for (char& i: newEntry->ext) {
|
|
|
|
|
if (i>='A' && i<='Z') i+='a'-'A';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
entries.push_back(newEntry);
|
2025-09-21 17:45:06 -05:00
|
|
|
if (stopReading) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
}
|
|
|
|
|
if (closedir(dir)!=0) {
|
|
|
|
|
// ?!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we're done - this is sufficient to show a file list (and sort by name)
|
|
|
|
|
haveFiles=true;
|
|
|
|
|
|
|
|
|
|
/// STAGE 2: retrieve file information
|
2025-09-21 17:45:06 -05:00
|
|
|
struct stat st;
|
|
|
|
|
String filePath;
|
|
|
|
|
for (FileEntry* i: entries) {
|
|
|
|
|
if (stopReading) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*path.rbegin()=='/') {
|
|
|
|
|
filePath=path+i->name;
|
|
|
|
|
} else {
|
|
|
|
|
filePath=path+'/'+i->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stat(filePath.c_str(),&st)<0) {
|
|
|
|
|
// fall back to unknown
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// read file information
|
2025-09-26 05:14:29 -05:00
|
|
|
entryLock.lock();
|
2025-09-21 17:45:06 -05:00
|
|
|
struct tm* retTM=localtime_r(&st.st_mtime,&i->time);
|
|
|
|
|
if (retTM!=NULL) {
|
|
|
|
|
i->hasTime=true;
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
|
2025-09-21 17:45:06 -05:00
|
|
|
i->size=st.st_size;
|
|
|
|
|
i->hasSize=true;
|
2025-09-26 05:14:29 -05:00
|
|
|
entryLock.unlock();
|
2025-09-21 17:45:06 -05:00
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
haveStat=true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FurnaceFilePicker::readDirectory(String path) {
|
|
|
|
|
if (fileThread!=NULL) {
|
|
|
|
|
// stop current file thread
|
|
|
|
|
stopReading=true;
|
|
|
|
|
fileThread->join();
|
|
|
|
|
delete fileThread;
|
|
|
|
|
fileThread=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clear all entries
|
|
|
|
|
sortedEntries.clear();
|
|
|
|
|
for (FileEntry* i: entries) {
|
|
|
|
|
delete i;
|
|
|
|
|
}
|
|
|
|
|
entries.clear();
|
2025-09-23 05:20:52 -05:00
|
|
|
chosenEntries.clear();
|
|
|
|
|
updateEntryName();
|
2025-09-21 05:48:30 -05:00
|
|
|
|
|
|
|
|
// start new file thread
|
|
|
|
|
this->path=path;
|
|
|
|
|
failMessage="";
|
|
|
|
|
haveFiles=false;
|
|
|
|
|
haveStat=false;
|
|
|
|
|
stopReading=false;
|
2025-09-23 01:31:49 -05:00
|
|
|
scheduledSort=1;
|
2025-09-21 05:48:30 -05:00
|
|
|
fileThread=new std::thread(_fileThread,this);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 01:31:49 -05:00
|
|
|
void FurnaceFilePicker::setHomeDir(String where) {
|
|
|
|
|
homeDir=where;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 05:20:52 -05:00
|
|
|
void FurnaceFilePicker::updateEntryName() {
|
|
|
|
|
if (chosenEntries.empty()) {
|
|
|
|
|
entryName="";
|
|
|
|
|
} else if (chosenEntries.size()>1) {
|
|
|
|
|
entryName="<multiple files selected>";
|
|
|
|
|
} else {
|
|
|
|
|
entryName=chosenEntries[0]->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 01:31:49 -05:00
|
|
|
void FurnaceFilePicker::sortFiles() {
|
2025-09-26 05:14:29 -05:00
|
|
|
std::chrono::high_resolution_clock::time_point timeStart=std::chrono::high_resolution_clock::now();
|
2025-09-23 01:31:49 -05:00
|
|
|
entryLock.lock();
|
|
|
|
|
sortedEntries=entries;
|
|
|
|
|
|
|
|
|
|
// sort by name
|
2025-09-26 05:14:29 -05:00
|
|
|
std::sort(sortedEntries.begin(),sortedEntries.end(),[this](const FileEntry* a, const FileEntry* b) -> bool {
|
2025-09-23 01:31:49 -05:00
|
|
|
if (a->isDir && !b->isDir) return true;
|
|
|
|
|
if (!a->isDir && b->isDir) return false;
|
|
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
switch (sortMode) {
|
|
|
|
|
case FP_SORT_NAME: {
|
|
|
|
|
// don't do anything. this is handled below.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FP_SORT_EXT: {
|
|
|
|
|
int result=a->ext.compare(b->ext);
|
|
|
|
|
// only sort if extensions differ
|
|
|
|
|
if (result!=0) {
|
|
|
|
|
return result<0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FP_SORT_SIZE: {
|
|
|
|
|
// only sort if sizes differ
|
|
|
|
|
if (a->size!=b->size) {
|
|
|
|
|
return a->size<b->size;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FP_SORT_DATE: {
|
|
|
|
|
// only sort if dates differ
|
|
|
|
|
if (a->time.tm_year==b->time.tm_year) {
|
|
|
|
|
if (a->time.tm_mon==b->time.tm_mon) {
|
|
|
|
|
if (a->time.tm_mday==b->time.tm_mday) {
|
|
|
|
|
if (a->time.tm_hour==b->time.tm_hour) {
|
|
|
|
|
if (a->time.tm_min==b->time.tm_min) {
|
|
|
|
|
if (a->time.tm_sec==b->time.tm_sec) {
|
|
|
|
|
// fall back to sorting by name
|
|
|
|
|
return a->nameLower<b->nameLower;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_sec<b->time.tm_sec;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_min<b->time.tm_min;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_hour<b->time.tm_hour;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_mday<b->time.tm_mday;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_mon<b->time.tm_mon;
|
|
|
|
|
}
|
|
|
|
|
return a->time.tm_year<b->time.tm_year;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-09-23 01:31:49 -05:00
|
|
|
}
|
2025-09-26 05:14:29 -05:00
|
|
|
|
|
|
|
|
// fall back to sorting by name
|
|
|
|
|
return a->nameLower<b->nameLower;
|
2025-09-23 01:31:49 -05:00
|
|
|
});
|
2025-09-26 05:14:29 -05:00
|
|
|
entryLock.unlock();
|
|
|
|
|
std::chrono::high_resolution_clock::time_point timeEnd=std::chrono::high_resolution_clock::now();
|
|
|
|
|
logV("sortFiles() took %dµs",std::chrono::duration_cast<std::chrono::microseconds>(timeEnd-timeStart).count());
|
2025-09-23 01:31:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FurnaceFilePicker::filterFiles() {
|
|
|
|
|
if (filter.empty()) {
|
|
|
|
|
filteredEntries=sortedEntries;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filteredEntries.clear();
|
|
|
|
|
|
|
|
|
|
String lowerFilter=filter;
|
|
|
|
|
for (char& i: lowerFilter) {
|
|
|
|
|
if (i>='A' && i<='Z') i+='a'-'A';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (FileEntry* i: sortedEntries) {
|
|
|
|
|
String lowerName=i->name;
|
|
|
|
|
for (char& j: lowerName) {
|
|
|
|
|
if (j>='A' && j<='Z') j+='a'-'A';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lowerName.find(lowerFilter)!=String::npos) {
|
|
|
|
|
filteredEntries.push_back(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
bool FurnaceFilePicker::draw() {
|
|
|
|
|
if (!isOpen) return false;
|
|
|
|
|
|
|
|
|
|
String newDir;
|
|
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(800.0,600.0),ImVec2(8000.0,6000.0));
|
|
|
|
|
if (ImGui::Begin(windowName.c_str(),NULL,ImGuiWindowFlags_NoSavedSettings)) {
|
2025-09-23 01:31:49 -05:00
|
|
|
if (ImGui::Button(ICON_FA_HOME "##HomeDir")) {
|
|
|
|
|
newDir=homeDir;
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
2025-09-21 05:48:30 -05:00
|
|
|
if (ImGui::Button(ICON_FA_CHEVRON_UP "##ParentDir")) {
|
|
|
|
|
size_t pos=path.rfind('/');
|
|
|
|
|
if (pos!=String::npos && path!="/") {
|
|
|
|
|
newDir=path.substr(0,pos);
|
|
|
|
|
if (newDir.empty()) newDir="/";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (!haveFiles) {
|
|
|
|
|
ImGui::Text("Loading... (%s)",path.c_str());
|
|
|
|
|
} else {
|
2025-09-23 05:20:52 -05:00
|
|
|
bool acknowledged=false;
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
if (haveStat) {
|
|
|
|
|
ImGui::Text("Hiya! (%s)",path.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("Loading... (%s)",path.c_str());
|
|
|
|
|
}
|
2025-09-23 01:31:49 -05:00
|
|
|
if (ImGui::Button(ICON_FA_REPEAT "##ClearFilter")) {
|
|
|
|
|
filter="";
|
|
|
|
|
filterFiles();
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
|
|
|
|
if (ImGui::InputTextWithHint("##Filter","Search",&filter)) {
|
|
|
|
|
filterFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scheduledSort) {
|
|
|
|
|
scheduledSort=0;
|
|
|
|
|
sortFiles();
|
|
|
|
|
filterFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImVec2 tableSize=ImGui::GetContentRegionAvail();
|
|
|
|
|
tableSize.y-=ImGui::GetFrameHeightWithSpacing()*2.0f;
|
2025-09-21 05:48:30 -05:00
|
|
|
|
2025-09-23 01:31:49 -05:00
|
|
|
if (filteredEntries.empty()) {
|
|
|
|
|
if (sortedEntries.empty()) {
|
|
|
|
|
if (failMessage.empty()) {
|
|
|
|
|
ImGui::Text("This directory is empty!");
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("Could not load this directory!\n(%s)",failMessage.c_str());
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
} else {
|
2025-09-23 01:31:49 -05:00
|
|
|
if (failMessage.empty()) {
|
|
|
|
|
ImGui::Text("No results");
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("Could not load this directory!\n(%s)",failMessage.c_str());
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-09-26 05:14:29 -05:00
|
|
|
// this is the list view. I might add other view modes in the future...
|
|
|
|
|
if (ImGui::BeginTable("FileList",4,ImGuiTableFlags_Borders|ImGuiTableFlags_ScrollY,tableSize)) {
|
2025-09-25 20:49:40 -05:00
|
|
|
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch);
|
2025-09-26 05:14:29 -05:00
|
|
|
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,ImGui::CalcTextSize(" .eeee").x);
|
|
|
|
|
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthFixed,ImGui::CalcTextSize(" 999.99G").x);
|
|
|
|
|
ImGui::TableSetupColumn("c3",ImGuiTableColumnFlags_WidthFixed,ImGui::CalcTextSize(" 6969/69/69 04:20").x);
|
2025-09-25 20:49:40 -05:00
|
|
|
ImGui::TableSetupScrollFreeze(0,1);
|
|
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
// header (sort options)
|
2025-09-25 20:49:40 -05:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
|
|
|
|
ImGui::TableNextColumn();
|
2025-09-26 05:14:29 -05:00
|
|
|
if (ImGui::Selectable("Name##SortName")) {
|
|
|
|
|
if (sortMode==FP_SORT_NAME) {
|
|
|
|
|
sortInvert=!sortInvert;
|
|
|
|
|
} else {
|
|
|
|
|
sortMode=FP_SORT_NAME;
|
|
|
|
|
scheduledSort=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (ImGui::Selectable("Type##SortType")) {
|
|
|
|
|
if (sortMode==FP_SORT_EXT) {
|
|
|
|
|
sortInvert=!sortInvert;
|
|
|
|
|
} else {
|
|
|
|
|
sortMode=FP_SORT_EXT;
|
|
|
|
|
scheduledSort=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-25 20:49:40 -05:00
|
|
|
ImGui::TableNextColumn();
|
2025-09-26 05:14:29 -05:00
|
|
|
if (ImGui::Selectable("Size##SortSize")) {
|
|
|
|
|
if (sortMode==FP_SORT_SIZE) {
|
|
|
|
|
sortInvert=!sortInvert;
|
|
|
|
|
} else {
|
|
|
|
|
sortMode=FP_SORT_SIZE;
|
|
|
|
|
scheduledSort=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-25 20:49:40 -05:00
|
|
|
ImGui::TableNextColumn();
|
2025-09-26 05:14:29 -05:00
|
|
|
if (ImGui::Selectable("Date##SortDate")) {
|
|
|
|
|
if (sortMode==FP_SORT_DATE) {
|
|
|
|
|
sortInvert=!sortInvert;
|
|
|
|
|
} else {
|
|
|
|
|
sortMode=FP_SORT_DATE;
|
|
|
|
|
scheduledSort=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-25 20:49:40 -05:00
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
// file list
|
2025-09-21 05:48:30 -05:00
|
|
|
entryLock.lock();
|
|
|
|
|
int index=0;
|
2025-09-23 01:31:49 -05:00
|
|
|
listClipper.Begin(filteredEntries.size());
|
2025-09-21 17:45:06 -05:00
|
|
|
while (listClipper.Step()) {
|
|
|
|
|
for (int _i=listClipper.DisplayStart; _i<listClipper.DisplayEnd; _i++) {
|
2025-09-26 05:14:29 -05:00
|
|
|
FileEntry* i=filteredEntries[sortInvert?(filteredEntries.size()-_i-1):_i];
|
2025-09-21 17:45:06 -05:00
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (i->type==FP_TYPE_DIR) {
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text,0xff00ffff);
|
|
|
|
|
}
|
|
|
|
|
ImGui::PushID(index++);
|
2025-09-24 01:25:28 -05:00
|
|
|
if (ImGui::Selectable("##File",i->isSelected,ImGuiSelectableFlags_AllowDoubleClick|ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_SpanAvailWidth)) {
|
2025-09-23 05:20:52 -05:00
|
|
|
for (FileEntry* j: chosenEntries) {
|
|
|
|
|
j->isSelected=false;
|
|
|
|
|
}
|
|
|
|
|
chosenEntries.clear();
|
|
|
|
|
chosenEntries.push_back(i);
|
|
|
|
|
i->isSelected=true;
|
|
|
|
|
updateEntryName();
|
2025-09-25 00:04:08 -05:00
|
|
|
if (isMobile) {
|
|
|
|
|
acknowledged=true;
|
|
|
|
|
} else if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
2025-09-23 05:20:52 -05:00
|
|
|
acknowledged=true;
|
2025-09-21 05:48:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-21 17:45:06 -05:00
|
|
|
ImGui::PopID();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::TextUnformatted(i->name.c_str());
|
|
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::TextUnformatted(i->ext.c_str());
|
|
|
|
|
|
2025-09-21 17:45:06 -05:00
|
|
|
ImGui::TableNextColumn();
|
2025-09-25 20:49:40 -05:00
|
|
|
if (i->hasSize && i->type==FP_TYPE_NORMAL) {
|
|
|
|
|
int sizeShift=0;
|
|
|
|
|
uint64_t sizeShifted=i->size;
|
|
|
|
|
|
|
|
|
|
while (sizeShifted && sizeShift<7) {
|
|
|
|
|
sizeShifted>>=10;
|
|
|
|
|
sizeShift++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sizeShift--;
|
|
|
|
|
|
|
|
|
|
uint64_t intPart=i->size>>(sizeShift*10);
|
|
|
|
|
uint64_t fracPart=i->size&((1U<<(sizeShift*10))-1);
|
|
|
|
|
// shift so we have sufficient digits for 100
|
|
|
|
|
// (precision loss is negligible)
|
|
|
|
|
if (sizeShift>0) {
|
|
|
|
|
fracPart=(100*(fracPart>>3))>>((sizeShift*10)-3);
|
|
|
|
|
if (fracPart>99) fracPart=99;
|
|
|
|
|
ImGui::Text("%" PRIu64 ".%02" PRIu64 "%c",intPart,fracPart,sizeSuffixes[sizeShift&7]);
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("%" PRIu64,i->size);
|
|
|
|
|
}
|
2025-09-21 17:45:06 -05:00
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
|
2025-09-21 17:45:06 -05:00
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (i->hasTime) {
|
|
|
|
|
ImGui::Text("%d/%02d/%02d %02d:%02d",i->time.tm_year+1900,i->time.tm_mon+1,i->time.tm_mday,i->time.tm_hour,i->time.tm_min);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i->type==FP_TYPE_DIR) {
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
entryLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-23 01:31:49 -05:00
|
|
|
|
|
|
|
|
ImGui::AlignTextToFramePadding();
|
|
|
|
|
ImGui::TextUnformatted("Name: ");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
|
|
|
|
if (ImGui::InputText("##EntryName",&entryName)) {
|
2025-09-25 00:04:08 -05:00
|
|
|
// find an entry with this name
|
|
|
|
|
|
|
|
|
|
|
2025-09-23 01:31:49 -05:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 05:20:52 -05:00
|
|
|
ImGui::BeginDisabled(chosenEntries.empty());
|
|
|
|
|
if (ImGui::Button("OK")) {
|
|
|
|
|
// accept entry
|
|
|
|
|
acknowledged=true;
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
2025-09-23 01:31:49 -05:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Cancel")) {
|
|
|
|
|
curStatus=FP_STATUS_CLOSED;
|
|
|
|
|
isOpen=false;
|
|
|
|
|
}
|
2025-09-23 05:20:52 -05:00
|
|
|
|
|
|
|
|
if (acknowledged) {
|
|
|
|
|
if (!chosenEntries.empty()) {
|
2025-09-24 01:25:28 -05:00
|
|
|
if (chosenEntries.size()==1 && chosenEntries[0]->isDir) {
|
|
|
|
|
// go there unless we've been required to select a directory
|
|
|
|
|
if (*path.rbegin()=='/') {
|
|
|
|
|
newDir=path+chosenEntries[0]->name;
|
|
|
|
|
} else {
|
|
|
|
|
newDir=path+'/'+chosenEntries[0]->name;
|
2025-09-23 05:20:52 -05:00
|
|
|
}
|
2025-09-24 01:25:28 -05:00
|
|
|
} else {
|
|
|
|
|
// select this entry
|
|
|
|
|
curStatus=FP_STATUS_ACCEPTED;
|
|
|
|
|
isOpen=false;
|
2025-09-23 05:20:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-21 05:48:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
if (!newDir.empty()) {
|
|
|
|
|
// change directory
|
|
|
|
|
readDirectory(newDir);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 05:14:29 -05:00
|
|
|
bool FurnaceFilePicker::open(String name, String path, bool modal, const std::vector<String>& filter) {
|
2025-09-21 05:48:30 -05:00
|
|
|
if (isOpen) return false;
|
|
|
|
|
|
|
|
|
|
readDirectory(path);
|
|
|
|
|
windowName=name;
|
|
|
|
|
isOpen=true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 00:04:08 -05:00
|
|
|
const String& FurnaceFilePicker::getEntryName() {
|
|
|
|
|
return entryName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FurnaceFilePicker::setMobile(bool val) {
|
|
|
|
|
isMobile=val;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 01:31:49 -05:00
|
|
|
FilePickerStatus FurnaceFilePicker::getStatus() {
|
|
|
|
|
FilePickerStatus retStatus=curStatus;
|
|
|
|
|
curStatus=FP_STATUS_WAITING;
|
|
|
|
|
return retStatus;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 05:20:52 -05:00
|
|
|
void FurnaceFilePicker::loadSettings(DivConfig& conf) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FurnaceFilePicker::saveSettings(DivConfig& conf) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 05:48:30 -05:00
|
|
|
FurnaceFilePicker::FurnaceFilePicker():
|
|
|
|
|
fileThread(NULL),
|
|
|
|
|
haveFiles(false),
|
|
|
|
|
haveStat(false),
|
|
|
|
|
stopReading(false),
|
2025-09-23 01:31:49 -05:00
|
|
|
isOpen(false),
|
2025-09-25 00:04:08 -05:00
|
|
|
isMobile(false),
|
2025-09-26 05:14:29 -05:00
|
|
|
sortInvert(false),
|
2025-09-23 01:31:49 -05:00
|
|
|
scheduledSort(0),
|
2025-09-26 05:14:29 -05:00
|
|
|
sortMode(FP_SORT_NAME),
|
2025-09-23 01:31:49 -05:00
|
|
|
curStatus(FP_STATUS_WAITING) {
|
2025-09-21 05:48:30 -05:00
|
|
|
|
2025-09-21 17:45:06 -05:00
|
|
|
}
|