10#if !defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
33 throw std::runtime_error(
"Could not get the current working directory. Is the filesystem readable?");
48 if (ImGui::BeginCombo(
"##FilesystemCombo", preview.
c_str(), ImGuiComboFlags_HeightLarge)) {
49 if (ImGui::IsWindowAppearing()) {
50 ImGui::SetKeyboardFocusHere();
54 changed = draw_combo_body(selected_path);
57 app->increment_forced_frames();
65 const bool is_directory_hint
71 flags(
is_directory ? ImGuiSelectableFlags_NoAutoClosePopups : ImGuiSelectableFlags_None)
95 std::filesystem::directory_options::skip_permission_denied |
96 std::filesystem::directory_options::follow_directory_symlink,
102 while (!error_code && iterator != end) {
107 if (!entry_error_code) {
113 if (is_directory || is_regular_file)
114 entries.emplace_back(directory_entry.
path(), is_directory);
136bool FilesystemCombo::draw_combo_body(
142 const bool enter_pressed =
145 bool changed =
false;
159 ImGui::CloseCurrentPopup();
165 ImGui::TextDisabled(
"Not a readable directory.");
177FilesystemCombo::BrowseTarget FilesystemCombo::get_browse_target()
const
179 std::error_code error_code;
181 auto const typed_path = typed_string.
empty() ? std::filesystem::path{} : std::filesystem::path{typed_string};
182 auto lookup_path = typed_path;
184 if (lookup_path.empty())
186 else if (lookup_path.is_relative())
189 if (error_code || lookup_path.empty())
195 return {.target_path = lookup_path, .parent_directory = lookup_path, .filter = {}};
197 std::filesystem::path directory = lookup_path.parent_path();
199 if (directory.
empty()) {
203 if (error_code || directory.
empty())
207 return {.target_path = lookup_path, .parent_directory = directory, .filter = lookup_path.
filename().string()};
210bool FilesystemCombo::draw_parent_entry(
211 const std::filesystem::path& directory
214 const std::filesystem::path parent = directory.
parent_path();
216 if (parent.
empty() || parent == directory)
219 if (ImGui::Selectable(
"../",
false, ImGuiSelectableFlags_NoAutoClosePopups)) {
227bool FilesystemCombo::draw_child_entries(
228 const std::string_view filter,
229 std::filesystem::path& selected_path
232 assert(
cache.has_value());
234 bool has_visible_entries =
false;
235 bool changed =
false;
237 for (
const auto& entry :
cache->entries) {
238 if (!filter.
empty() && !entry.name.contains(filter))
241 has_visible_entries =
true;
246 if (entry.is_directory) {
251 selected_path = entry.
path;
255 ImGui::CloseCurrentPopup();
260 if (!has_visible_entries)
261 ImGui::TextDisabled(
"No matching entries.");
266void FilesystemCombo::accept_path(
267 std::filesystem::path& selected_path,
268 const std::filesystem::path& path
276 selected_path = path;
EchoMap class specification.
FilesystemCombo specification.
The EchoMap maintains state for the application including WebGPU and Dear ImGui context,...
void invalidate_cache()
Invalidates the EntryCache.
bool operator()(std::filesystem::path &selected_path)
Draws the FilesystemCombo control.
FilesystemCombo(EchoMap *app)
Sets up a new FilesystemCombo with the given EchoMap application context.
std::optional< EntryCache > cache
Cache of entries visible in the combo box.
BrowseTarget current_target
The current target specified in the filter window.
EchoMap * app
Pointer to the owning application instance.
void update_current_state(const std::filesystem::path &path)
Copies and formats the given path into the fixed-size current directory state member variable.
std::array< char, max_path_length > current_root
The current raw string entered by the user.
T current_path(T... args)
T has_parent_path(T... args)
T is_directory(T... args)
T is_regular_file(T... args)
The main EchoMap outermost namespace for all non-exported symbols.
std::filesystem::path parent_directory
The parent directory of the target path.
std::filesystem::path target_path
The selected path.
std::string filter
Cached string of the target path filename.
EntryCache(const std::filesystem::path &directory)
Creates a new EntryCache and populates it for the given root directory.
std::filesystem::path directory
The root directory on the file-system.
std::vector< Entry > entries
The first-level children of the root.
bool is_directory
Directory sentinel flag.
std::string name
The cached display name of the path.
std::string imgui_id
Dear ImGui display name, including ID disambiguator.
std::filesystem::path path
The path represented by the Entry.
Entry(const std::filesystem::path &path, bool is_directory_hint)
Create a new Entry for a regular file or directory.
ImGuiSelectableFlags flags
Dear ImGui flags for rendering the Selectable.
bool draw() const noexcept
Draws the Entry as a Dear ImGui Selectable.