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) 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_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 */
35typedef struct _NvdFileDialog NvdFileDialog;
36
37/**
38 * @brief Creates a new, empty @ref NvdFileDialog to be used for
39 * retrieving a file and returns it.
40 *
41 * This creates a new file dialog and returns it. In order to use it, you must
42 * call @ref nvd_get_file_location and pass a pointer to write the file location to.
43 * @warning The `file_extensions` parameter has no effect with the `gtk` backend due to the `gtk` library's limitations.
44 * @param title A string to put as the dialog title.
45 * @param file_extensions A string of file extensions/endings allowed, see the example below for details.
46 * @returns An empty @ref NvdFileDialog object if successful, otherwise NULL and
47 * an error retrievable through @ref nvd_get_error is set.
48 * @example
49 * @code
50 * int main(void) {
51 * const char* filters = ".img;.png;.jpeg;.ico;.svg";
52 * NvdFileDialog* dialog = nvd_open_file_dialog_new("Open File", filters);
53 *
54 * NvdDynamicString *filename = nvd_get_file_location(dialog);
55 * if (filename != NULL) printf("Chosen file: %s\n", NVD_CSTR(filename));
56 *
57 * nvd_free_object(dialog);
58 * return 0;
59 * }
60 * @endcode
61 * @ingroup FileDialog
62 */
64 const char *file_extensions);
65
66/**
67 * @brief Creates a new, empty @ref NvdFileDialog object that will be used to
68 * save a file in the selected (from the user) location.
69 * @param title The title of the dialog, default is "Save file"
70 * @param default_filename The default filename to use for saving.
71 * @return An @ref NvdFileDialog on success, otherwise NULL and @ref
72 * nvd_get_error should be called to get the failure reason.
73 * @ingroup FileDialog
74 */
76 const char *default_filename);
77
78/**
79 * @brief Creates a new, empty @ref NvdFileDialog object that will be used to
80 * request a directory or folder in the filesystem.
81 *
82 * @param title The title of the dialog, default is "Open directory"
83 * @param default_folder Path to the default folder to open. May be ignored in
84 * some platforms.
85 * @return An @ref NvdFileDialog on success or NULL otherwise. @ref
86 * nvd_get_error should be called for further information about the error
87 * occurring.
88 * @ingroup FileDialog
89 * @since v0.9.0
90 */
92 const char *default_folder);
93
94/**
95 * @brief Returns the filesystem path chosen through the @ref NvdFileDialog
96 * passed.
97 *
98 * @details This function will return the path on the filesystem from the dialog chosen,
99 * that you can then use to either open or save the file given. It works with
100 * both save and open file dialog types.
101 *
102 * @sa nvd_open_file_dialog_new
103 * @param dialog The file dialog to take the filename from.
104 * @returns A @ref NvdDynamicString if a file/folder was selected, or NULL if no path was selected by the user.
105 * @ingroup FileDialog
106 */
108
109/**
110 * @brief Returns the raw object behind the dialog.
111 * @param dialog The dialog to retrieve the object from.
112 * @return void* The raw toolkit-created object.
113 * @ingroup FileDialog
114 */
#define NVD_API
Definition nvdialog.h:113
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:35
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 ...
struct _NvdDynamicString NvdDynamicString
A string type that can be resized, manipulated, converted and read from.
Definition nvdialog_string.h:60