NvDialog 0.10.1
A cross-platform modal dialogs library for C/C++ that uses the native OS theme.
Loading...
Searching...
No Matches
nvdialog_file_dialog.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2022, 2025 Aggelos Tselios
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#include "../nvdialog_platform.h"
26#include "../nvdialog_string.h"
27
28/**
29 * @brief An opaque file dialog type, representing either a file
30 * dialog that can be used to open a file or save a file, and since v0.9.0,
31 * opening a directory instead.
32 * @since v0.1.0
33 * @ingroup FileDialog
34 * @sa nvd_open_file_dialog_new
35 */
36typedef struct _NvdFileDialog NvdFileDialog;
37
38/**
39 * @brief Creates a new, empty @ref NvdFileDialog to be used for
40 * retrieving a file and returns it.
41 *
42 * This creates a new file dialog and returns it. In order to use it, you must
43 * call @ref nvd_get_file_location and pass a pointer to write the file location
44 * to.
45 * @warning The `file_extensions` parameter has no effect with the `gtk` backend
46 * due to the `gtk` library's limitations.
47 * @param title A string to put as the dialog title.
48 * @param file_extensions A string of file extensions/endings allowed, see the
49 * example below for details.
50 * @returns An empty @ref NvdFileDialog object if successful, otherwise NULL and
51 * an error retrievable through @ref nvd_get_error is set.
52 * @example
53 * @code
54 * int main(void) {
55 * const char* filters = ".img;.png;.jpeg;.ico;.svg";
56 * NvdFileDialog* dialog = nvd_open_file_dialog_new("Open File", filters);
57 *
58 * NvdDynamicString *filename = nvd_get_file_location(dialog);
59 * if (filename != NULL) printf("Chosen file: %s\n", NVD_CSTR(filename));
60 *
61 * nvd_free_object(dialog);
62 * return 0;
63 * }
64 * @endcode
65 * @ingroup FileDialog
66 */
68 const char *file_extensions);
69
70/**
71 * @brief Creates a new, empty @ref NvdFileDialog object that will be used to
72 * save a file in the selected (from the user) location.
73 * @param title The title of the dialog, default is "Save file"
74 * @param default_filename The default filename to use for saving.
75 * @return An @ref NvdFileDialog on success, otherwise NULL and @ref
76 * nvd_get_error should be called to get the failure reason.
77 * @ingroup FileDialog
78 */
80 const char *default_filename);
81
82/**
83 * @brief Creates a new, empty @ref NvdFileDialog object that will be used to
84 * request a directory or folder in the filesystem.
85 *
86 * @param title The title of the dialog, default is "Open directory"
87 * @param default_folder Path to the default folder to open. May be ignored in
88 * some platforms.
89 * @return An @ref NvdFileDialog on success or NULL otherwise. @ref
90 * nvd_get_error should be called for further information about the error
91 * occurring.
92 * @ingroup FileDialog
93 * @since v0.9.0
94 */
96 const char *default_folder);
97
98/**
99 * @brief Returns the filesystem path chosen through the @ref NvdFileDialog
100 * passed.
101 *
102 * @details This function will return the path on the filesystem from the dialog
103 * chosen, that you can then use to either open or save the file given. It works
104 * with both save and open file dialog types.
105 *
106 * @sa nvd_open_file_dialog_new
107 * @param dialog The file dialog to take the filename from.
108 * @returns A @ref NvdDynamicString if a file/folder was selected, or NULL if no
109 * path was selected by the user.
110 * @ingroup FileDialog
111 */
113
114/**
115 * @brief Returns the raw object behind the dialog.
116 * @param dialog The dialog to retrieve the object from.
117 * @return void* The raw toolkit-created object.
118 * @ingroup FileDialog
119 */
NVD_API NvdFileDialog * nvd_open_file_dialog_new(const char *title, const char *file_extensions)
NVD_API NvdDynamicString * nvd_get_file_location(NvdFileDialog *dialog)
Returns the filesystem path chosen through the NvdFileDialog passed.
NVD_API void * nvd_open_file_dialog_get_raw(NvdFileDialog *dialog)
Returns the raw object behind the dialog.
struct _NvdFileDialog NvdFileDialog
An opaque file dialog type, representing either a file dialog that can be used to open a file or save...
Definition: nvdialog_file_dialog.h:36
NVD_API NvdFileDialog * nvd_open_folder_dialog_new(const char *title, const char *default_folder)
Creates a new, empty NvdFileDialog object that will be used to request a directory or folder in the f...
NVD_API NvdFileDialog * nvd_save_file_dialog_new(const char *title, const char *default_filename)
Creates a new, empty NvdFileDialog object that will be used to save a file in the selected (from the ...
#define NVD_API
Definition: nvdialog_platform.h:57
struct _NvdDynamicString NvdDynamicString
A string type that can be resized, manipulated, converted and read from.
Definition: nvdialog_string.h:64