Skip to content

Commit

Permalink
Merge pull request #2321 from cwensley/curtis/mac-fix-save-file-dialog
Browse files Browse the repository at this point in the history
Mac: Fix setting SaveFileDialog.FileName with a path
  • Loading branch information
cwensley authored Sep 26, 2022
2 parents 009d2e6 + be5935c commit 18720f6
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 18720f6

Please sign in to comment.