From ff5dbaffc03d2d8708306c29874867476c482c6d Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 8 Feb 2024 18:11:51 +0100 Subject: [PATCH] fix some file selector glitches --- src/chat_gui4.cpp | 6 +++++- src/file_selector.cpp | 6 ++++-- src/file_selector.hpp | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index fab54bc..227a75e 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -737,7 +737,11 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { ) { if (ImGui::Button("save to")) { _fss.requestFile( - [](const auto& path) -> bool { return std::filesystem::is_directory(path); }, + [](std::filesystem::path& path) -> bool { + // remove file path + path.remove_filename(); + return std::filesystem::is_directory(path); + }, [this, ®, e](const auto& path) { if (reg.valid(e)) { // still valid // TODO: trim file? diff --git a/src/file_selector.cpp b/src/file_selector.cpp index cc5a7d2..05ca9c0 100644 --- a/src/file_selector.cpp +++ b/src/file_selector.cpp @@ -18,7 +18,7 @@ FileSelector::FileSelector(void) { } void FileSelector::requestFile( - std::function&& is_valid, + std::function&& is_valid, std::function&& on_choose, std::function&& on_cancel ) { @@ -77,7 +77,9 @@ void FileSelector::render(void) { if (current_path.has_parent_path()) { if (ImGui::TableNextColumn()) { if (ImGui::Selectable("D##..", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) { - _current_file_path = _current_file_path.parent_path(); + // the first "parent_path()" only removes the filename and the ending "/" + _current_file_path = _current_file_path.parent_path().parent_path() / ""; + //_current_file_path = _current_file_path.remove_filename().parent_path() / ""; } } diff --git a/src/file_selector.hpp b/src/file_selector.hpp index 2a783a9..33620bf 100644 --- a/src/file_selector.hpp +++ b/src/file_selector.hpp @@ -8,7 +8,7 @@ struct FileSelector { bool _open_popup {false}; - std::function _is_valid = [](auto){ return true; }; + std::function _is_valid = [](auto){ return true; }; std::function _on_choose = [](auto){}; std::function _on_cancel = [](){}; @@ -18,8 +18,9 @@ struct FileSelector { FileSelector(void); // TODO: supply hints + // HACK: until we supply hints, is_valid can modify void requestFile( - std::function&& is_valid, + std::function&& is_valid, std::function&& on_choose, std::function&& on_cancel );