ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FileDialogNative.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 // Include FileDialog here to get value of GUI_USE_NATIVE_FILE_DIALOG
10 
11 #if defined(__APPLE__) && GUI_USE_NATIVE_FILE_DIALOG
12 
13 #include <string>
14 #include <vector>
15 
17 
18 namespace cloudViewer {
19 namespace visualization {
20 namespace gui {
21 
22 struct FileDialog::Impl {
24  std::string path_;
25  std::vector<std::pair<std::string, std::string>> filters_;
26  std::function<void()> on_cancel_;
27  std::function<void(const char *)> on_done_;
28 };
29 
30 FileDialog::FileDialog(Mode mode, const char *title, const Theme &theme)
31  : Dialog(title), impl_(new FileDialog::Impl()) {
32  impl_->mode_ = mode;
33 }
34 
35 FileDialog::~FileDialog() {}
36 
37 void FileDialog::SetPath(const char *path) { impl_->path_ = path; }
38 
39 void FileDialog::AddFilter(const char *filter, const char *description) {
40  impl_->filters_.push_back(
41  std::make_pair<std::string, std::string>(filter, description));
42 }
43 
44 void FileDialog::SetOnCancel(std::function<void()> on_cancel) {
45  impl_->on_cancel_ = on_cancel;
46 }
47 
48 void FileDialog::SetOnDone(std::function<void(const char *)> on_done) {
49  impl_->on_done_ = on_done;
50 }
51 
52 Size FileDialog::CalcPreferredSize(const LayoutContext &context,
53  const Constraints &constraints) const {
54  return Size(0, 0);
55 }
56 
57 void FileDialog::OnWillShow() {
58  auto on_ok = [this](const char *path) { this->impl_->on_done_(path); };
59  auto on_cancel = [this]() { this->impl_->on_cancel_(); };
60  ShowNativeFileDialog(impl_->mode_, impl_->path_, impl_->filters_, on_ok,
61  on_cancel);
62 }
63 
64 void FileDialog::OnDone() {}
65 
66 } // namespace gui
67 } // namespace visualization
68 } // namespace cloudViewer
69 
70 #endif // __APPLE__ && GUI_USE_NATIVE_FILE_DIALOG
FileDialog(Mode type, const char *title, const Theme &theme)
Definition: FileDialog.cpp:212
ImGuiContext * context
Definition: Window.cpp:76
const Theme * theme
Definition: Window.cpp:74
static const std::string path
Definition: PointCloud.cpp:59
Generic file read and write utility for python interface.
std::function< void(const char *)> on_done_
Definition: FileDialog.cpp:119