forked from gammasoft71/Examples_Gtkmm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveFileDialog.cpp
More file actions
58 lines (49 loc) · 1.79 KB
/
Copy pathSaveFileDialog.cpp
File metadata and controls
58 lines (49 loc) · 1.79 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
#include <iostream>
#include <gtkmm.h>
using namespace Glib;
using namespace Gtk;
class Form : public Window {
public:
Form() {
this->add(this->scrolledWindow);
this->scrolledWindow.add(this->fixed);
this->button.set_label("Save...");
this->fixed.add(this->button);
this->fixed.move(this->button, 10, 10);
this->button.signal_button_release_event().connect([&](GdkEventButton* event) {
FileChooserDialog saveFileDialog("", FILE_CHOOSER_ACTION_SAVE);
saveFileDialog.add_button("Cancel", RESPONSE_CANCEL);
saveFileDialog.add_button("Open", RESPONSE_OK);
saveFileDialog.set_current_folder(ustring::compose("%1/Desktop", ustring(getenv("HOME"))));
saveFileDialog.set_current_name("MyFile.txt");
saveFileDialog.set_transient_for(*this);
Glib::RefPtr<Gtk::FileFilter> fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("Text Files (*.txt)");
fileFilter->add_pattern("*.txt");
saveFileDialog.add_filter(fileFilter);
fileFilter = Gtk::FileFilter::create();
fileFilter->set_name("All Files (*.*)");
fileFilter->add_pattern("*.*");
saveFileDialog.add_filter(fileFilter);
if (saveFileDialog.run() == RESPONSE_OK)
this->label.set_text(ustring::compose("File = %1", ustring(saveFileDialog.get_filename())));
return true;
});
this->label.set_text("File = ");
this->fixed.add(this->label);
this->fixed.move(this->label, 10, 50);
this->set_title("SaveFileDialog example");
this->resize(300, 300);
this->show_all();
}
private:
Fixed fixed;
ScrolledWindow scrolledWindow;
Button button;
Label label;
};
int main(int argc, char* argv[]) {
RefPtr<Application> application = Application::create(argc, argv);
Form form;
return application->run(form);
}