diff --git a/release-notes.md b/release-notes.md index c12255b39..45dd61cf8 100644 --- a/release-notes.md +++ b/release-notes.md @@ -5,6 +5,7 @@ * Fix file deletion to close file even if not active * Fix file copy to work when creating a copy with the name of a previously deleted file +* Make file picker popup accept on double click of a file * PaletteEditor: Add RGB key shortcuts for focusing color channels * PaletteEditor: Add color preview to color editor * PaletteEditor: Make RGB key shortcuts work when color channel inputs are diff --git a/src/olympic/studio/modlib/include/studio/filepickerpopup.hpp b/src/olympic/studio/modlib/include/studio/filepickerpopup.hpp index 94708e561..acbebceab 100644 --- a/src/olympic/studio/modlib/include/studio/filepickerpopup.hpp +++ b/src/olympic/studio/modlib/include/studio/filepickerpopup.hpp @@ -13,7 +13,11 @@ class FilePickerPopup { private: ox::String m_name; - FileExplorer m_explorer; + struct Explorer: public FileExplorer { + mutable bool opened{}; + explicit Explorer(keel::Context &kctx); + void fileOpened(ox::StringViewCR path) const noexcept override; + } m_explorer; ox::Vector const m_fileExts; bool m_open{}; @@ -33,6 +37,10 @@ class FilePickerPopup { ox::Optional draw(Context &ctx) noexcept; + private: + [[nodiscard]] + ox::Optional handlePick() noexcept; + }; } diff --git a/src/olympic/studio/modlib/src/filepickerpopup.cpp b/src/olympic/studio/modlib/src/filepickerpopup.cpp index 2b499fe29..e4390ff63 100644 --- a/src/olympic/studio/modlib/src/filepickerpopup.cpp +++ b/src/olympic/studio/modlib/src/filepickerpopup.cpp @@ -8,6 +8,15 @@ namespace studio { +FilePickerPopup::Explorer::Explorer(keel::Context &kctx): + FileExplorer{kctx} { +} + +void FilePickerPopup::Explorer::fileOpened(ox::StringViewCR) const noexcept { + opened = true; +} + + FilePickerPopup::FilePickerPopup( ox::StringParam name, keel::Context &kctx, @@ -41,6 +50,7 @@ void FilePickerPopup::refresh() noexcept { void FilePickerPopup::open() noexcept { refresh(); m_open = true; + m_explorer.opened = false; } void FilePickerPopup::close() noexcept { @@ -60,16 +70,22 @@ ox::Optional FilePickerPopup::draw(Context &ctx) noexcept { if (ig::BeginPopup(ctx.tctx, m_name, m_open, {380, 340})) { auto const vp = ImGui::GetContentRegionAvail(); m_explorer.draw(ctx, {vp.x, vp.y - 30}); - if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK) { - auto p = m_explorer.selectedPath(); - if (p) { - out.emplace(*p); - } - close(); + if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK || m_explorer.opened) { + out = handlePick(); } ImGui::EndPopup(); } return out; } +ox::Optional FilePickerPopup::handlePick() noexcept { + ox::Optional out; + auto p = m_explorer.selectedPath(); + if (p) { + out.emplace(*p); + } + close(); + return out; +} + }