From 32a9b10491c7869c93e3e9e3a4a921847e02a767 Mon Sep 17 00:00:00 2001 From: emmaus Date: Wed, 27 Jun 2018 10:23:20 +0000 Subject: [PATCH] Extended file picker to support drives --- .../GUI/Widgets/ConfigurationWidget.cs | 16 +- Ryujinx.ImGui/GUI/Widgets/FilePicker.cs | 105 ++++++++--- Ryujinx.ImGui/GUI/Widgets/FolderPicker.cs | 166 ------------------ Ryujinx.ImGui/GUI/Widgets/GameList.cs | 6 +- 4 files changed, 93 insertions(+), 200 deletions(-) delete mode 100644 Ryujinx.ImGui/GUI/Widgets/FolderPicker.cs diff --git a/Ryujinx.ImGui/GUI/Widgets/ConfigurationWidget.cs b/Ryujinx.ImGui/GUI/Widgets/ConfigurationWidget.cs index b2c758c1e3..7280267f16 100644 --- a/Ryujinx.ImGui/GUI/Widgets/ConfigurationWidget.cs +++ b/Ryujinx.ImGui/GUI/Widgets/ConfigurationWidget.cs @@ -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) diff --git a/Ryujinx.ImGui/GUI/Widgets/FilePicker.cs b/Ryujinx.ImGui/GUI/Widgets/FilePicker.cs index 9653b02e0a..db76997636 100644 --- a/Ryujinx.ImGui/GUI/Widgets/FilePicker.cs +++ b/Ryujinx.ImGui/GUI/Widgets/FilePicker.cs @@ -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; + } } } diff --git a/Ryujinx.ImGui/GUI/Widgets/FolderPicker.cs b/Ryujinx.ImGui/GUI/Widgets/FolderPicker.cs deleted file mode 100644 index eaf8d2690f..0000000000 --- a/Ryujinx.ImGui/GUI/Widgets/FolderPicker.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Numerics; - -namespace ImGuiNET -{ - /// - /// Adapted from Mellinoe's file picker for imgui - /// https://github.com/mellinoe/synthapp/blob/master/src/synthapp/Widgets/FilePicker.cs - /// - public class FolderPicker - { - private const string FolderPickerID = "###FolderPicker"; - private static readonly Dictionary FolderPickers - = new Dictionary(); - 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; - } - } -} diff --git a/Ryujinx.ImGui/GUI/Widgets/GameList.cs b/Ryujinx.ImGui/GUI/Widgets/GameList.cs index 51ebf895d0..b58d179521 100644 --- a/Ryujinx.ImGui/GUI/Widgets/GameList.cs +++ b/Ryujinx.ImGui/GUI/Widgets/GameList.cs @@ -14,12 +14,12 @@ namespace Ryujinx.UI.Widgets static string GameDirectory; static List 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)