mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
fix: only check FileDialog location existence during navigation (#1196)
* Make DriveListLoader always async instead of usually async * Simplify code * Only check location existence during navigation
This commit is contained in:
parent
48c00da429
commit
69b615f218
3 changed files with 8 additions and 27 deletions
|
|
@ -1,5 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -10,14 +10,12 @@ namespace Dalamud.Interface.ImGuiFileDialog;
|
|||
/// </summary>
|
||||
internal class DriveListLoader
|
||||
{
|
||||
private bool initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DriveListLoader"/> class.
|
||||
/// </summary>
|
||||
public DriveListLoader()
|
||||
{
|
||||
this.Drives = ImmutableArray<DriveInfo>.Empty;
|
||||
this.Drives = Array.Empty<DriveInfo>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -49,23 +47,8 @@ internal class DriveListLoader
|
|||
|
||||
private async Task InitDrives()
|
||||
{
|
||||
var drives = ImmutableArray<DriveInfo>.Empty;
|
||||
foreach (var drive in DriveInfo.GetDrives())
|
||||
{
|
||||
drives = drives.Add(drive);
|
||||
if (!this.initialized)
|
||||
{
|
||||
// Show results as soon as they load initially, but otherwise keep
|
||||
// the existing drive list
|
||||
this.Drives = drives;
|
||||
}
|
||||
|
||||
// Force async to avoid this being invoked synchronously unless it's awaited
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
// Replace the whole drive list
|
||||
this.Drives = drives;
|
||||
this.initialized = true;
|
||||
// Force async to avoid this being invoked synchronously unless it's awaited.
|
||||
await Task.Yield();
|
||||
this.Drives = DriveInfo.GetDrives();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ public partial class FileDialog
|
|||
this.Text = text;
|
||||
this.Location = location;
|
||||
this.Icon = icon;
|
||||
this.Exists = !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
|
||||
}
|
||||
|
||||
public string Text { get; init; }
|
||||
|
|
@ -40,8 +39,6 @@ public partial class FileDialog
|
|||
|
||||
public FontAwesomeIcon Icon { get; init; }
|
||||
|
||||
public bool Exists { get; init; }
|
||||
|
||||
public bool CheckExistence()
|
||||
=> !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.ImGuiFileDialog;
|
||||
|
|
@ -316,7 +317,7 @@ public partial class FileDialog
|
|||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + Scaled(5));
|
||||
|
||||
var idx = 0;
|
||||
foreach (var qa in this.GetDrives().Concat(this.quickAccess).Where(qa => qa.Exists))
|
||||
foreach (var qa in this.GetDrives().Concat(this.quickAccess).Where(qa => !qa.Location.IsNullOrEmpty()))
|
||||
{
|
||||
ImGui.PushID(idx++);
|
||||
ImGui.SetCursorPosX(Scaled(25));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue