From 6f44617d0a378d980de71e6a5e1d634bff95bbcb Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 28 Sep 2024 20:32:18 -0500 Subject: Flesh out dialog. --- src/bookmouse.cpp | 83 +++++++------------------------------------------------ 1 file changed, 10 insertions(+), 73 deletions(-) (limited to 'src/bookmouse.cpp') diff --git a/src/bookmouse.cpp b/src/bookmouse.cpp index 2e13b4e..d367af1 100644 --- a/src/bookmouse.cpp +++ b/src/bookmouse.cpp @@ -107,9 +107,9 @@ void Bookmouse::updateState() // m_imgui.getIO().AddKeyEvent() - if (ImGui::IsKeyPressed(ImGuiKey_O) && m_imgui.getIO().KeyCtrl && !m_openDialog) { - m_openDialog = true; - } + // if (ImGui::IsKeyPressed(ImGuiKey_O) && m_imgui.getIO().KeyCtrl && !m_openDialog) { + // m_openDialog = true; + // } if (ImMenuBar menuBar{}) { IM_ASSERT(menuBar); @@ -176,83 +176,20 @@ void Bookmouse::openDialog() ImGui::CloseCurrentPopup(); } } -} - -void Bookmouse::openDialog2() -{ - if (m_getContents) { - m_getContents = false; - - m_directoryName = fud::String{"./"}; - m_directory = fud::Directory{m_directoryName}; - - auto directoryStatsResult = m_directory.info(); - if (directoryStatsResult.isError()) { - m_openDialog = false; - ImGui::CloseCurrentPopup(); - } - auto directoryStats = directoryStatsResult.getOkay(); - size_t count{0}; - m_directoryContents.reserve(directoryStats.links); + auto result = m_fileDialog->pickFiles(); - while (true && count < SIZE_MAX) { - auto dirEntryResult = m_directory.getNextEntry(); - if (dirEntryResult.isError()) { - break; - } - - auto dirEntryOpt = dirEntryResult.getOkay(); - if (dirEntryOpt == std::nullopt) { - break; - } - - if (dirEntryOpt->inode == directoryStats.inode) { - continue; - } - - m_directoryContents.emplace_back(std::move(*dirEntryOpt)); - auto status = m_directoryContents.back().formatTime(m_timeFormat); - if (status != FudStatus::Success) { - spdlog::error("Could not convert time: {}", fud::FudStatusToString(status)); - } + if (result != std::nullopt) { + auto selectedFiles = *result; + for (const auto& name : selectedFiles) { + spdlog::info("Selected {}", name.c_str()); } - } - - ImText("%s %zu", m_directory.name().c_str(), m_directoryContents.size()); - if (ImTable table{"Entries", 4, ImGuiTableFlags_Borders}) { - auto colFlags = ImGuiSelectableFlags_NoAutoClosePopups; - IM_ASSERT(table); - ImNextColumn(); - ImSelectable("T", &m_typeSelected, colFlags); - ImNextColumn(); - ImSelectable("Name", &m_nameSelectede, colFlags); - ImNextColumn(); - ImSelectable("Size", &m_sizeSelected, colFlags); - ImNextColumn(); - ImSelectable("Date", &m_dateSelected, colFlags); - for (auto& entry : m_directoryContents) { - ImNextRow(); - const char entryLetter = DirEntryTypeToChar(entry.entryType); - ImNextColumn(); - ImText("%c", entryLetter); - ImNextColumn(); - ImSelectable(entry.name.c_str(), &entry.selected, colFlags | ImGuiSelectableFlags_SpanAllColumns); - ImNextColumn(); - ImText("%zu\n", entry.isDirectory() ? entry.links : entry.size); - ImNextColumn(); - ImText("%s", entry.niceTime.c_str()); - } - } - - if (ImButton("Accept")) { m_openDialog = false; ImGui::CloseCurrentPopup(); + return; } - ImSameLine(); - - if (ImButton("Cancel")) { + if (m_fileDialog->canceled()) { m_openDialog = false; ImGui::CloseCurrentPopup(); } -- cgit v1.2.3