[studio] Make FilePickerPopup accept on double click of a file
All checks were successful
Build / build (push) Successful in 1m22s

This commit is contained in:
2025-06-20 23:57:53 -05:00
parent 8838bf420e
commit 58e0ecb469
3 changed files with 32 additions and 7 deletions

View File

@ -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

View File

@ -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<ox::String> const m_fileExts;
bool m_open{};
@ -33,6 +37,10 @@ class FilePickerPopup {
ox::Optional<ox::String> draw(Context &ctx) noexcept;
private:
[[nodiscard]]
ox::Optional<ox::String> handlePick() noexcept;
};
}

View File

@ -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<ox::String> 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<ox::String> FilePickerPopup::handlePick() noexcept {
ox::Optional<ox::String> out;
auto p = m_explorer.selectedPath();
if (p) {
out.emplace(*p);
}
close();
return out;
}
}