EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::FileChooser Class Reference

Modal containing controls for interactively selecting a file from the file-system. More...

#include <FileChooser.hpp>

Inheritance diagram for echomap::FileChooser:
[legend]

Public Member Functions

 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.
void change_active_project (const Project *new_project) override
 Updates the active Project being described by the IPanel.
Public Member Functions inherited from echomap::IPanel
virtual void update_gpu (const wgpu::CommandEncoder &command_encoder)
 Delegate work to the GPU via the WebGPU platform.

Static Public Member Functions

static const char * get_imgui_stable_name () noexcept

Private Attributes

std::filesystem::path expected_extension = ".json"
std::filesystem::path chosen_path
FilesystemCombo file_combo
std::string panel_name
bool is_open = false
EchoMapapp
RaiseFileChooserNotification::SuccessCallbackT success_callback
RaiseFileChooserNotification::CancelledCallbackT cancelled_callback

Static Private Attributes

static constexpr ImVec2 default_modal_size {500.0f, 0.0f}

Additional Inherited Members

Static Protected Attributes inherited from echomap::IPanel
static constexpr ImVec2 button_size {80.0f, 20.0f}
static constexpr auto table_flags

Detailed Description

Modal containing controls for interactively selecting a file from the file-system.

Definition at line 31 of file FileChooser.hpp.

Constructor & Destructor Documentation

◆ FileChooser()

echomap::FileChooser::FileChooser ( EchoMap * app,
RaiseFileChooserNotification::SuccessCallbackT && success_callback,
RaiseFileChooserNotification::CancelledCallbackT && cancelled_callback )
explicit

Create a new FileChooser modal for the given EchoMap instance.

Parameters
appThe owning EchoMap instance.
success_callbackThe slot to invoke with the path once a file has been selected.
cancelled_callbackThe slot to invoke if the operation is cancelled.

Definition at line 19 of file FileChooser.cpp.

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}

Member Function Documentation

◆ change_active_project()

void echomap::FileChooser::change_active_project ( const Project * new_project)
overridevirtual

Updates the active Project being described by the IPanel.

Parameters
new_projectAn observing pointer to the new active Project.

Implements echomap::IProjectPanel.

Definition at line 76 of file FileChooser.cpp.

79{
80 std::ignore = new_project;
81}

◆ draw()

void echomap::FileChooser::draw ( )
overridevirtualnoexcept

Draw the panel to the active rendering context.

Implements echomap::IPanel.

Definition at line 32 of file FileChooser.cpp.

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}
#define LOG_F_DEBUG(msg,...)
Conditionally logs a formatted debug-level message using echomap::Logger::log_f.
Definition Logger.hpp:94
const char * get_imgui_name() const noexcept override
Retrieves the name of the IPanel for Dear ImGui API functions.
T exchange(T... args)

◆ get_imgui_name()

const char * echomap::FileChooser::get_imgui_name ( ) const
nodiscardoverridevirtualnoexcept

Retrieves the name of the IPanel for Dear ImGui API functions.

Returns
The human-readable name of the window as a NULL-terminated C string.

Implements echomap::IPanel.

Definition at line 71 of file FileChooser.cpp.

72{
73 return panel_name.c_str();
74}

◆ get_imgui_stable_name()

const char * echomap::FileChooser::get_imgui_stable_name ( )
staticnoexcept

Definition at line 83 of file FileChooser.cpp.

84{
85 return "###FileChooser";
86}

Member Data Documentation

◆ app

EchoMap* echomap::FileChooser::app
private

Definition at line 64 of file FileChooser.hpp.

◆ cancelled_callback

RaiseFileChooserNotification::CancelledCallbackT echomap::FileChooser::cancelled_callback
private

Definition at line 66 of file FileChooser.hpp.

◆ chosen_path

std::filesystem::path echomap::FileChooser::chosen_path
private

Definition at line 59 of file FileChooser.hpp.

◆ default_modal_size

ImVec2 echomap::FileChooser::default_modal_size {500.0f, 0.0f}
staticconstexprprivate

Definition at line 56 of file FileChooser.hpp.

56{500.0f, 0.0f};

◆ expected_extension

std::filesystem::path echomap::FileChooser::expected_extension = ".json"
private

Definition at line 58 of file FileChooser.hpp.

◆ file_combo

FilesystemCombo echomap::FileChooser::file_combo
private

Definition at line 60 of file FileChooser.hpp.

◆ is_open

bool echomap::FileChooser::is_open = false
private

Definition at line 63 of file FileChooser.hpp.

◆ panel_name

std::string echomap::FileChooser::panel_name
private

Definition at line 62 of file FileChooser.hpp.

◆ success_callback

RaiseFileChooserNotification::SuccessCallbackT echomap::FileChooser::success_callback
private

Definition at line 65 of file FileChooser.hpp.


The documentation for this class was generated from the following files: