Fix FilePicker broken callback handling and make function signatures unique (#822)

This commit is contained in:
Ottermandias 2022-04-26 17:09:44 +02:00 committed by GitHub
parent be848737c0
commit ae54988f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,8 +20,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="callback">The action to execute when the dialog is finished.</param>
public void OpenFolderDialog(string title, Action<bool, string> callback)
{
this.SetCallback(callback);
this.SetDialog("OpenFolderDialog", title, string.Empty, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly);
this.SetDialog("OpenFolderDialog", title, string.Empty, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly, callback);
}
/// <summary>
@ -33,8 +32,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
public void OpenFolderDialog(string title, Action<bool, string> callback, string? startPath, bool isModal = false)
{
this.SetCallback(callback);
this.SetDialog("OpenFolderDialog", title, string.Empty, startPath ?? this.savedPath, ".", string.Empty, 1, isModal, ImGuiFileDialogFlags.SelectOnly);
this.SetDialog("OpenFolderDialog", title, string.Empty, startPath ?? this.savedPath, ".", string.Empty, 1, isModal, ImGuiFileDialogFlags.SelectOnly, callback);
}
/// <summary>
@ -45,8 +43,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="callback">The action to execute when the dialog is finished.</param>
public void SaveFolderDialog(string title, string defaultFolderName, Action<bool, string> callback)
{
this.SetCallback(callback);
this.SetDialog("SaveFolderDialog", title, string.Empty, this.savedPath, defaultFolderName, string.Empty, 1, false, ImGuiFileDialogFlags.None);
this.SetDialog("SaveFolderDialog", title, string.Empty, this.savedPath, defaultFolderName, string.Empty, 1, false, ImGuiFileDialogFlags.None, callback);
}
/// <summary>
@ -59,8 +56,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
public void SaveFolderDialog(string title, string defaultFolderName, Action<bool, string> callback, string? startPath, bool isModal = false)
{
this.SetCallback(callback);
this.SetDialog("SaveFolderDialog", title, string.Empty, startPath ?? this.savedPath, defaultFolderName, string.Empty, 1, isModal, ImGuiFileDialogFlags.None);
this.SetDialog("SaveFolderDialog", title, string.Empty, startPath ?? this.savedPath, defaultFolderName, string.Empty, 1, isModal, ImGuiFileDialogFlags.None, callback);
}
/// <summary>
@ -71,8 +67,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="callback">The action to execute when the dialog is finished.</param>
public void OpenFileDialog(string title, string filters, Action<bool, string> callback)
{
this.SetCallback(callback);
this.SetDialog("OpenFileDialog", title, filters, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly);
this.SetDialog("OpenFileDialog", title, filters, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly, callback);
}
/// <summary>
@ -81,19 +76,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// <param name="title">The header title of the dialog.</param>
/// <param name="filters">Which files to show in the dialog.</param>
/// <param name="callback">The action to execute when the dialog is finished.</param>
/// <param name="startPath">The directory which the dialog should start inside of. The last path this manager was in is used if this is null.</param>
/// <param name="selectionCountMax">The maximum amount of files or directories which can be selected. Set to 0 for an infinite number.</param>
/// <param name="startPath">The directory which the dialog should start inside of. The last path this manager was in is used if this is null.</param>
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
public void OpenFileDialog(
string title,
string filters,
Action<bool, List<string>> callback,
int selectionCountMax,
string? startPath = null,
int selectionCountMax = 1,
bool isModal = false)
{
this.SetCallback(callback);
this.SetDialog("OpenFileDialog", title, filters, startPath ?? this.savedPath, ".", string.Empty, selectionCountMax, isModal, ImGuiFileDialogFlags.SelectOnly);
this.SetDialog("OpenFileDialog", title, filters, startPath ?? this.savedPath, ".", string.Empty, selectionCountMax, isModal, ImGuiFileDialogFlags.SelectOnly, callback);
}
/// <summary>
@ -111,8 +105,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
string defaultExtension,
Action<bool, string> callback)
{
this.SetCallback(callback);
this.SetDialog("SaveFileDialog", title, filters, this.savedPath, defaultFileName, defaultExtension, 1, false, ImGuiFileDialogFlags.None);
this.SetDialog("SaveFileDialog", title, filters, this.savedPath, defaultFileName, defaultExtension, 1, false, ImGuiFileDialogFlags.None, callback);
}
/// <summary>
@ -134,8 +127,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
string? startPath,
bool isModal = false)
{
this.SetCallback(callback);
this.SetDialog("SaveFileDialog", title, filters, startPath ?? this.savedPath, defaultFileName, defaultExtension, 1, isModal, ImGuiFileDialogFlags.None);
this.SetDialog("SaveFileDialog", title, filters, startPath ?? this.savedPath, defaultFileName, defaultExtension, 1, isModal, ImGuiFileDialogFlags.None, callback);
}
/// <summary>
@ -166,18 +158,6 @@ namespace Dalamud.Interface.ImGuiFileDialog
this.multiCallback = null;
}
private void SetCallback(Action<bool, string> action)
{
this.callback = action;
this.multiCallback = null;
}
private void SetCallback(Action<bool, List<string>> action)
{
this.multiCallback = action;
this.callback = null;
}
private void SetDialog(
string id,
string title,
@ -187,9 +167,19 @@ namespace Dalamud.Interface.ImGuiFileDialog
string defaultExtension,
int selectionCountMax,
bool isModal,
ImGuiFileDialogFlags flags)
ImGuiFileDialogFlags flags,
Delegate callback)
{
this.Reset();
if (callback is Action<bool, List<string>> multi)
{
this.multiCallback = multi;
}
else
{
this.callback = callback as Action<bool, string>;
}
this.dialog = new FileDialog(id, title, filters, path, defaultFileName, defaultExtension, selectionCountMax, isModal, flags);
this.dialog.Show();
}