You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lunarium_OLD/src/internal_libs/gui/file_browser.h

84 lines
2.2 KiB
C++

/******************************************************************************
* File - fileBrowser.h
* Author - Joey Pollack
* Date - 2021/11/04 (y/m/d)
* Mod Date - 2021/11/04 (y/m/d)
* Description - File browser dialog window. Can be used for opening
* and saving files.
******************************************************************************/
// Some useful links:
// https://en.cppreference.com/w/cpp/filesystem/is_directory
// https://en.cppreference.com/w/cpp/filesystem/path
#ifndef FILE_SELECT_H_
#define FILE_SELECT_H_
#include <utils/opRes.h>
#include <vector>
#include <filesystem>
namespace lunarium
{
class Image;
class FileBrowser
{
public:
enum Result
{
OK,
CANCEL,
STILL_WAITING // TODO: Implement STILL_WAITING
};
enum SelectionMode
{
FILES_ONLY,
DIRECTORIES_ONLY,
ANY,
};
public:
FileBrowser();
bool OpenInDirectory(std::filesystem::path path);
bool DoFrame();
bool IsOpen() const;
void Close();
void SetPrompt(std::string prompt);
void AddExtensionFilter(std::string ext);
void SetSelectionMode(SelectionMode mode);
void WarnOnExistingFileSelection(bool warn);
// returns nullptr if the dialog has not been opened yet
const std::filesystem::path* GetSelectedItem() const;
Result GetResult() const;
private:
bool mIsOpen;
SelectionMode mSelectionMode;
bool mWarnOnExisting;
Result mResult;
std::string mPrompt;
std::filesystem::path mCurrentDirectory;
std::vector<std::filesystem::path> mItemsInDir;
std::vector<std::string> mExtensionsFilter; // Show only these extensions. If empty show all files.
std::filesystem::path* mpSelectedItem;
std::filesystem::path mInputSelection;
static const int mBufferSize = 256;
char mDirNameBuffer[mBufferSize];
char mInputBuffer[mBufferSize];
private:
void ReloadItems();
void DoListBox();
bool DoButtons();
};
}
#endif // FILE_SELECT_H_