summaryrefslogtreecommitdiff
path: root/src/file_dialog.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-28 20:32:18 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-28 20:32:18 -0500
commit6f44617d0a378d980de71e6a5e1d634bff95bbcb (patch)
treec0e87f9c9ef581d165c97dc7fb2553c383187453 /src/file_dialog.cpp
parent876c829512301e3f20161f05d7c193540e6d1710 (diff)
Flesh out dialog.
Diffstat (limited to 'src/file_dialog.cpp')
-rw-r--r--src/file_dialog.cpp51
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