diff --git a/include/JUI/Widgets/FileDialog.hpp b/include/JUI/Widgets/FileDialog.hpp index 66572ed..6f9be05 100644 --- a/include/JUI/Widgets/FileDialog.hpp +++ b/include/JUI/Widgets/FileDialog.hpp @@ -27,13 +27,14 @@ namespace JUI Event<> UserCompleted; Event<> UserConfirmed; Event<> UserCancelled; + Event FileSelected; FileDialogWindow() : Window() { Title("File Dialog"); - auto* toolbar = new JUI::UtilityBar(this->Content()); + //auto* toolbar = new JUI::UtilityBar(this->Content()); - auto* file_listing = new JUI::Rect(this->Content()); + auto* file_listing = new JUI::ScrollingRect(this->Content()); file_listing->Size({100_percent, 100_percent-20_px}); file_layout = new JUI::VerticalListLayout(file_listing); @@ -82,7 +83,8 @@ namespace JUI JUI::Rect* CreateFileEntry(const std::filesystem::directory_entry& entry) { - auto* rect = new JUI::TextRect(file_layout); + auto* rect = new JUI::TextButton(file_layout); + rect->LayoutOrder(index); rect->Size({100_percent, 20_px}); std::string entry_type = entry.is_directory() ? "directory" : "file"; @@ -95,11 +97,17 @@ namespace JUI std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), file_size_str, entry_type, perms, timestamp); rect->Content(label); + rect->BaseBGColor(Colors::Gray); + + index++; + + rect->Clicked += [this, entry] (auto ev) mutable { + FileSelected(entry.path().string()); + }; return rect; } - FileDialogWindow(const std::filesystem::path& root) : FileDialogWindow() { std::cout << root.relative_path() << std::endl; std::cout << root.root_directory() << std::endl; @@ -120,11 +128,15 @@ namespace JUI Parent(parent); } - + void SetSelectedFile(const std::string& filename); + void SetConfirmOverwrite(bool confirm); + void SetBlockingWhileOpen(bool blocking); + bool GetBlockingWhileOpen() const; protected: int directories_indexed = 0; + int index = 0; VerticalListLayout* file_layout; std::vector file_entry_widgets; private: