Lagrange
file_dialog.h
1/*
2 * Copyright 2021 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/fs/filesystem.h>
16
17#include <vector>
18
19namespace lagrange {
20namespace ui {
21
29class LA_UI_API FileDialogPath
30{
31public:
33 static FileDialogPath make_input_path(const fs::path& path);
35 static FileDialogPath make_output_path(const fs::path& path);
36
38 FileDialogPath& operator=(FileDialogPath&& other);
40
42 operator const fs::path &() const { return path(); }
44 operator std::string() const { return string(); }
45
47 std::string string() const { return path().string(); }
48
49 bool empty() const noexcept { return path().empty(); }
50
52 const fs::path& path() const;
53
54protected:
55 FileDialogPath(const fs::path& path);
56 struct FileDialogPathImpl;
57 std::unique_ptr<FileDialogPathImpl> m_impl;
58};
59
60
65{
67 std::string name;
68
70 std::string pattern;
71};
72
76enum class FileSave {
79};
80
84enum class FolderOpen {
87};
88
98LA_UI_API FileDialogPath open_file(
99 const std::string& title,
100 const fs::path& default_path = ".",
101 const std::vector<FileFilter>& filters = {{"All Files", "*"}});
102
112LA_UI_API std::vector<FileDialogPath> open_files(
113 const std::string& title,
114 const fs::path& default_path = ".",
115 const std::vector<FileFilter>& filters = {{"All Files", "*"}});
116
127LA_UI_API FileDialogPath save_file(
128 const std::string& title,
129 const fs::path& default_path = ".",
130 const std::vector<FileFilter>& filters = {{"All Files", "*"}},
131 FileSave overwrite_behavior = FileSave::ConfirmOverwrite);
132
143LA_UI_API FileDialogPath open_folder(
144 const std::string& title,
145 const fs::path& default_path = ".",
146 FolderOpen open_behavior = FolderOpen::LastOpened);
147
148
149namespace utils {
163LA_UI_API std::string transform_filters_to_accept(const std::vector<FileFilter>& filters);
164
165} // namespace utils
166
167} // namespace ui
168} // namespace lagrange
RAII Wrapper for fs::path obtained from a file dialog.
Definition: file_dialog.h:30
operator std::string() const
Implicit string conversion.
Definition: file_dialog.h:44
std::string string() const
Convert path to string.
Definition: file_dialog.h:47
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API std::vector< FileDialogPath > open_files(const std::string &title, const fs::path &default_path=".", const std::vector< FileFilter > &filters={{"All Files", "*"}})
Opens a native file dialog to open multiple files.
Definition: file_dialog.cpp:386
FolderOpen
Controls the behavior of the folder open dialog.
Definition: file_dialog.h:84
@ ForcePath
Force folder dialog window to use the provided initial path.
@ LastOpened
On Windows, use the last opened folder as the initial path.
FileSave
Controls the behavior of the file save dialog.
Definition: file_dialog.h:76
@ SilentOverwrite
Force silently overwriting the file.
@ ConfirmOverwrite
Open a confirmation dialog before overwriting a file.
LA_UI_API FileDialogPath save_file(const std::string &title, const fs::path &default_path=".", const std::vector< FileFilter > &filters={{"All Files", "*"}}, FileSave overwrite_behavior=FileSave::ConfirmOverwrite)
Opens a native file dialog to save a file.
Definition: file_dialog.cpp:411
LA_UI_API FileDialogPath open_folder(const std::string &title, const fs::path &default_path=".", FolderOpen open_behavior=FolderOpen::LastOpened)
Opens a native file dialog to select a folder.
Definition: file_dialog.cpp:463
LA_UI_API FileDialogPath open_file(const std::string &title, const fs::path &default_path=".", const std::vector< FileFilter > &filters={{"All Files", "*"}})
Opens a native file dialog to open a single file.
Definition: file_dialog.cpp:361
Main namespace for Lagrange.
Definition: AABBIGL.h:30
File filter option.
Definition: file_dialog.h:65
std::string pattern
Pattern used for filter, e.g. "*" or *.png *.jpg *.jpeg *.bmp".
Definition: file_dialog.h:70
std::string name
Name of the filter, e.g. "All files" or "Image files".
Definition: file_dialog.h:67