From ae54988f91b30553b22bc36174d7dd4092a76bee Mon Sep 17 00:00:00 2001
From: Ottermandias <70807659+Ottermandias@users.noreply.github.com>
Date: Tue, 26 Apr 2022 17:09:44 +0200
Subject: [PATCH] Fix FilePicker broken callback handling and make function
signatures unique (#822)
---
.../ImGuiFileDialog/FileDialogManager.cs | 52 ++++++++-----------
1 file changed, 21 insertions(+), 31 deletions(-)
diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
index e5c5854db..f9cd06290 100644
--- a/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
@@ -20,8 +20,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The action to execute when the dialog is finished.
public void OpenFolderDialog(string title, Action 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);
}
///
@@ -33,8 +32,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// Whether the dialog should be a modal popup.
public void OpenFolderDialog(string title, Action 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);
}
///
@@ -45,8 +43,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The action to execute when the dialog is finished.
public void SaveFolderDialog(string title, string defaultFolderName, Action 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);
}
///
@@ -59,8 +56,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// Whether the dialog should be a modal popup.
public void SaveFolderDialog(string title, string defaultFolderName, Action 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);
}
///
@@ -71,8 +67,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The action to execute when the dialog is finished.
public void OpenFileDialog(string title, string filters, Action 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);
}
///
@@ -81,19 +76,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The header title of the dialog.
/// Which files to show in the dialog.
/// The action to execute when the dialog is finished.
- /// The directory which the dialog should start inside of. The last path this manager was in is used if this is null.
/// The maximum amount of files or directories which can be selected. Set to 0 for an infinite number.
+ /// The directory which the dialog should start inside of. The last path this manager was in is used if this is null.
/// Whether the dialog should be a modal popup.
public void OpenFileDialog(
string title,
string filters,
Action> 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);
}
///
@@ -111,8 +105,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
string defaultExtension,
Action 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);
}
///
@@ -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);
}
///
@@ -166,18 +158,6 @@ namespace Dalamud.Interface.ImGuiFileDialog
this.multiCallback = null;
}
- private void SetCallback(Action action)
- {
- this.callback = action;
- this.multiCallback = null;
- }
-
- private void SetCallback(Action> 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> multi)
+ {
+ this.multiCallback = multi;
+ }
+ else
+ {
+ this.callback = callback as Action;
+ }
+
this.dialog = new FileDialog(id, title, filters, path, defaultFileName, defaultExtension, selectionCountMax, isModal, flags);
this.dialog.Show();
}