-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveFileDialogHandler.cs
58 lines (50 loc) · 1.22 KB
/
SaveFileDialogHandler.cs
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
using System;
using System.IO;
using Eto.Forms;
namespace Eto.Mac.Forms
{
public class SaveFileDialogHandler : MacFileDialog<NSSavePanel, SaveFileDialog>, SaveFileDialog.IHandler
{
bool hasShown;
string selectedFileName;
public override string FileName
{
get => hasShown ? base.FileName : selectedFileName;
set
{
selectedFileName = value;
var name = value;
if (!string.IsNullOrEmpty(name))
{
var dir = Path.GetDirectoryName(name);
if (!string.IsNullOrEmpty(dir) && System.IO.Directory.Exists(dir))
Directory = new Uri(dir);
name = Path.GetFileName(name);
}
Control.NameFieldStringValue = name ?? string.Empty;
hasShown = false;
}
}
protected override bool DisposeControl { get { return false; } }
protected override NSSavePanel CreateControl()
{
return NSSavePanel.SavePanel;
}
protected override void Initialize()
{
Control.AllowsOtherFileTypes = true;
Control.CanSelectHiddenExtension = true;
base.Initialize();
}
public override DialogResult ShowDialog(Window parent)
{
var result = base.ShowDialog(parent);
if (result == DialogResult.Ok)
{
selectedFileName = null;
hasShown = true;
}
return result;
}
}
}