File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments