90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
/// Josh's User Interface Library
|
|
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
|
|
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
|
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
|
/// (c) 2024 Redacted Software
|
|
/// This work is dedicated to the public domain.
|
|
|
|
/// @file FileDialog.hpp
|
|
/// @desc A dialog window that shows a selection of files on disk, and a form for naming, used for file loading and saving.
|
|
|
|
/// @edit 2024-5-29
|
|
|
|
#pragma once
|
|
|
|
#include <JUI/Widgets/Window.hpp>
|
|
#include <JUI/Widgets/UtilityBar.hpp>
|
|
#include <JUI/Widgets/ScrollingRect.hpp>
|
|
|
|
namespace JUI
|
|
{
|
|
class FileListing : public JUI::Widget { };
|
|
|
|
class FileDialogWindow : public JUI::Window
|
|
{
|
|
public:
|
|
Event<> UserCompleted;
|
|
Event<> UserConfirmed;
|
|
Event<> UserCancelled;
|
|
FileDialogWindow() : Window() {
|
|
auto* toolbar = new JUI::UtilityBar(this->Content());
|
|
|
|
auto* file_listing = new JUI::Rect(this->Content());
|
|
file_listing->Size({100_percent, 100_percent-20_px});
|
|
|
|
file_layout = new JUI::VerticalListLayout(file_listing);
|
|
}
|
|
|
|
/// Tree system
|
|
|
|
JUI::Rect* CreateFileEntry(const std::filesystem::directory_entry& entry) {
|
|
auto* rect = new JUI::TextRect(file_layout);
|
|
rect->Size({100_percent, 20_px});
|
|
|
|
std::string entry_type = entry.is_directory() ? "directory" : "file";
|
|
std::string perms = stringify(entry.status().permissions());
|
|
std::string type = stringify(entry.status().type());
|
|
|
|
auto file_size = (entry.is_directory() ? entry.file_size() : 0 );
|
|
|
|
std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), entry.file_size(), perms, entry.last_write_time(), type);
|
|
|
|
rect->Content(entry.path().filename());
|
|
|
|
|
|
if (entry.is_directory()) {
|
|
|
|
}
|
|
|
|
return rect;
|
|
}
|
|
|
|
|
|
FileDialogWindow(const std::filesystem::path& root) : FileDialogWindow() {
|
|
std::cout << root.relative_path() << std::endl;
|
|
std::cout << root.root_directory() << std::endl;
|
|
for (const auto& entry: std::filesystem::directory_iterator(root)) {
|
|
|
|
CreateFileEntry(entry);
|
|
}
|
|
}
|
|
explicit FileDialogWindow(Widget* parent, const std::filesystem::path& root) : FileDialogWindow(root)
|
|
{
|
|
Parent(parent);
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
VerticalListLayout* file_layout;
|
|
std::vector<Rect*> file_entry_widgets;
|
|
private:
|
|
};
|
|
|
|
|
|
class OpenFileDialogWindow : public JUI::Window { };
|
|
class SaveFileDialogWindow : public JUI::Window { };
|
|
class SelectFolderDialog : public JUI::Window { };
|
|
|
|
} |