File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
src/Uno.UI.Runtime.Skia.Gtk
Extensions/Storage/Pickers Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 12
12
| Picker | UWP | WebAssembly | Android | iOS | macOS | WPF | GTK |
13
13
| ----------------| -------| -------------| ---------| -------| -------| -----| -----|
14
14
| FileOpenPicker | ✔️ | ✔️ (1) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
15
- | FileSavePicker | ✔️ | ✔️ (1) | ✔️ | ✔️ | ✔️ | ✔️ | ❌ |
15
+ | FileSavePicker | ✔️ | ✔️ (1) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
16
16
| FolderPicker | ✔️ | ✔️ | ✔️ | 💬 (2)| ✔️ | ❌ | ✔️ |
17
17
18
18
* (1) - Multiple implementations supported - see WebAssembly section below*
Original file line number Diff line number Diff line change
1
+ #nullable enable
2
+
3
+ using Gtk ;
4
+ using System ;
5
+ using System . Threading ;
6
+ using System . Threading . Tasks ;
7
+ using Uno . UI . Runtime . Skia ;
8
+ using Windows . Storage ;
9
+ using Windows . Storage . Pickers ;
10
+
11
+ namespace Uno . Extensions . Storage . Pickers
12
+ {
13
+ internal class FileSavePickerExtension : IFileSavePickerExtension
14
+ {
15
+ private readonly FileSavePicker _picker ;
16
+
17
+ public FileSavePickerExtension ( FileSavePicker owner )
18
+ {
19
+ _picker = owner ?? throw new ArgumentNullException ( nameof ( owner ) ) ;
20
+ }
21
+
22
+ public async Task < StorageFile ? > PickSaveFileAsync ( CancellationToken token )
23
+ {
24
+ string commitText = "Save File" ;
25
+ if ( ! string . IsNullOrWhiteSpace ( _picker . CommitButtonText ) )
26
+ {
27
+ commitText = _picker . CommitButtonText ;
28
+ }
29
+
30
+ FileChooserDialog dialog = new FileChooserDialog (
31
+ "Save File" ,
32
+ GtkHost . Window ,
33
+ FileChooserAction . Save ,
34
+ "Cancel" , ResponseType . Cancel ,
35
+ commitText , ResponseType . Accept ) ;
36
+
37
+ dialog . SelectMultiple = false ;
38
+ dialog . SetFilename ( _picker . SuggestedFileName ) ;
39
+ dialog . SetCurrentFolder ( PickerHelpers . GetInitialDirectory ( _picker . SuggestedStartLocation ) ) ;
40
+
41
+ StorageFile ? file = null ;
42
+ if ( dialog . Run ( ) == ( int ) ResponseType . Accept )
43
+ {
44
+ file = await StorageFile . GetFileFromPathAsync ( dialog . Filename ) ;
45
+ }
46
+
47
+ dialog . Destroy ( ) ;
48
+ return file ;
49
+ }
50
+ }
51
+ }
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ public void Run()
64
64
ApiExtensibility . Register < FileOpenPicker > ( typeof ( IFileOpenPickerExtension ) , o => new FileOpenPickerExtension ( o ) ) ;
65
65
ApiExtensibility . Register < FolderPicker > ( typeof ( IFolderPickerExtension ) , o => new FolderPickerExtension ( o ) ) ;
66
66
ApiExtensibility . Register ( typeof ( IClipboardExtension ) , o => new ClipboardExtensions ( o ) ) ;
67
+ ApiExtensibility . Register < FileSavePicker > ( typeof ( IFileSavePickerExtension ) , o => new FileSavePickerExtension ( o ) ) ;
67
68
68
69
_isDispatcherThread = true ;
69
70
_window = new Gtk . Window ( "Uno Host" ) ;
You can’t perform that action at this time.
0 commit comments