Extended file picker to support drives
This commit is contained in:
parent
b9d2039995
commit
32a9b10491
4 changed files with 93 additions and 200 deletions
|
@ -6,19 +6,19 @@ namespace Ryujinx.UI.Widgets
|
|||
{
|
||||
public partial class ConfigurationWidget
|
||||
{
|
||||
static bool ConfigIntialized = false;
|
||||
static bool OpenFolderPicker;
|
||||
static bool ConfigIntialized = false;
|
||||
static bool OpenFolderPicker;
|
||||
static string CurrentPath;
|
||||
|
||||
static IniParser IniParser;
|
||||
static FolderPicker FolderPicker;
|
||||
static JoyCon CurrentJoyConLayout;
|
||||
static Page CurrentPage = Page.General;
|
||||
static IniParser IniParser;
|
||||
static FilePicker FolderPicker;
|
||||
static JoyCon CurrentJoyConLayout;
|
||||
static Page CurrentPage = Page.General;
|
||||
|
||||
static ConfigurationWidget()
|
||||
{
|
||||
IniParser = new IniParser(Config.IniPath);
|
||||
FolderPicker = FolderPicker.GetFolderPicker("FolderDialog",Config.DefaultGameDirectory);
|
||||
FolderPicker = FilePicker.GetFilePicker("FolderDialog",Config.DefaultGameDirectory);
|
||||
CurrentPath = Config.DefaultGameDirectory.ToString();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace Ryujinx.UI.Widgets
|
|||
OpenFolderPicker = true;
|
||||
}
|
||||
if (OpenFolderPicker)
|
||||
ImGui.OpenPopup("OpenFolder");
|
||||
ImGui.OpenPopup("Open Folder");
|
||||
|
||||
DialogResult DialogResult = FolderPicker.GetFolder(ref CurrentPath);
|
||||
if (DialogResult == DialogResult.OK)
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace ImGuiNET
|
|||
|
||||
public string CurrentFolder { get; set; }
|
||||
public string SelectedEntry { get; set; }
|
||||
public string CurrentDrive { get; set; }
|
||||
|
||||
public static FilePicker GetFilePicker(object Id, string StartingPath)
|
||||
{
|
||||
|
@ -46,16 +47,40 @@ namespace ImGuiNET
|
|||
return FilePicker;
|
||||
}
|
||||
|
||||
public DialogResult Draw(ref string SelectedPath, bool ReturnOnSelection)
|
||||
public DialogResult Draw(ref string SelectedPath, bool ReturnOnSelection, bool FoldersOnly = false)
|
||||
{
|
||||
return DrawFolder(ref SelectedPath, ReturnOnSelection);
|
||||
return DrawFolder(ref SelectedPath, ReturnOnSelection, FoldersOnly);
|
||||
}
|
||||
|
||||
private DialogResult DrawFolder(ref string SelectedPath, bool ReturnOnSelection = false)
|
||||
private DialogResult DrawFolder(ref string SelectedPath, bool ReturnOnSelection = false, bool FoldersOnly = false)
|
||||
{
|
||||
ImGui.Text("Current Folder: " + CurrentFolder);
|
||||
|
||||
if (ImGui.BeginChildFrame(1, ImGui.GetContentRegionAvailable() - new Vector2(20, Values.ButtonHeight),
|
||||
if(ImGui.BeginChildFrame(0,new Vector2(ImGui.GetContentRegionAvailableWidth()/3,
|
||||
ImGui.GetContentRegionAvailable().Y - Values.ButtonHeight - 10), WindowFlags.Default))
|
||||
{
|
||||
DriveInfo[] DriveList = DriveInfo.GetDrives();
|
||||
|
||||
foreach(DriveInfo Drive in DriveList)
|
||||
{
|
||||
bool IsSelected = CurrentDrive == Drive.Name;
|
||||
|
||||
ImGui.PushStyleColor(ColorTarget.Text, Values.Color.Yellow);
|
||||
|
||||
if (ImGui.Selectable(Drive.Name + "/", IsSelected, SelectableFlags.DontClosePopups
|
||||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
{
|
||||
CurrentDrive = Drive.Name;
|
||||
CurrentFolder = Drive.Name;
|
||||
}
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui.EndChildFrame();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.BeginChildFrame(1, ImGui.GetContentRegionAvailable() - new Vector2(20, Values.ButtonHeight + 10),
|
||||
WindowFlags.Default))
|
||||
{
|
||||
DirectoryInfo CurrentDirectory = new DirectoryInfo(CurrentFolder);
|
||||
|
@ -87,41 +112,43 @@ namespace ImGuiNET
|
|||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
{
|
||||
SelectedEntry = Dir;
|
||||
SelectedPath = SelectedEntry;
|
||||
SelectedPath = SelectedEntry;
|
||||
}
|
||||
|
||||
if (SelectedEntry != null)
|
||||
if (ImGui.IsMouseDoubleClicked(0) && SelectedEntry.Equals(Dir))
|
||||
{
|
||||
SelectedEntry = null;
|
||||
SelectedPath = null;
|
||||
SelectedPath = null;
|
||||
CurrentFolder = Dir;
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
foreach (string File in Directory.EnumerateFiles(CurrentDirectory.FullName))
|
||||
{
|
||||
string Name = Path.GetFileName(File);
|
||||
bool IsSelected = SelectedEntry == File;
|
||||
|
||||
if (ImGui.Selectable(Name, IsSelected, SelectableFlags.DontClosePopups
|
||||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
if (!FoldersOnly)
|
||||
foreach (string File in Directory.EnumerateFiles(CurrentDirectory.FullName))
|
||||
{
|
||||
SelectedEntry = File;
|
||||
if (ReturnOnSelection)
|
||||
{
|
||||
SelectedPath = SelectedEntry;
|
||||
}
|
||||
}
|
||||
string Name = Path.GetFileName(File);
|
||||
bool IsSelected = SelectedEntry == File;
|
||||
|
||||
if (SelectedEntry != null)
|
||||
if (ImGui.IsMouseDoubleClicked(0) && SelectedEntry.Equals(File))
|
||||
if (ImGui.Selectable(Name, IsSelected, SelectableFlags.DontClosePopups
|
||||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
{
|
||||
SelectedPath = File;
|
||||
SelectedEntry = File;
|
||||
if (ReturnOnSelection)
|
||||
{
|
||||
SelectedPath = SelectedEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SelectedEntry != null)
|
||||
if (ImGui.IsMouseDoubleClicked(0) && SelectedEntry.Equals(File))
|
||||
{
|
||||
SelectedPath = File;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui.EndChildFrame();
|
||||
|
@ -135,7 +162,7 @@ namespace ImGuiNET
|
|||
if (SelectedEntry != null)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Load", new Vector2(Values.ButtonWidth, Values.ButtonHeight)))
|
||||
if (ImGui.Button("Open", new Vector2(Values.ButtonWidth, Values.ButtonHeight)))
|
||||
{
|
||||
SelectedPath = SelectedEntry;
|
||||
|
||||
|
@ -151,5 +178,37 @@ namespace ImGuiNET
|
|||
|
||||
return DialogResult.None;
|
||||
}
|
||||
|
||||
public DialogResult GetFolder(ref string CurrentPath)
|
||||
{
|
||||
ImGui.SetNextWindowSize(new Vector2(600, 600), Condition.FirstUseEver);
|
||||
if (ImGui.BeginPopupModal("Open Folder", WindowFlags.NoResize))
|
||||
{
|
||||
try
|
||||
{
|
||||
string Output = CurrentPath;
|
||||
DialogResult DialogResult = Draw(ref Output, false, true);
|
||||
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Output))
|
||||
{
|
||||
return DialogResult.None;
|
||||
}
|
||||
}
|
||||
|
||||
if (DialogResult != DialogResult.None)
|
||||
ImGui.CloseCurrentPopup();
|
||||
|
||||
return DialogResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
return DialogResult.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
|
||||
namespace ImGuiNET
|
||||
{
|
||||
/// <summary>
|
||||
/// Adapted from Mellinoe's file picker for imgui
|
||||
/// https://github.com/mellinoe/synthapp/blob/master/src/synthapp/Widgets/FilePicker.cs
|
||||
/// </summary>
|
||||
public class FolderPicker
|
||||
{
|
||||
private const string FolderPickerID = "###FolderPicker";
|
||||
private static readonly Dictionary<object, FolderPicker> FolderPickers
|
||||
= new Dictionary<object, FolderPicker>();
|
||||
private static readonly Vector2 DefaultFilePickerSize = new Vector2(600, 400);
|
||||
|
||||
public string CurrentFolder { get; set; }
|
||||
public string SelectedDirectory { get; set; }
|
||||
|
||||
public static FolderPicker GetFolderPicker(object Id, string StartingPath)
|
||||
{
|
||||
if (File.Exists(StartingPath))
|
||||
{
|
||||
StartingPath = new FileInfo(StartingPath).DirectoryName;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(StartingPath) || !Directory.Exists(StartingPath))
|
||||
{
|
||||
StartingPath = Environment.CurrentDirectory;
|
||||
if (string.IsNullOrEmpty(StartingPath))
|
||||
{
|
||||
StartingPath = AppContext.BaseDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
if (!FolderPickers.TryGetValue(Id, out FolderPicker FolderPicker))
|
||||
{
|
||||
FolderPicker = new FolderPicker
|
||||
{
|
||||
CurrentFolder = StartingPath
|
||||
};
|
||||
|
||||
FolderPickers.Add(Id, FolderPicker);
|
||||
}
|
||||
|
||||
return FolderPicker;
|
||||
}
|
||||
|
||||
public DialogResult Draw(ref string Selected, bool ReturnOnSelection)
|
||||
{
|
||||
return DrawFolder(ref Selected, ReturnOnSelection);
|
||||
}
|
||||
|
||||
private DialogResult DrawFolder(ref string Selected, bool ReturnOnSelection = false)
|
||||
{
|
||||
ImGui.Text("Current Folder: " + CurrentFolder);
|
||||
|
||||
if (ImGui.BeginChildFrame(1, ImGui.GetContentRegionAvailable() - new Vector2(20, Values.ButtonHeight),
|
||||
WindowFlags.Default))
|
||||
{
|
||||
DirectoryInfo CurrentDirectory = new DirectoryInfo(CurrentFolder);
|
||||
if (CurrentDirectory.Exists)
|
||||
{
|
||||
if (CurrentDirectory.Parent != null)
|
||||
{
|
||||
ImGui.PushStyleColor(ColorTarget.Text, Values.Color.Yellow);
|
||||
|
||||
if (ImGui.Selectable("../", false, SelectableFlags.DontClosePopups
|
||||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
{
|
||||
CurrentFolder = CurrentDirectory.Parent.FullName;
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
foreach (var Dir in Directory.EnumerateFileSystemEntries(CurrentDirectory.FullName))
|
||||
{
|
||||
if (Directory.Exists(Dir))
|
||||
{
|
||||
string Name = Path.GetFileName(Dir);
|
||||
bool IsSelected = SelectedDirectory == Dir;
|
||||
|
||||
ImGui.PushStyleColor(ColorTarget.Text, Values.Color.Yellow);
|
||||
|
||||
if (ImGui.Selectable(Name + "/", IsSelected, SelectableFlags.DontClosePopups
|
||||
, new Vector2(ImGui.GetContentRegionAvailableWidth(), Values.SelectibleHeight)))
|
||||
{
|
||||
SelectedDirectory = Dir;
|
||||
Selected = SelectedDirectory;
|
||||
}
|
||||
|
||||
if (SelectedDirectory != null)
|
||||
if (ImGui.IsMouseDoubleClicked(0) && SelectedDirectory.Equals(Dir))
|
||||
{
|
||||
SelectedDirectory = null;
|
||||
Selected = null;
|
||||
CurrentFolder = Dir;
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui.EndChildFrame();
|
||||
|
||||
|
||||
if (ImGui.Button("Cancel", new Vector2(Values.ButtonWidth, Values.ButtonHeight)))
|
||||
{
|
||||
return DialogResult.Cancel;
|
||||
}
|
||||
|
||||
if (SelectedDirectory != null)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Open", new Vector2(Values.ButtonWidth, Values.ButtonHeight)))
|
||||
{
|
||||
Selected = SelectedDirectory;
|
||||
|
||||
return DialogResult.OK;
|
||||
}
|
||||
else if(ReturnOnSelection)
|
||||
{
|
||||
Selected = SelectedDirectory;
|
||||
|
||||
return DialogResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
return DialogResult.None;
|
||||
}
|
||||
|
||||
public DialogResult GetFolder(ref string CurrentPath)
|
||||
{
|
||||
ImGui.SetNextWindowSize(new Vector2(500, 500), Condition.FirstUseEver);
|
||||
if (ImGui.BeginPopupModal("OpenFolder", WindowFlags.NoResize))
|
||||
{
|
||||
try
|
||||
{
|
||||
string Output = CurrentPath;
|
||||
DialogResult DialogResult = Draw(ref Output, false);
|
||||
|
||||
if (DialogResult == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Output))
|
||||
{
|
||||
return DialogResult.None;
|
||||
}
|
||||
}
|
||||
|
||||
if(DialogResult!= DialogResult.None)
|
||||
ImGui.CloseCurrentPopup();
|
||||
|
||||
return DialogResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
return DialogResult.None;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,12 +14,12 @@ namespace Ryujinx.UI.Widgets
|
|||
static string GameDirectory;
|
||||
static List<GameItem> GameItems;
|
||||
static GameItem SelectedGame;
|
||||
static FolderPicker FolderPicker;
|
||||
static FilePicker FolderPicker;
|
||||
|
||||
static GameList()
|
||||
{
|
||||
GameDirectory = Config.DefaultGameDirectory;
|
||||
FolderPicker = FolderPicker.GetFolderPicker("FolderDialog", Config.DefaultGameDirectory);
|
||||
FolderPicker = FilePicker.GetFilePicker("FolderDialog", Config.DefaultGameDirectory);
|
||||
|
||||
Refresh(GameDirectory);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ namespace Ryujinx.UI.Widgets
|
|||
}
|
||||
|
||||
if (OpenFolderPicker)
|
||||
ImGui.OpenPopup("OpenFolder");
|
||||
ImGui.OpenPopup("Open Folder");
|
||||
|
||||
DialogResult DialogResult = FolderPicker.GetFolder(ref GameDirectory);
|
||||
if (DialogResult == DialogResult.OK)
|
||||
|
|
Loading…
Add table
Reference in a new issue