EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
FileChooser.cpp
Go to the documentation of this file.
1
9
10#if !defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
11
12#include "FileChooser.hpp"
13
15
16namespace echomap
17{
18
20 EchoMap* const app,
21 RaiseFileChooserNotification::SuccessCallbackT&& success_callback,
22 RaiseFileChooserNotification::CancelledCallbackT&& cancelled_callback
23) :
24 file_combo(app),
25 panel_name(std::string("Select File to Open") + get_imgui_stable_name()),
26 app(app),
27 success_callback(std::move(success_callback)),
28 cancelled_callback(std::move(cancelled_callback))
29{
30}
31
32void FileChooser::draw() noexcept
33{
34 if (!std::exchange(is_open, true))
35 ImGui::OpenPopup(get_imgui_name());
36
37 ImGui::SetNextWindowSize(default_modal_size, ImGuiCond_Appearing);
38
39 if (ImGui::BeginPopupModal(get_imgui_name(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
40 ImGui::PushID(get_imgui_name());
41
42 if (file_combo(chosen_path))
43 LOG_F_DEBUG("Changed: {}", chosen_path.c_str());
44
45 ImGui::Spacing();
46 ImGui::Separator();
47 ImGui::Spacing();
48
49 if (ImGui::Button("Cancel", button_size)) {
50 ImGui::CloseCurrentPopup();
51 cancelled_callback();
52 }
53
54 ImGui::SameLine();
55
56 if (chosen_path.extension() == expected_extension) {
57 if (ImGui::Button("OK", button_size))
58 success_callback(chosen_path);
59 } else {
60 ImGui::BeginDisabled();
61 ImGui::Button("OK", button_size);
62 ImGui::SetItemTooltip("To continue, select a JSON EchoMap project file.");
63 ImGui::EndDisabled();
64 }
65
66 ImGui::PopID();
67 ImGui::EndPopup();
68 }
69}
70
71const char* FileChooser::get_imgui_name() const noexcept
72{
73 return panel_name.c_str();
74}
75
77 const Project* const new_project
78)
79{
80 std::ignore = new_project;
81}
82
83const char* FileChooser::get_imgui_stable_name() noexcept
84{
85 return "###FileChooser";
86}
87
88} // namespace echomap
89
90#endif // __EMSCRIPTEN__
FileChooser specification.
EchoMap portable logger specification.
#define LOG_F_DEBUG(msg,...)
Conditionally logs a formatted debug-level message using echomap::Logger::log_f.
Definition Logger.hpp:94
The EchoMap maintains state for the application including WebGPU and Dear ImGui context,...
Definition EchoMap.hpp:35
void change_active_project(const Project *new_project) override
Updates the active Project being described by the IPanel.
FileChooser(EchoMap *app, RaiseFileChooserNotification::SuccessCallbackT &&success_callback, RaiseFileChooserNotification::CancelledCallbackT &&cancelled_callback)
Create a new FileChooser modal for the given EchoMap instance.
void draw() noexcept override
Draw the panel to the active rendering context.
const char * get_imgui_name() const noexcept override
Retrieves the name of the IPanel for Dear ImGui API functions.
T exchange(T... args)
The main EchoMap outermost namespace for all non-exported symbols.
STL namespace.