Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default filename parameter for save file dialog #213

Draft
wants to merge 3 commits into
base: debug
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Photino.NET/PhotinoDllImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public partial class PhotinoWindow

[LibraryImport(DLL_NAME, SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial IntPtr Photino_ShowSaveFile(IntPtr inst, string title, string defaultPath, string[] filters, int filtersCount);
public static partial IntPtr Photino_ShowSaveFile(IntPtr inst, string title, string defaultPath, string defaultFileName, string[] filters, int filtersCount);

[LibraryImport(DLL_NAME, SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
Expand All @@ -343,7 +343,7 @@ public partial class PhotinoWindow
public static extern IntPtr Photino_ShowOpenFolder(IntPtr inst, [MarshalAs(UnmanagedType.LPUTF8Str)] string title, [MarshalAs(UnmanagedType.LPUTF8Str)] string defaultPath, bool multiSelect, out int resultCount);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr Photino_ShowSaveFile(IntPtr inst, [MarshalAs(UnmanagedType.LPUTF8Str)] string title, [MarshalAs(UnmanagedType.LPUTF8Str)] string defaultPath, string[] filters, int filtersCount);
public static extern IntPtr Photino_ShowSaveFile(IntPtr inst, [MarshalAs(UnmanagedType.LPUTF8Str)] string title, [MarshalAs(UnmanagedType.LPUTF8Str)] string defaultPath, [MarshalAs(UnmanagedType.LPUTF8Str)] string defaultFileName, string[] filters, int filtersCount);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern PhotinoDialogResult Photino_ShowMessage(IntPtr inst, [MarshalAs(UnmanagedType.LPUTF8Str)] string title, [MarshalAs(UnmanagedType.LPUTF8Str)] string text, PhotinoDialogButtons buttons, PhotinoDialogIcon icon);
Expand Down
23 changes: 21 additions & 2 deletions Photino.NET/PhotinoWindow.NET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ public void SendNotification(string title, string body)
public string[] ShowOpenFolder(string title = "Select folder", string defaultPath = null, bool multiSelect = false) => ShowOpenDialog(true, title, defaultPath, multiSelect, null);

/// <summary>
/// Show an save folder dialog native to the OS.
/// Show a save folder dialog native to the OS.
/// </summary>
/// <remarks>
/// Filter names are not used on macOS.
Expand All @@ -2460,6 +2460,25 @@ public void SendNotification(string title, string body)
/// <param name="filters">Array of <see cref="Extensions"/> for filtering.</param>
/// <returns></returns>
public string ShowSaveFile(string title = "Save file", string defaultPath = null, (string Name, string[] Extensions)[] filters = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this back in as a method overload and call the new signature, supplying a null value for the new defaultFileName parameter?

{
return ShowSaveFile(title, defaultPath, null, filters);
}

/// <summary>
/// Show a save folder dialog native to the OS.
/// </summary>
/// <remarks>
/// Filter names are not used on macOS.
/// </remarks>
/// <exception cref="ApplicationException">
/// Thrown when the window is not initialized.
/// </exception>
/// <param name="title">Title of the dialog</param>
/// <param name="defaultPath">Default path. Defaults to <see cref="Environment.SpecialFolder.MyDocuments"/></param>
/// <param name="defaultFileName">Default file name in the text input field.</param>
/// <param name="filters">Array of <see cref="Extensions"/> for filtering.</param>
/// <returns></returns>
public string ShowSaveFile(string title = "Save file", string defaultPath = null, string defaultFileName = null, (string Name, string[] Extensions)[] filters = null)
{
defaultPath ??= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
filters ??= Array.Empty<(string, string[])>();
Expand All @@ -2469,7 +2488,7 @@ public string ShowSaveFile(string title = "Save file", string defaultPath = null

Invoke(() =>
{
var ptrResult = Photino_ShowSaveFile(_nativeInstance, title, defaultPath, nativeFilters, filters.Length);
var ptrResult = Photino_ShowSaveFile(_nativeInstance, title, defaultPath, defaultFileName, nativeFilters, filters.Length);
result = Marshal.PtrToStringAuto(ptrResult);
});

Expand Down