Movimiento por carpetas/1 steam x dir
This commit is contained in:
parent
564f840936
commit
54bd3a914e
1 changed files with 45 additions and 14 deletions
59
main.cpp
59
main.cpp
|
|
@ -23,17 +23,25 @@ static void glfw_error_callback(int error, const char* description)
|
||||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FILE PICKER MOMENTO */
|
||||||
|
|
||||||
bool retrieveCurrentDirectory(char** currentPath){
|
bool retrieveCurrentDirectory(char** currentPath){
|
||||||
if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true;
|
if(GetCurrentDirectory(MAX_PATH, *currentPath)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool moveDirectory(char** currentPath){
|
||||||
|
if(SetCurrentDirectory(*currentPath)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
||||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||||
WIN32_FIND_DATA ffd;
|
WIN32_FIND_DATA ffd;
|
||||||
LARGE_INTEGER filesize;
|
LARGE_INTEGER filesize;
|
||||||
int numFiles = 0;
|
int numFiles = 0;
|
||||||
|
|
||||||
if (path.length() > (MAX_PATH - 3)) return -1;
|
if (path.length() > (MAX_PATH - 3)) return -1;
|
||||||
path = path + "\\*";
|
path = path + "\\*";
|
||||||
hFind = FindFirstFile(path.c_str(), &ffd);
|
hFind = FindFirstFile(path.c_str(), &ffd);
|
||||||
|
|
@ -54,12 +62,12 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
||||||
} while (ffd.cFileName[idx]);
|
} while (ffd.cFileName[idx]);
|
||||||
|
|
||||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
strcat(itemPath, " <DIR>");
|
//strcat(itemPath, " <DIR>");
|
||||||
} else {
|
} else {
|
||||||
filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow);
|
// filesize.QuadPart = ((ffd.nFileSizeHigh * (MAXDWORD+1)) + ffd.nFileSizeLow);
|
||||||
char buf[16]; buf[0] = ' ';
|
// char buf[16]; buf[0] = ' ';
|
||||||
itoa(filesize.QuadPart, buf + 1 , 10 );
|
// itoa(filesize.QuadPart, buf + 1 , 10 );
|
||||||
strcat(itemPath, buf);
|
// strcat(itemPath, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
numFiles++;
|
numFiles++;
|
||||||
|
|
@ -68,6 +76,7 @@ int listDirectory(std::string path, std::vector<char*> *directoryContents){
|
||||||
return numFiles;
|
return numFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIN FILE PICKER MOMENTO */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -188,28 +197,50 @@ int main(int, char**)
|
||||||
{
|
{
|
||||||
ImGui::Begin("File Picker in 4K");
|
ImGui::Begin("File Picker in 4K");
|
||||||
|
|
||||||
//cursed C momento
|
//cursed C momento: necesario ptr en otra var para mandar a char** de firma
|
||||||
|
static bool renderList = true;
|
||||||
static char currentPath[MAX_PATH];
|
static char currentPath[MAX_PATH];
|
||||||
char* ptr = ¤tPath[0];
|
static char* ptr = ¤tPath[0];
|
||||||
|
|
||||||
static int currentItemIdx = 0;
|
static int currentItemIdx = -1;
|
||||||
|
static std::vector<char*> displayContents;
|
||||||
std::vector<char*> directoryContents;
|
std::vector<char*> directoryContents;
|
||||||
|
ImGui::Text("%s primir", currentPath);
|
||||||
|
static int numFiles = 0;
|
||||||
|
|
||||||
if(!retrieveCurrentDirectory(&ptr)) goto filepickerFailure;
|
if(renderList) {
|
||||||
|
renderList = false;
|
||||||
|
if(!retrieveCurrentDirectory(&ptr))
|
||||||
|
goto filepickerFailure;
|
||||||
|
//
|
||||||
|
numFiles = (listDirectory(std::string(currentPath), &directoryContents));
|
||||||
|
//std::cout << numFiles;
|
||||||
|
if (numFiles < 0)
|
||||||
|
goto filepickerFailure;
|
||||||
|
displayContents = std::move(directoryContents);
|
||||||
|
}
|
||||||
|
|
||||||
if(int numFiles = (listDirectory(".", &directoryContents))){
|
if(numFiles > 0){
|
||||||
ImGui::Text("Select a file:");
|
ImGui::Text("Select a file:");
|
||||||
|
//TODO quitar
|
||||||
|
ImGui::Text("%s %d", currentPath, currentItemIdx);
|
||||||
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){
|
||||||
for (int i = 0; i < numFiles; i++) {
|
for (int i = 0; i < numFiles; i++) {
|
||||||
// ImGui::Selectable(directoryContents.at(i), false);
|
// ImGui::Selectable(directoryContents.at(i), false);
|
||||||
|
|
||||||
const bool isSelected = (currentItemIdx == i);
|
const bool isSelected = (currentItemIdx == i);
|
||||||
if (ImGui::Selectable(directoryContents.at(i), isSelected))
|
if (ImGui::Selectable(displayContents.at(i), isSelected))
|
||||||
currentItemIdx = i;
|
currentItemIdx = i;
|
||||||
|
|
||||||
//Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
//Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||||
if (isSelected)
|
if (isSelected) {
|
||||||
ImGui::SetItemDefaultFocus();
|
strcat(currentPath, "\\");
|
||||||
|
strcat(currentPath, displayContents.at(i));
|
||||||
|
moveDirectory(&ptr);
|
||||||
|
currentItemIdx = -1;
|
||||||
|
renderList = true;
|
||||||
|
}
|
||||||
|
//ImGui::SetItemDefaultFocus();
|
||||||
|
|
||||||
}
|
}
|
||||||
ImGui::EndListBox();
|
ImGui::EndListBox();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue