mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +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;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
@ -10,14 +10,12 @@ namespace Dalamud.Interface.ImGuiFileDialog;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DriveListLoader
|
internal class DriveListLoader
|
||||||
{
|
{
|
||||||
private bool initialized;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DriveListLoader"/> class.
|
/// Initializes a new instance of the <see cref="DriveListLoader"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DriveListLoader()
|
public DriveListLoader()
|
||||||
{
|
{
|
||||||
this.Drives = ImmutableArray<DriveInfo>.Empty;
|
this.Drives = Array.Empty<DriveInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -49,23 +47,8 @@ internal class DriveListLoader
|
||||||
|
|
||||||
private async Task InitDrives()
|
private async Task InitDrives()
|
||||||
{
|
{
|
||||||
var drives = ImmutableArray<DriveInfo>.Empty;
|
// Force async to avoid this being invoked synchronously unless it's awaited.
|
||||||
foreach (var drive in DriveInfo.GetDrives())
|
await Task.Yield();
|
||||||
{
|
this.Drives = 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ public partial class FileDialog
|
||||||
this.Text = text;
|
this.Text = text;
|
||||||
this.Location = location;
|
this.Location = location;
|
||||||
this.Icon = icon;
|
this.Icon = icon;
|
||||||
this.Exists = !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Text { get; init; }
|
public string Text { get; init; }
|
||||||
|
|
@ -40,8 +39,6 @@ public partial class FileDialog
|
||||||
|
|
||||||
public FontAwesomeIcon Icon { get; init; }
|
public FontAwesomeIcon Icon { get; init; }
|
||||||
|
|
||||||
public bool Exists { get; init; }
|
|
||||||
|
|
||||||
public bool CheckExistence()
|
public bool CheckExistence()
|
||||||
=> !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
|
=> !this.Location.IsNullOrEmpty() && Directory.Exists(this.Location);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
|
using Dalamud.Utility;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
||||||
namespace Dalamud.Interface.ImGuiFileDialog;
|
namespace Dalamud.Interface.ImGuiFileDialog;
|
||||||
|
|
@ -316,7 +317,7 @@ public partial class FileDialog
|
||||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + Scaled(5));
|
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + Scaled(5));
|
||||||
|
|
||||||
var idx = 0;
|
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.PushID(idx++);
|
||||||
ImGui.SetCursorPosX(Scaled(25));
|
ImGui.SetCursorPosX(Scaled(25));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue