-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathOpenFileDialog.cpp
58 lines (49 loc) · 1.71 KB
/
OpenFileDialog.cpp
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
#include <iostream>
#include <gtkmm.h>
using namespace Glib;
using namespace Gtk;
class Form : public Window {
public:
Form() {
add(scrolledWindow);
scrolledWindow.add(fixed);
button.set_label("Open...");
fixed.add(button);
fixed.move(button, 10, 10);
button.signal_button_release_event().connect([&](GdkEventButton* event) {
FileChooserDialog openFileDialog("", FILE_CHOOSER_ACTION_OPEN);
openFileDialog.add_button("Cancel", RESPONSE_CANCEL);
openFileDialog.add_button("Open", RESPONSE_OK);
openFileDialog.set_current_folder(ustring::compose("%1/Desktop", ustring(getenv("HOME"))));
openFileDialog.set_transient_for(*this);
Glib::RefPtr<Gtk::FileFilter> fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("Text Files (*.txt)");
fileFilter->add_pattern("*.txt");
openFileDialog.add_filter(fileFilter);
fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("All Files (*.*)");
fileFilter->add_pattern("*.*");
openFileDialog.add_filter(fileFilter);
if (openFileDialog.run() == RESPONSE_OK)
label.set_text(ustring::compose("File = %1", ustring(openFileDialog.get_filename())));
return true;
});
label.set_text("File = ");
fixed.add(label);
fixed.move(label, 10, 50);
set_title("OpenFileDialog example");
resize(300, 300);
show_all();
}
private:
Fixed fixed;
ScrolledWindow scrolledWindow;
Button button;
Label label;
};
int main(int argc, char* argv[]) {
g_object_set(gtk_settings_get_default(), "gtk-button-images", true, NULL);
RefPtr<Application> application = Application::create(argc, argv);
Form form;
return application->run(form);
}