forked from samhocevar/portable-file-dialogs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
139 lines (119 loc) · 4.04 KB
/
Copy pathexample.cpp
File metadata and controls
139 lines (119 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// Portable File Dialogs
//
// Copyright © 2018–2022 Sam Hocevar <[email protected]>
//
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//
#include "portable-file-dialogs.h"
#include <iostream>
void test_notify();
void test_message();
void test_select_folder();
void test_open_file();
void test_save_file();
int main()
{
// Check that a backend is available
if (!pfd::settings::available())
{
std::cout << "Portable File Dialogs are not available on this platform.\n";
return 1;
}
// Set verbosity to true
pfd::settings::verbose(true);
test_notify();
test_message();
test_select_folder();
test_open_file();
test_save_file();
}
void test_notify()
{
// Notification
pfd::notify("Important Notification",
"This is ' a message, pay \" attention \\ to it!",
pfd::icon::info);
}
void test_message()
{
// Message box with nice message
auto m = pfd::message("Personal Message",
"You are an amazing person, don’t let anyone make you think otherwise.",
pfd::choice::yes_no_cancel,
pfd::icon::warning);
// Optional: do something while waiting for user action
for (int i = 0; i < 10 && !m.ready(1000); ++i)
std::cout << "Waited 1 second for user input...\n";
// Do something according to the selected button
switch (m.result())
{
case pfd::button::yes: std::cout << "User agreed.\n"; break;
case pfd::button::no: std::cout << "User disagreed.\n"; break;
case pfd::button::cancel: std::cout << "User freaked out.\n"; break;
default: break; // Should not happen
}
}
void test_select_folder()
{
// Directory selection
auto dir = pfd::select_folder("Select any directory", pfd::path::home()).result();
std::cout << "Selected dir: " << dir << "\n";
}
void test_open_file()
{
// File open
auto f = pfd::open_file("Choose files to read", pfd::path::home(),
{ "Text Files (.txt .text)", "*.txt *.text",
"All Files", "*" },
pfd::opt::multiselect);
std::cout << "Selected files:";
for (auto const &name : f.result())
std::cout << " " + name;
std::cout << "\n";
}
void test_save_file()
{
// File save
auto f = pfd::save_file("Choose file to save",
pfd::path::home() + pfd::path::separator() + "readme.txt",
{ "Text Files (.txt .text)", "*.txt *.text" },
pfd::opt::force_overwrite);
std::cout << "Selected file: " << f.result() << "\n";
}
// Unused function that just tests the whole API
void test_api()
{
// pfd::settings
pfd::settings::verbose(true);
pfd::settings::rescan();
// pfd::notify
pfd::notify("", "");
pfd::notify("", "", pfd::icon::info);
pfd::notify("", "", pfd::icon::warning);
pfd::notify("", "", pfd::icon::error);
pfd::notify("", "", pfd::icon::question);
pfd::notify a("", "");
(void)a.ready();
(void)a.ready(42);
// pfd::message
pfd::message("", "");
pfd::message("", "", pfd::choice::ok);
pfd::message("", "", pfd::choice::ok_cancel);
pfd::message("", "", pfd::choice::yes_no);
pfd::message("", "", pfd::choice::yes_no_cancel);
pfd::message("", "", pfd::choice::retry_cancel);
pfd::message("", "", pfd::choice::abort_retry_ignore);
pfd::message("", "", pfd::choice::ok, pfd::icon::info);
pfd::message("", "", pfd::choice::ok, pfd::icon::warning);
pfd::message("", "", pfd::choice::ok, pfd::icon::error);
pfd::message("", "", pfd::choice::ok, pfd::icon::question);
pfd::message b("", "");
(void)b.ready();
(void)b.ready(42);
(void)b.result();
}