Skip to content

Commit 1ff9605

Browse files
authored
Port 'Save File' demo to Vala (#169)
1 parent 86ef030 commit 1ff9605

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Save File/main.vala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /usr/bin/env -S vala workbench.vala --pkg gtk4
2+
3+
async void save_file () {
4+
var file_dialog = new Gtk.FileDialog () {
5+
initial_name = "Workbench.txt"
6+
};
7+
try {
8+
File file = yield file_dialog.save (workbench.window, null);
9+
10+
uint8[] contents = ("Hello from Workbench!").data;
11+
12+
yield file.replace_contents_async (contents, // contents
13+
null, // etag
14+
false, // make_backup
15+
FileCreateFlags.NONE, // flags
16+
null, // cancellable
17+
null // callback
18+
);
19+
20+
message (@"File $(file.get_basename()) saved");
21+
} catch (Error e) {
22+
message (@"$(e.message)");
23+
}
24+
}
25+
26+
public void main () {
27+
var button = (Gtk.Button) workbench.builder.get_object ("button");
28+
29+
button.clicked.connect (() => {
30+
save_file.begin ();
31+
});
32+
}

0 commit comments

Comments
 (0)