removed scrolling due to bug + Fixed file source

This commit is contained in:
Ryzerth
2021-02-07 23:47:17 +01:00
parent 49ec3d68d2
commit 9df90e5e75
37 changed files with 11910 additions and 3792 deletions

View File

@@ -3,14 +3,14 @@
#include <options.h>
#include <filesystem>
FileSelect::FileSelect(std::string defaultPath, char* filter) {
FileSelect::FileSelect(std::string defaultPath) {
path = defaultPath;
strcpy(_filter, filter);
pathValid = std::filesystem::is_regular_file(path);
strcpy(strPath, path.c_str());
}
void FileSelect::render(std::string id) {
bool FileSelect::render(std::string id) {
bool _pathChanged = false;
#ifdef _WIN32
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
float buttonWidth = ImGui::CalcTextSize("...").x + 20.0f;
@@ -59,6 +59,15 @@ void FileSelect::render(std::string id) {
ImGui::PopStyleColor();
}
#endif
_pathChanged |= pathChanged;
pathChanged = false;
return _pathChanged;
}
void FileSelect::setPath(std::string path) {
this->path = path;
pathValid = std::filesystem::is_regular_file(path);
strcpy(strPath, path.c_str());
}
std::string FileSelect::expandString(std::string input) {
@@ -70,45 +79,35 @@ bool FileSelect::pathIsValid() {
return pathValid;
}
bool FileSelect::pathChanged() {
if (_pathChanged) {
_pathChanged = false;
return true;
}
return false;
#ifdef _WIN32
void FileSelect::setWindowsFilter(COMDLG_FILTERSPEC* filt, int n) {
filter = filt;
filterCount = n;
}
#ifdef _WIN32
void FileSelect::windowsWorker() {
OPENFILENAMEA ofn; // common dialog box structure
char szFile[2048]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
IFileOpenDialog *pFileOpen;
HRESULT hr;
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetFocus();
ofn.lpstrFile = (LPSTR)szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = (LPCSTR)_filter;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXTENSIONDIFFERENT;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (filter != NULL) { pFileOpen->SetFileTypes(filterCount, filter); }
// Display the Open dialog box.
if (GetOpenFileNameA(&ofn)==TRUE) {
strcpy(strPath, szFile);
_pathChanged = true;
hr = pFileOpen->Show(NULL);
if (SUCCEEDED(hr)) {
PWSTR pszFilePath;
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
wcstombs(strPath, pszFilePath, 2048);
CoTaskMemFree(pszFilePath);
path = std::string(strPath);
pathChanged = true;
}
pathValid = std::filesystem::is_regular_file(strPath);
pathValid = std::filesystem::is_regular_file(path);
dialogOpen = false;
}
#endif