UI: Added recent files menu

This commit is contained in:
Sour 2019-03-10 19:37:42 -04:00
parent 2893664d0f
commit 9188baf7f1
7 changed files with 164 additions and 59 deletions

View file

@ -87,7 +87,7 @@ extern "C" {
} }
} }
DllExport void __stdcall LoadRom(char* filename, char* patchFile) { _console->LoadRom((VirtualFile)filename, (VirtualFile)patchFile); } DllExport void __stdcall LoadRom(char* filename, char* patchFile) { _console->LoadRom((VirtualFile)filename, patchFile ? (VirtualFile)patchFile : VirtualFile()); }
//DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); } //DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); }
//DllExport void __stdcall SetFolderOverrides(char* saveFolder, char* saveStateFolder, char* screenshotFolder) { FolderUtilities::SetFolderOverrides(saveFolder, saveStateFolder, screenshotFolder); } //DllExport void __stdcall SetFolderOverrides(char* saveFolder, char* saveStateFolder, char* screenshotFolder) { FolderUtilities::SetFolderOverrides(saveFolder, saveStateFolder, screenshotFolder); }

View file

@ -12,11 +12,10 @@ namespace Mesen.GUI.Config
{ {
public class Configuration public class Configuration
{ {
private const int MaxRecentFiles = 10;
private bool _needToSave = false; private bool _needToSave = false;
public string Version = "0.1.0"; public string Version = "0.1.0";
public List<RecentItem> RecentFiles; public RecentItems RecentFiles;
public VideoConfig Video; public VideoConfig Video;
public AudioConfig Audio; public AudioConfig Audio;
public DebugInfo Debug; public DebugInfo Debug;
@ -25,7 +24,7 @@ namespace Mesen.GUI.Config
public Configuration() public Configuration()
{ {
RecentFiles = new List<RecentItem>(); RecentFiles = new RecentItems();
Debug = new DebugInfo(); Debug = new DebugInfo();
Video = new VideoConfig(); Video = new VideoConfig();
Audio = new AudioConfig(); Audio = new AudioConfig();
@ -61,21 +60,6 @@ namespace Mesen.GUI.Config
public void InitializeDefaults() public void InitializeDefaults()
{ {
} }
public void AddRecentFile(ResourcePath romFile, ResourcePath? patchFile)
{
RecentItem existingItem = RecentFiles.Where((item) => item.RomFile == romFile && item.PatchFile == patchFile).FirstOrDefault();
if(existingItem != null) {
RecentFiles.Remove(existingItem);
}
RecentItem recentItem = new RecentItem { RomFile = romFile, PatchFile = patchFile };
RecentFiles.Insert(0, recentItem);
if(RecentFiles.Count > Configuration.MaxRecentFiles) {
RecentFiles.RemoveAt(Configuration.MaxRecentFiles);
}
ConfigManager.ApplyChanges();
}
public static Configuration Deserialize(string configFile) public static Configuration Deserialize(string configFile)
{ {
@ -122,27 +106,6 @@ namespace Mesen.GUI.Config
} }
} }
public class RecentItem
{
public ResourcePath RomFile;
public ResourcePath? PatchFile;
public override string ToString()
{
string text;
/*if(ConfigManager.Config.PreferenceInfo.ShowFullPathInRecents) {
text = RomFile.ReadablePath.Replace("&", "&&");
} else {*/
text = Path.GetFileName(RomFile.FileName).Replace("&", "&&");
//}
if(PatchFile.HasValue) {
text += " [" + Path.GetFileName(PatchFile.Value) + "]";
}
return text;
}
}
[Flags] [Flags]
public enum DefaultKeyMappingType public enum DefaultKeyMappingType
{ {

71
UI/Config/RecentItems.cs Normal file
View file

@ -0,0 +1,71 @@
using Mesen.GUI.Forms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesen.GUI.Config
{
public class RecentItems
{
private const int MaxRecentFiles = 10;
public List<RecentItem> Items;
public void AddRecentFile(ResourcePath romFile, ResourcePath? patchFile)
{
if(patchFile.HasValue && string.IsNullOrWhiteSpace(patchFile)) {
patchFile = null;
}
RecentItem existingItem = Items.Where((item) => item.RomFile == romFile && item.PatchFile == patchFile).FirstOrDefault();
if(existingItem != null) {
Items.Remove(existingItem);
}
RecentItem recentItem = new RecentItem { RomFile = romFile, PatchFile = patchFile };
Items.Insert(0, recentItem);
if(Items.Count > RecentItems.MaxRecentFiles) {
Items.RemoveAt(RecentItems.MaxRecentFiles);
}
ConfigManager.ApplyChanges();
}
public List<ToolStripItem> GetMenuItems()
{
List<ToolStripItem> menuItems = new List<ToolStripItem>();
foreach(RecentItem recentItem in Items) {
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = recentItem.ToString();
tsmi.Click += (object sender, EventArgs args) => {
EmuRunner.LoadRom(recentItem.RomFile, recentItem.PatchFile);
};
menuItems.Add(tsmi);
}
return menuItems;
}
}
public class RecentItem
{
public ResourcePath RomFile;
public ResourcePath? PatchFile;
public override string ToString()
{
string text;
/*if(ConfigManager.Config.PreferenceInfo.ShowFullPathInRecents) {
text = RomFile.ReadablePath.Replace("&", "&&");
} else {*/
text = Path.GetFileName(RomFile.FileName).Replace("&", "&&");
//}
if(PatchFile.HasValue) {
text += " [" + Path.GetFileName(PatchFile.Value) + "]";
}
return text;
}
}
}

28
UI/EmuRunner.cs Normal file
View file

@ -0,0 +1,28 @@
using Mesen.GUI.Config;
using Mesen.GUI.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Mesen.GUI
{
public static class EmuRunner
{
private static Thread _emuThread = null;
public static void LoadRom(ResourcePath romPath, ResourcePath? patchPath = null)
{
EmuApi.LoadRom(romPath, patchPath);
ConfigManager.Config.RecentFiles.AddRecentFile(romPath, patchPath);
_emuThread = new Thread(() => {
EmuApi.Run();
});
_emuThread.Start();
}
}
}

View file

@ -32,6 +32,7 @@
this.mnuFile = new System.Windows.Forms.ToolStripMenuItem(); this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
this.mnuOpen = new System.Windows.Forms.ToolStripMenuItem(); this.mnuOpen = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuAudioConfig = new System.Windows.Forms.ToolStripMenuItem();
this.mnuVideoConfig = new System.Windows.Forms.ToolStripMenuItem(); this.mnuVideoConfig = new System.Windows.Forms.ToolStripMenuItem();
this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRun = new System.Windows.Forms.ToolStripMenuItem(); this.mnuRun = new System.Windows.Forms.ToolStripMenuItem();
@ -44,7 +45,10 @@
this.mnuTilemapViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuTilemapViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEventViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuEventViewer = new System.Windows.Forms.ToolStripMenuItem();
this.pnlRenderer = new System.Windows.Forms.Panel(); this.pnlRenderer = new System.Windows.Forms.Panel();
this.mnuAudioConfig = new System.Windows.Forms.ToolStripMenuItem(); this.mnuRecentFiles = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripSeparator();
this.mnuExit = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.mnuMain.SuspendLayout(); this.mnuMain.SuspendLayout();
this.pnlRenderer.SuspendLayout(); this.pnlRenderer.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -71,17 +75,22 @@
// mnuFile // mnuFile
// //
this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuOpen}); this.mnuOpen,
this.toolStripMenuItem2,
this.mnuRecentFiles,
this.toolStripMenuItem6,
this.mnuExit});
this.mnuFile.Name = "mnuFile"; this.mnuFile.Name = "mnuFile";
this.mnuFile.Size = new System.Drawing.Size(37, 20); this.mnuFile.Size = new System.Drawing.Size(37, 20);
this.mnuFile.Text = "File"; this.mnuFile.Text = "File";
this.mnuFile.DropDownOpening += new System.EventHandler(this.mnuFile_DropDownOpening);
// //
// mnuOpen // mnuOpen
// //
this.mnuOpen.Image = global::Mesen.GUI.Properties.Resources.Folder; this.mnuOpen.Image = global::Mesen.GUI.Properties.Resources.Folder;
this.mnuOpen.Name = "mnuOpen"; this.mnuOpen.Name = "mnuOpen";
this.mnuOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); this.mnuOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
this.mnuOpen.Size = new System.Drawing.Size(146, 22); this.mnuOpen.Size = new System.Drawing.Size(152, 22);
this.mnuOpen.Text = "Open"; this.mnuOpen.Text = "Open";
this.mnuOpen.Click += new System.EventHandler(this.mnuOpen_Click); this.mnuOpen.Click += new System.EventHandler(this.mnuOpen_Click);
// //
@ -94,6 +103,14 @@
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.optionsToolStripMenuItem.Text = "Options"; this.optionsToolStripMenuItem.Text = "Options";
// //
// mnuAudioConfig
//
this.mnuAudioConfig.Image = global::Mesen.GUI.Properties.Resources.Audio;
this.mnuAudioConfig.Name = "mnuAudioConfig";
this.mnuAudioConfig.Size = new System.Drawing.Size(152, 22);
this.mnuAudioConfig.Text = "Audio";
this.mnuAudioConfig.Click += new System.EventHandler(this.mnuAudioConfig_Click);
//
// mnuVideoConfig // mnuVideoConfig
// //
this.mnuVideoConfig.Image = global::Mesen.GUI.Properties.Resources.VideoOptions; this.mnuVideoConfig.Image = global::Mesen.GUI.Properties.Resources.VideoOptions;
@ -197,13 +214,29 @@
this.pnlRenderer.Size = new System.Drawing.Size(512, 448); this.pnlRenderer.Size = new System.Drawing.Size(512, 448);
this.pnlRenderer.TabIndex = 2; this.pnlRenderer.TabIndex = 2;
// //
// mnuAudioConfig // mnuRecentFiles
// //
this.mnuAudioConfig.Image = global::Mesen.GUI.Properties.Resources.Audio; this.mnuRecentFiles.Name = "mnuRecentFiles";
this.mnuAudioConfig.Name = "mnuAudioConfig"; this.mnuRecentFiles.Size = new System.Drawing.Size(152, 22);
this.mnuAudioConfig.Size = new System.Drawing.Size(152, 22); this.mnuRecentFiles.Text = "Recent Files";
this.mnuAudioConfig.Text = "Audio"; //
this.mnuAudioConfig.Click += new System.EventHandler(this.mnuAudioConfig_Click); // toolStripMenuItem6
//
this.toolStripMenuItem6.Name = "toolStripMenuItem6";
this.toolStripMenuItem6.Size = new System.Drawing.Size(149, 6);
//
// mnuExit
//
this.mnuExit.Image = global::Mesen.GUI.Properties.Resources.Exit;
this.mnuExit.Name = "mnuExit";
this.mnuExit.Size = new System.Drawing.Size(152, 22);
this.mnuExit.Text = "Exit";
this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
// //
// frmMain // frmMain
// //
@ -244,5 +277,9 @@
private System.Windows.Forms.ToolStripMenuItem mnuVideoConfig; private System.Windows.Forms.ToolStripMenuItem mnuVideoConfig;
private System.Windows.Forms.Panel pnlRenderer; private System.Windows.Forms.Panel pnlRenderer;
private System.Windows.Forms.ToolStripMenuItem mnuAudioConfig; private System.Windows.Forms.ToolStripMenuItem mnuAudioConfig;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem mnuRecentFiles;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem6;
private System.Windows.Forms.ToolStripMenuItem mnuExit;
} }
} }

View file

@ -136,7 +136,7 @@ namespace Mesen.GUI.Forms
using(OpenFileDialog ofd = new OpenFileDialog()) { using(OpenFileDialog ofd = new OpenFileDialog()) {
ofd.Filter = ResourceHelper.GetMessage("FilterRom"); ofd.Filter = ResourceHelper.GetMessage("FilterRom");
if(ofd.ShowDialog() == DialogResult.OK) { if(ofd.ShowDialog() == DialogResult.OK) {
LoadFile(ofd.FileName); EmuRunner.LoadRom(ofd.FileName);
} }
} }
} }
@ -151,14 +151,6 @@ namespace Mesen.GUI.Forms
DebugApi.Step(1000); DebugApi.Step(1000);
} }
private void LoadFile(string filepath)
{
EmuApi.LoadRom(filepath);
Task.Run(() => {
EmuApi.Run();
});
}
protected override void OnDragDrop(DragEventArgs e) protected override void OnDragDrop(DragEventArgs e)
{ {
base.OnDragDrop(e); base.OnDragDrop(e);
@ -166,7 +158,7 @@ namespace Mesen.GUI.Forms
try { try {
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if(File.Exists(files[0])) { if(File.Exists(files[0])) {
LoadFile(files[0]); EmuRunner.LoadRom(files[0]);
this.Activate(); this.Activate();
} else { } else {
//InteropEmu.DisplayMessage("Error", "File not found: " + files[0]); //InteropEmu.DisplayMessage("Error", "File not found: " + files[0]);
@ -190,5 +182,17 @@ namespace Mesen.GUI.Forms
MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
} }
} }
private void mnuExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void mnuFile_DropDownOpening(object sender, EventArgs e)
{
mnuRecentFiles.DropDownItems.Clear();
mnuRecentFiles.DropDownItems.AddRange(ConfigManager.Config.RecentFiles.GetMenuItems().ToArray());
mnuRecentFiles.Enabled = ConfigManager.Config.RecentFiles.Items.Count > 0;
}
} }
} }

View file

@ -233,6 +233,7 @@
<Compile Include="Debugger\Config\DebuggerShortcutsConfig.cs" /> <Compile Include="Debugger\Config\DebuggerShortcutsConfig.cs" />
<Compile Include="Debugger\Config\EventViewerInfo.cs" /> <Compile Include="Debugger\Config\EventViewerInfo.cs" />
<Compile Include="Debugger\Config\HexEditorInfo.cs" /> <Compile Include="Debugger\Config\HexEditorInfo.cs" />
<Compile Include="Config\RecentItems.cs" />
<Compile Include="Debugger\Config\TraceLoggerInfo.cs" /> <Compile Include="Debugger\Config\TraceLoggerInfo.cs" />
<Compile Include="Debugger\Config\DebugInfo.cs" /> <Compile Include="Debugger\Config\DebugInfo.cs" />
<Compile Include="Controls\BaseControl.cs"> <Compile Include="Controls\BaseControl.cs">
@ -502,6 +503,7 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceExtractor.cs" /> <Compile Include="ResourceExtractor.cs" />
<Compile Include="EmuRunner.cs" />
<Compile Include="RuntimeChecker.cs" /> <Compile Include="RuntimeChecker.cs" />
<Compile Include="SingleInstance.cs" /> <Compile Include="SingleInstance.cs" />
<Compile Include="Utilities\HexConverter.cs" /> <Compile Include="Utilities\HexConverter.cs" />