diff options
Diffstat (limited to 'src/file_dialog.cpp')
-rw-r--r-- | src/file_dialog.cpp | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/src/file_dialog.cpp b/src/file_dialog.cpp index faab3e7..80e994d 100644 --- a/src/file_dialog.cpp +++ b/src/file_dialog.cpp @@ -1,8 +1,8 @@ #include "file_dialog.hpp" + #include "imgui_context.hpp" #include <imgui/imgui.h> - #include <spdlog/spdlog.h> namespace bookmouse { @@ -27,8 +27,7 @@ FudStatus DialogEntry::formatTime(TimeFormat& format) } auto result = format.format(this->timeInfo); - if (result.isError()) - { + if (result.isError()) { return result.getError(); } @@ -37,11 +36,8 @@ FudStatus DialogEntry::formatTime(TimeFormat& format) return FudStatus::Success; } -FileDialog::FileDialog( - const fud::String& directoryName, - TimeFormat& timeFormat) : m_directoryName{directoryName}, - m_directory{directoryName}, - m_timeFormat{timeFormat} +FileDialog::FileDialog(const fud::String& directoryName, TimeFormat& timeFormat) : + m_directoryName{directoryName}, m_directory{directoryName}, m_timeFormat{timeFormat} { auto status = getDirectoryContents(); if (status != FudStatus::Success) { @@ -49,13 +45,16 @@ FileDialog::FileDialog( } } -FudStatus FileDialog::getDirectoryContents() { +FudStatus FileDialog::getDirectoryContents() +{ auto directoryStatsResult = m_directory.info(); if (directoryStatsResult.isError()) { return directoryStatsResult.getError(); } auto directoryStats = directoryStatsResult.getOkay(); + m_directoryContents.clear(); + size_t count{0}; m_directoryContents.reserve(directoryStats.links); @@ -87,6 +86,7 @@ FudStatus FileDialog::getDirectoryContents() { FilePickerResult FileDialog::pickFiles() { ImText("%s %zu", m_directory.name().c_str(), m_directoryContents.size()); + size_t selected{0}; if (ImTable table{"Entries", 4, ImGuiTableFlags_Borders}) { auto colFlags = ImGuiSelectableFlags_NoAutoClosePopups; IM_ASSERT(table); @@ -109,21 +109,46 @@ FilePickerResult FileDialog::pickFiles() ImText("%zu\n", entry.isDirectory() ? entry.links : entry.size); ImNextColumn(); ImText("%s", entry.niceTime.c_str()); + if (entry.selected && entry.isDirectory()) { + selected++; + } } } + if (selected == 0) { + ImGui::BeginDisabled(); + } + if (ImButton("Accept")) { - return FilePickerResult::error(FudStatus::NotImplemented); + std::vector<fud::String> files{}; + files.reserve(selected); + + for (const auto& entry: m_directoryContents) { + if (!entry.selected) { + continue; + } + if (entry.isDirectory()) { + spdlog::info("Skipping directory {}", entry.name.c_str()); + continue; + } + files.emplace_back(m_directory.name().catenate(entry.name)); + } + + return files; + } + + if (selected == 0) { + ImGui::EndDisabled(); } ImSameLine(); if (ImButton("Cancel")) { - return FilePickerResult::error(FudStatus::NotImplemented); + m_canceled = true; + return std::nullopt; } - - return FilePickerResult::error(FudStatus::NotImplemented); + return std::nullopt; } } // namespace bookmouse |