From 2becb128559b3387db7658bc270c5548edca954d Mon Sep 17 00:00:00 2001
From: Ottermandias <70807659+Ottermandias@users.noreply.github.com>
Date: Mon, 18 Apr 2022 01:25:00 +0200
Subject: [PATCH] FilePicker additions (#798)
---
.../Interface/ImGuiFileDialog/FileDialog.cs | 7 +--
.../ImGuiFileDialog/FileDialogManager.cs | 45 +++++++++++++++----
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.cs
index 9e2a77f0d..98b70a3ab 100644
--- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.cs
@@ -115,8 +115,9 @@ namespace Dalamud.Interface.ImGuiFileDialog
///
/// Gets the result of the selection.
///
- /// The result of the selection (file or folder path). If multiple entries were selected, they are separated with commas.
- public string GetResult()
+ /// The separator to put between multiple selected entries.
+ /// The result of the selection (file or folder path). If multiple entries were selected, they are separated with the given separator, which is a comma by default.
+ public string GetResult(char separator = ',')
{
if (!this.flags.HasFlag(ImGuiFileDialogFlags.SelectOnly))
{
@@ -129,7 +130,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
}
var fullPaths = this.selectedFileNames.Where(x => !string.IsNullOrEmpty(x)).Select(x => Path.Combine(this.currentPath, x));
- return string.Join(",", fullPaths.ToArray());
+ return string.Join(separator, fullPaths.ToArray());
}
///
diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
index 18bd9dc14..2c1bab735 100644
--- a/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
+++ b/Dalamud/Interface/ImGuiFileDialog/FileDialogManager.cs
@@ -10,15 +10,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
private FileDialog dialog;
private string savedPath = ".";
private Action callback;
+ private char selectionSeparator;
///
/// Create a dialog which selects an already existing folder.
///
/// The header title of the dialog.
/// The action to execute when the dialog is finished.
- public void OpenFolderDialog(string title, Action callback)
+ /// The directory which the dialog should start inside of.
+ /// Whether the dialog should be a modal popup.
+ public void OpenFolderDialog(string title, Action callback, string? startPath = null, bool isModal = false)
{
- this.SetDialog("OpenFolderDialog", title, string.Empty, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly, callback);
+ this.SetDialog("OpenFolderDialog", title, string.Empty, startPath ?? this.savedPath, ".", string.Empty, 1, isModal, ImGuiFileDialogFlags.SelectOnly, callback);
}
///
@@ -27,9 +30,11 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The header title of the dialog.
/// The default name to use when creating a new folder.
/// The action to execute when the dialog is finished.
- public void SaveFolderDialog(string title, string defaultFolderName, Action callback)
+ /// The directory which the dialog should start inside of.
+ /// Whether the dialog should be a modal popup.
+ public void SaveFolderDialog(string title, string defaultFolderName, Action callback, string? startPath = null, bool isModal = false)
{
- this.SetDialog("SaveFolderDialog", title, string.Empty, this.savedPath, defaultFolderName, string.Empty, 1, false, ImGuiFileDialogFlags.None, callback);
+ this.SetDialog("SaveFolderDialog", title, string.Empty, startPath ?? this.savedPath, defaultFolderName, string.Empty, 1, isModal, ImGuiFileDialogFlags.None, callback);
}
///
@@ -38,9 +43,21 @@ 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.
- public void OpenFileDialog(string title, string filters, Action callback)
+ /// The directory which the dialog should start inside of.
+ /// The maximum amount of files or directories which can be selected. Set to 0 for an infinite number.
+ /// The separator to put between multiple selected entries.
+ /// Whether the dialog should be a modal popup.
+ public void OpenFileDialog(
+ string title,
+ string filters,
+ Action callback,
+ string? startPath = null,
+ int selectionCountMax = 1,
+ char selectionSeparator = '\0',
+ bool isModal = false)
{
- this.SetDialog("OpenFileDialog", title, filters, this.savedPath, ".", string.Empty, 1, false, ImGuiFileDialogFlags.SelectOnly, callback);
+ this.selectionSeparator = selectionSeparator;
+ this.SetDialog("OpenFileDialog", title, filters, startPath ?? this.savedPath, ".", string.Empty, selectionCountMax, isModal, ImGuiFileDialogFlags.SelectOnly, callback);
}
///
@@ -51,9 +68,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
/// The default name to use when creating a new file.
/// The extension to use when creating a new file.
/// The action to execute when the dialog is finished.
- public void SaveFileDialog(string title, string filters, string defaultFileName, string defaultExtension, Action callback)
+ /// The directory which the dialog should start inside of.
+ /// Whether the dialog should be a modal popup.
+ public void SaveFileDialog(
+ string title,
+ string filters,
+ string defaultFileName,
+ string defaultExtension,
+ Action callback,
+ string? startPath = null,
+ bool isModal = false)
{
- this.SetDialog("SaveFileDialog", title, filters, this.savedPath, defaultFileName, defaultExtension, 1, false, ImGuiFileDialogFlags.None, callback);
+ this.SetDialog("SaveFileDialog", title, filters, startPath ?? this.savedPath, defaultFileName, defaultExtension, 1, isModal, ImGuiFileDialogFlags.None, callback);
}
///
@@ -64,7 +90,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
if (this.dialog == null) return;
if (this.dialog.Draw())
{
- this.callback(this.dialog.GetIsOk(), this.dialog.GetResult());
+ this.callback(this.dialog.GetIsOk(), this.dialog.GetResult(this.selectionSeparator));
this.savedPath = this.dialog.GetCurrentPath();
this.Reset();
}
@@ -78,6 +104,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
this.dialog?.Hide();
this.dialog = null;
this.callback = null;
+ this.selectionSeparator = '\0';
}
private void SetDialog(