Skip to content

Commit 8ccf2a9

Browse files
committed
Add a documentation folder.
1 parent e126e07 commit 8ccf2a9

File tree

5 files changed

+282
-4
lines changed

5 files changed

+282
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Experimental support for Emscripten is on its way.
2626

2727
## Documentation
2828

29-
* [Message Box API](https://github.com/samhocevar/portable-file-dialogs/issues/1)
30-
* [Notification API](https://github.com/samhocevar/portable-file-dialogs/issues/2)
31-
* [File Open API](https://github.com/samhocevar/portable-file-dialogs/issues/3)
32-
* [Folder Selection Open API](https://github.com/samhocevar/portable-file-dialogs/issues/13)
29+
* [Message Box API](doc/message.md)
30+
* [Notification API](doc/notify.md)
31+
* [File Open API](doc/open_file.md)
32+
* [Folder Selection Open API](select_folder.md)
3333

3434
## Screenshots (Windows 10)
3535

doc/message.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
## Message Box API
2+
3+
Displaying a message box is done using the `pfd::message` class. It can be provided a title, a
4+
message text, a `choice` representing which buttons need to be rendered, and an `icon` for the
5+
message:
6+
7+
```cpp
8+
pfd::message::message(std::string const &title,
9+
std::string const &text,
10+
pfd::choice choice = pfd::choice::ok_cancel,
11+
pfd::icon icon = pfd::icon::info);
12+
13+
enum class pfd::choice { ok, ok_cancel, yes_no, yes_no_cancel };
14+
15+
enum class pfd::icon { info, warning, error, question };
16+
```
17+
18+
The pressed button is queried using `pfd::message::result()`. If the dialog box is closed by any
19+
other means, the `pfd::button::cancel` is assumed:
20+
21+
```cpp
22+
pfd::button pfd::message::result();
23+
24+
enum class pfd::button { ok, cancel, yes, no };
25+
```
26+
27+
It is possible to ask the dialog box whether the user took action using the `pfd::message::ready()`
28+
method, with an optional `timeout` argument. If the user did not press a button within `timeout`
29+
milliseconds, the function will return `false`:
30+
31+
```cpp
32+
bool pfd::message::ready(int timeout = pfd::default_wait_timeout);
33+
```
34+
35+
## Example 1: simple notification
36+
37+
The `pfd::message` destructor waits for user action, so this operation will block until the user
38+
closes the message box:
39+
40+
```cpp
41+
pfd::message("Problem", "An error occurred while doing things",
42+
pfd::choice::ok, pfd::icon::error);
43+
```
44+
45+
## Example 2: retrieving the pressed button
46+
47+
Using `pfd::message::result()` will also wait for user action before returning. This operation will block and return the user choice:
48+
49+
```cpp
50+
// Ask for user opinion
51+
auto button = pfd::message("Action requested", "Do you want to proceed with things?",
52+
pfd::choice::yes_no, pfd::icon::question).result();
53+
// Do something with button…
54+
```
55+
56+
## Example 3: asynchronous message box
57+
58+
Using `pfd::message::ready()` allows the application to perform other tasks while waiting for
59+
user input:
60+
61+
```cpp
62+
// Message box with nice message
63+
auto box = pfd::message("Unsaved Files", "Do you want to save the current "
64+
"document before closing the application?",
65+
pfd::choice::yes_no_cancel,
66+
pfd::icon::warning);
67+
68+
// Do something while waiting for user input
69+
while (!box.ready(1000))
70+
std::cout << "Waited 1 second for user input...\n";
71+
72+
// Act depending on the selected button
73+
switch (box.result())
74+
{
75+
case pfd::button::yes: std::cout << "User agreed.\n"; break;
76+
case pfd::button::no: std::cout << "User disagreed.\n"; break;
77+
case pfd::button::cancel: std::cout << "User freaked out.\n"; break;
78+
}
79+
```
80+
81+
## Screenshots
82+
83+
Windows 10:
84+
![warning-win32](https://user-images.githubusercontent.com/245089/47136607-76919a00-d2b4-11e8-8f42-e2d62c4f9570.png)
85+
86+
Mac OS X (dark theme):
87+
![warning-osx-dark](https://user-images.githubusercontent.com/245089/56053001-22dba700-5d53-11e9-8233-ca7a2c58188d.png)
88+
89+
Mac OS X (light theme):
90+
![warning-osx-light](https://user-images.githubusercontent.com/245089/56053055-49014700-5d53-11e9-8306-e9a03a25e044.png)
91+
92+
Linux (GNOME desktop):
93+
![warning-gnome](https://user-images.githubusercontent.com/245089/47140824-8662ab80-d2bf-11e8-9c87-2742dd5b58af.png)
94+
95+
Linux (KDE desktop):
96+
![warning-kde](https://user-images.githubusercontent.com/245089/47149255-4dcccd00-d2d3-11e8-84c9-f85612784680.png)
97+

doc/notify.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Notification API
2+
3+
Displaying a desktop notification is done using the `pfd::notify` class. It can be provided a
4+
title, a message text, and an `icon` for the notification style:
5+
6+
```cpp
7+
pfd::notify::notify(std::string const &title,
8+
std::string const &text,
9+
pfd::icon icon = pfd::icon::info);
10+
11+
enum class pfd::icon { info, warning, error };
12+
```
13+
14+
## Example
15+
16+
Displaying a notification is straightforward. Emoji are supported:
17+
18+
```cpp
19+
pfd::notify("System event", "Something might be on fire 🔥",
20+
pfd::icon::warning);
21+
```
22+
23+
The `pfd::notify` object needs not be kept around, letting the object clean up itself is enough.
24+
25+
## Screenshots
26+
27+
Windows 10:
28+
![notify-win32](https://user-images.githubusercontent.com/245089/47142453-2ff76c00-d2c3-11e8-871a-1a110ac91eb2.png)
29+
30+
Mac OS X (dark theme):
31+
![image](https://user-images.githubusercontent.com/245089/56053188-bc0abd80-5d53-11e9-8298-68aa96315c6c.png)
32+
33+
Mac OS X (light theme):
34+
![image](https://user-images.githubusercontent.com/245089/56053137-92ea2d00-5d53-11e9-8cf2-049486c45713.png)
35+
36+
Linux (GNOME desktop):
37+
![notify-gnome](https://user-images.githubusercontent.com/245089/47142455-30900280-d2c3-11e8-8b76-ea16c7e502d4.png)
38+
39+
Linux (KDE desktop):
40+
![notify-kde](https://user-images.githubusercontent.com/245089/47149206-27a72d00-d2d3-11e8-8f1b-96e462f08c2b.png)
41+

doc/open_file.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## File Open API
2+
3+
The `pfd::open_file` class handles file opening dialogs. It can be provided a title, a starting
4+
directory and/or pre-selected file, an optional filter for recognised file types, and an optional
5+
flag to allow multiple selection:
6+
7+
```cpp
8+
pfd::open_file::open_file(std::string const &title,
9+
std::string const &initial_path,
10+
std::vector<std::string> filters = { "All Files", "*" },
11+
bool allow_multiselect = false);
12+
```
13+
14+
The selected files are queried using `pfd::open_file::result()`. If the user canceled the
15+
operation, the returned list is empty:
16+
17+
```cpp
18+
std::vector<std::string> pfd::open_file::result();
19+
```
20+
21+
It is possible to ask the file open dialog whether the user took action using the
22+
`pfd::message::ready()` method, with an optional `timeout` argument. If the user did not validate
23+
the dialog within `timeout` milliseconds, the function will return `false`:
24+
25+
```cpp
26+
bool pfd::open_file::ready(int timeout = pfd::default_wait_timeout);
27+
```
28+
29+
## Example 1: simple file selection
30+
31+
Using `pfd::open_file::result()` will wait for user action before returning. This operation will
32+
block and return the user choice:
33+
34+
```cpp
35+
auto selection = pfd::open_file("Select a file").result();
36+
if (!selection.empty())
37+
std::cout << "User selected file " << selection[0] << "\n";
38+
```
39+
40+
## Example 2: filters
41+
42+
The filter list enumerates filter names and corresponded space-separated wildcard lists. It
43+
defaults to `{ "All Files", "*" }`, but here is how to use other options:
44+
45+
```cpp
46+
auto selection = pfd::open_file("Select a file", ".",
47+
{ "Image Files", "*.png *.jpg *.jpeg *.bmp",
48+
"Audio Files", "*.wav *.mp3",
49+
"All Files", "*" },
50+
true).result();
51+
// Do something with selection
52+
for (auto const &filename : dialog.result())
53+
std::cout << "Selected file: " << filename << "\n";
54+
```
55+
56+
## Example 3: asynchronous file open
57+
58+
Using `pfd::open_file::ready()` allows the application to perform other tasks while waiting for
59+
user input:
60+
61+
```cpp
62+
// File open dialog
63+
auto dialog = pfd::open_file("Select file to open");
64+
65+
// Do something while waiting for user input
66+
while (!dialog.ready(1000))
67+
std::cout << "Waited 1 second for user input...\n";
68+
69+
// Act depending on the user choice
70+
std::cout << "Number of selected files: " << dialog.result().size() << "\n";
71+
```
72+
73+
## Screenshots
74+
75+
Windows 10:
76+
![open-win32](https://user-images.githubusercontent.com/245089/47155865-0f8cd900-d2e6-11e8-8041-1e20b6f77dee.png)
77+
78+
Mac OS X (dark theme):
79+
![image](https://user-images.githubusercontent.com/245089/56053378-39363280-5d54-11e9-9583-9f1c978fa0db.png)
80+
81+
Mac OS X (light theme):
82+
![image](https://user-images.githubusercontent.com/245089/56053413-4fdc8980-5d54-11e9-85e3-e9e5d0e10772.png)
83+
84+
Linux (GNOME desktop):
85+
![open-gnome](https://user-images.githubusercontent.com/245089/47155867-0f8cd900-d2e6-11e8-93af-275636491ec4.png)
86+
87+
Linux (KDE desktop):
88+
![open-kde](https://user-images.githubusercontent.com/245089/47155866-0f8cd900-d2e6-11e8-8006-f14b948afc55.png)
89+

doc/select_folder.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Folder Selection API
2+
3+
The `pfd::select_folder` class handles folder opening dialogs. It can be provided a title, and an
4+
optional starting directory:
5+
6+
```cpp
7+
pfd::select_folder::select_folder(std::string const &title,
8+
std::string const &default_path = "");
9+
```
10+
11+
The selected folder is queried using `pfd::select_folder::result()`. If the user canceled the
12+
operation, the returned string is empty:
13+
14+
```cpp
15+
std::string pfd::select_folder::result();
16+
```
17+
18+
It is possible to ask the folder selection dialog whether the user took action using the
19+
`pfd::message::ready()` method, with an optional `timeout` argument. If the user did not validate
20+
the dialog within `timeout` milliseconds, the function will return `false`:
21+
22+
```cpp
23+
bool pfd::select_folder::ready(int timeout = pfd::default_wait_timeout);
24+
```
25+
26+
## Example 1: simple folder selection
27+
28+
Using `pfd::select_folder::result()` will wait for user action before returning. This operation
29+
will block and return the user choice:
30+
31+
```cpp
32+
auto selection = pfd::select_folder("Select a folder").result();
33+
if (!selection.empty())
34+
std::cout << "User selected folder " << selection << "\n";
35+
```
36+
37+
## Example 2: asynchronous folder open
38+
39+
Using `pfd::select_folder::ready()` allows the application to perform other tasks while waiting for user input:
40+
41+
```cpp
42+
// Folder selection dialog
43+
auto dialog = pfd::select_folder("Select folder to open");
44+
45+
// Do something while waiting for user input
46+
while (!dialog.ready(1000))
47+
std::cout << "Waited 1 second for user input...\n";
48+
49+
// Act depending on the user choice
50+
std::cout << "Selected folder: " << dialog.result() << "\n";
51+
```

0 commit comments

Comments
 (0)