mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
FilePicker additions (#798)
This commit is contained in:
parent
c4343d0976
commit
2becb12855
2 changed files with 40 additions and 12 deletions
|
|
@ -115,8 +115,9 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the result of the selection.
|
/// Gets the result of the selection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The result of the selection (file or folder path). If multiple entries were selected, they are separated with commas.</returns>
|
/// <param name="separator">The separator to put between multiple selected entries.</param>
|
||||||
public string GetResult()
|
/// <returns>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.</returns>
|
||||||
|
public string GetResult(char separator = ',')
|
||||||
{
|
{
|
||||||
if (!this.flags.HasFlag(ImGuiFileDialogFlags.SelectOnly))
|
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));
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
private FileDialog dialog;
|
private FileDialog dialog;
|
||||||
private string savedPath = ".";
|
private string savedPath = ".";
|
||||||
private Action<bool, string> callback;
|
private Action<bool, string> callback;
|
||||||
|
private char selectionSeparator;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a dialog which selects an already existing folder.
|
/// Create a dialog which selects an already existing folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="title">The header title of the dialog.</param>
|
/// <param name="title">The header title of the dialog.</param>
|
||||||
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
||||||
public void OpenFolderDialog(string title, Action<bool, string> callback)
|
/// <param name="startPath">The directory which the dialog should start inside of.</param>
|
||||||
|
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
|
||||||
|
public void OpenFolderDialog(string title, Action<bool, string> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -27,9 +30,11 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
/// <param name="title">The header title of the dialog.</param>
|
/// <param name="title">The header title of the dialog.</param>
|
||||||
/// <param name="defaultFolderName">The default name to use when creating a new folder.</param>
|
/// <param name="defaultFolderName">The default name to use when creating a new folder.</param>
|
||||||
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
||||||
public void SaveFolderDialog(string title, string defaultFolderName, Action<bool, string> callback)
|
/// <param name="startPath">The directory which the dialog should start inside of.</param>
|
||||||
|
/// <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 = 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -38,9 +43,21 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
/// <param name="title">The header title of the dialog.</param>
|
/// <param name="title">The header title of the dialog.</param>
|
||||||
/// <param name="filters">Which files to show in 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="callback">The action to execute when the dialog is finished.</param>
|
||||||
public void OpenFileDialog(string title, string filters, Action<bool, string> callback)
|
/// <param name="startPath">The directory which the dialog should start inside of.</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="selectionSeparator">The separator to put between multiple selected entries.</param>
|
||||||
|
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
|
||||||
|
public void OpenFileDialog(
|
||||||
|
string title,
|
||||||
|
string filters,
|
||||||
|
Action<bool, string> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -51,9 +68,18 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
/// <param name="defaultFileName">The default name to use when creating a new file.</param>
|
/// <param name="defaultFileName">The default name to use when creating a new file.</param>
|
||||||
/// <param name="defaultExtension">The extension to use when creating a new file.</param>
|
/// <param name="defaultExtension">The extension to use when creating a new file.</param>
|
||||||
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
/// <param name="callback">The action to execute when the dialog is finished.</param>
|
||||||
public void SaveFileDialog(string title, string filters, string defaultFileName, string defaultExtension, Action<bool, string> callback)
|
/// <param name="startPath">The directory which the dialog should start inside of.</param>
|
||||||
|
/// <param name="isModal">Whether the dialog should be a modal popup.</param>
|
||||||
|
public void SaveFileDialog(
|
||||||
|
string title,
|
||||||
|
string filters,
|
||||||
|
string defaultFileName,
|
||||||
|
string defaultExtension,
|
||||||
|
Action<bool, string> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -64,7 +90,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
if (this.dialog == null) return;
|
if (this.dialog == null) return;
|
||||||
if (this.dialog.Draw())
|
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.savedPath = this.dialog.GetCurrentPath();
|
||||||
this.Reset();
|
this.Reset();
|
||||||
}
|
}
|
||||||
|
|
@ -78,6 +104,7 @@ namespace Dalamud.Interface.ImGuiFileDialog
|
||||||
this.dialog?.Hide();
|
this.dialog?.Hide();
|
||||||
this.dialog = null;
|
this.dialog = null;
|
||||||
this.callback = null;
|
this.callback = null;
|
||||||
|
this.selectionSeparator = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetDialog(
|
private void SetDialog(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue