Skip to content

Commit

Permalink
Mac: Fix setting SaveFileDialog.FileName with a path
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Sep 26, 2022
1 parent e647a6a commit be5935c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/Eto.Mac/Forms/SaveFileDialogHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
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 : Control.NameFieldStringValue;
get => hasShown ? base.FileName : selectedFileName;
set
{
Control.NameFieldStringValue = value ?? string.Empty;
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;
}
}
Expand All @@ -33,10 +45,13 @@ protected override void Initialize()

public override DialogResult ShowDialog(Window parent)
{
hasShown = true;
var result = base.ShowDialog(parent);
if (result != DialogResult.Ok)
hasShown = false;
if (result == DialogResult.Ok)
{
selectedFileName = null;
hasShown = true;
}

return result;
}
}
Expand Down

0 comments on commit be5935c

Please sign in to comment.