fix some file selector glitches

This commit is contained in:
Green Sky 2024-02-08 18:11:51 +01:00
parent b56d581e4b
commit ff5dbaffc0
No known key found for this signature in database
3 changed files with 12 additions and 5 deletions

View File

@ -737,7 +737,11 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
) { ) {
if (ImGui::Button("save to")) { if (ImGui::Button("save to")) {
_fss.requestFile( _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, &reg, e](const auto& path) { [this, &reg, e](const auto& path) {
if (reg.valid(e)) { // still valid if (reg.valid(e)) { // still valid
// TODO: trim file? // TODO: trim file?

View File

@ -18,7 +18,7 @@ FileSelector::FileSelector(void) {
} }
void FileSelector::requestFile( void FileSelector::requestFile(
std::function<bool(const std::filesystem::path& path)>&& is_valid, std::function<bool(std::filesystem::path& path)>&& is_valid,
std::function<void(const std::filesystem::path& path)>&& on_choose, std::function<void(const std::filesystem::path& path)>&& on_choose,
std::function<void(void)>&& on_cancel std::function<void(void)>&& on_cancel
) { ) {
@ -77,7 +77,9 @@ void FileSelector::render(void) {
if (current_path.has_parent_path()) { if (current_path.has_parent_path()) {
if (ImGui::TableNextColumn()) { if (ImGui::TableNextColumn()) {
if (ImGui::Selectable("D##..", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) { 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() / "";
} }
} }

View File

@ -8,7 +8,7 @@ struct FileSelector {
bool _open_popup {false}; bool _open_popup {false};
std::function<bool(const std::filesystem::path& path)> _is_valid = [](auto){ return true; }; std::function<bool(std::filesystem::path& path)> _is_valid = [](auto){ return true; };
std::function<void(const std::filesystem::path& path)> _on_choose = [](auto){}; std::function<void(const std::filesystem::path& path)> _on_choose = [](auto){};
std::function<void(void)> _on_cancel = [](){}; std::function<void(void)> _on_cancel = [](){};
@ -18,8 +18,9 @@ struct FileSelector {
FileSelector(void); FileSelector(void);
// TODO: supply hints // TODO: supply hints
// HACK: until we supply hints, is_valid can modify
void requestFile( void requestFile(
std::function<bool(const std::filesystem::path& path)>&& is_valid, std::function<bool(std::filesystem::path& path)>&& is_valid,
std::function<void(const std::filesystem::path& path)>&& on_choose, std::function<void(const std::filesystem::path& path)>&& on_choose,
std::function<void(void)>&& on_cancel std::function<void(void)>&& on_cancel
); );