Some code refactoring - movie winform specific code from RecentFiles to ToolHelpers
This commit is contained in:
parent
568fe3c1a2
commit
bb2ff540db
|
@ -703,15 +703,23 @@ namespace BizHawk.MultiClient
|
|||
private void recentROMToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
recentROMToolStripMenuItem.DropDownItems.Clear();
|
||||
recentROMToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentRoms.GenerateRecentMenu(LoadRomFromRecent));
|
||||
recentROMToolStripMenuItem.DropDownItems.Add(Global.Config.RecentRoms.GenerateAutoLoadItem());
|
||||
recentROMToolStripMenuItem.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentRoms, LoadRomFromRecent)
|
||||
);
|
||||
recentROMToolStripMenuItem.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentRoms)
|
||||
);
|
||||
}
|
||||
|
||||
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
recentToolStripMenuItem.DropDownItems.Clear();
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentMovies.GenerateRecentMenu(LoadMoviesFromRecent));
|
||||
recentToolStripMenuItem.DropDownItems.Add(Global.Config.RecentMovies.GenerateAutoLoadItem());
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentMovies, LoadMoviesFromRecent)
|
||||
);
|
||||
recentToolStripMenuItem.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentMovies)
|
||||
);
|
||||
}
|
||||
|
||||
private void screenshotAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -738,7 +738,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
if (!LoadRom(rom))
|
||||
{
|
||||
Global.Config.RecentRoms.HandleLoadError(rom);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentRoms, rom);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,7 +748,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
if (!m.Loaded)
|
||||
{
|
||||
Global.Config.RecentMovies.HandleLoadError(path);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentMovies, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
|
@ -10,7 +9,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
private readonly int MAX_RECENT_FILES; //Maximum number of files
|
||||
private readonly List<string> recentlist; //List of recent files
|
||||
|
||||
|
||||
public bool AutoLoad = false;
|
||||
|
||||
public RecentFiles() : this(8) { }
|
||||
|
@ -77,7 +76,6 @@ namespace BizHawk.MultiClient
|
|||
|
||||
public List<string> GetRecentListTruncated(int length)
|
||||
{
|
||||
//iterate through list, truncating each item to length, and return the result in a List<string>
|
||||
return recentlist.Select(t => t.Substring(0, length)).ToList();
|
||||
}
|
||||
|
||||
|
@ -96,55 +94,7 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public void HandleLoadError(string path)
|
||||
{
|
||||
Global.Sound.StopSound();
|
||||
DialogResult result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
Remove(path);
|
||||
}
|
||||
|
||||
Global.Sound.StartSound();
|
||||
}
|
||||
|
||||
public ToolStripItem[] GenerateRecentMenu(Action<string> loadFileCallback)
|
||||
{
|
||||
var items = new List<ToolStripItem>();
|
||||
|
||||
if (Empty)
|
||||
{
|
||||
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
||||
items.Add(none);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string filename in recentlist)
|
||||
{
|
||||
string temp = filename;
|
||||
var item = new ToolStripMenuItem { Text = temp };
|
||||
item.Click += (o, ev) => loadFileCallback(temp);
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
items.Add(new ToolStripSeparator());
|
||||
|
||||
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
||||
clearitem.Click += (o, ev) => recentlist.Clear();
|
||||
items.Add(clearitem);
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
public ToolStripMenuItem GenerateAutoLoadItem()
|
||||
{
|
||||
var auto = new ToolStripMenuItem { Text = "&Auto-Load", Checked = AutoLoad };
|
||||
auto.Click += (o, ev) => ToggleAutoLoad();
|
||||
return auto;
|
||||
}
|
||||
|
||||
private void ToggleAutoLoad()
|
||||
public void ToggleAutoLoad()
|
||||
{
|
||||
AutoLoad ^= true;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace BizHawk.MultiClient
|
|||
bool load_result = Global.CheatList.Load(path, append: false);
|
||||
if (!load_result)
|
||||
{
|
||||
Global.Config.RecentWatches.HandleLoadError(path);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentWatches, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -569,7 +569,9 @@ namespace BizHawk.MultiClient
|
|||
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(Global.Config.RecentCheats.GenerateRecentMenu(LoadFileFromRecent));
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentCheats, LoadFileFromRecent)
|
||||
);
|
||||
}
|
||||
|
||||
private void NewMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -533,7 +533,9 @@ namespace BizHawk.MultiClient
|
|||
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
recentToolStripMenuItem.DropDownItems.Clear();
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentLua.GenerateRecentMenu(LoadLuaFromRecent));
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentLua, LoadLuaFromRecent)
|
||||
);
|
||||
}
|
||||
|
||||
private void LoadLuaFromRecent(string path)
|
||||
|
@ -979,7 +981,9 @@ namespace BizHawk.MultiClient
|
|||
private void recentSessionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
recentSessionsToolStripMenuItem.DropDownItems.Clear();
|
||||
recentSessionsToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentLuaSession.GenerateRecentMenu(LoadSessionFromRecent));
|
||||
recentSessionsToolStripMenuItem.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentLuaSession, LoadSessionFromRecent)
|
||||
);
|
||||
}
|
||||
|
||||
public void LoadSessionFromRecent(string path)
|
||||
|
@ -991,7 +995,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
if (!LoadLuaSession(path))
|
||||
{
|
||||
Global.Config.RecentLuaSession.HandleLoadError(path);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentLuaSession, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -8,6 +8,54 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
class ToolHelpers
|
||||
{
|
||||
public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent)
|
||||
{
|
||||
var auto = new ToolStripMenuItem { Text = "&Auto-Load", Checked = recent.AutoLoad };
|
||||
auto.Click += (o, ev) => recent.ToggleAutoLoad();
|
||||
return auto;
|
||||
}
|
||||
|
||||
public static ToolStripItem[] GenerateRecentMenu(RecentFiles recent, Action<string> loadFileCallback)
|
||||
{
|
||||
var items = new List<ToolStripItem>();
|
||||
|
||||
if (recent.Empty)
|
||||
{
|
||||
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
||||
items.Add(none);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string filename in recent)
|
||||
{
|
||||
string temp = filename;
|
||||
var item = new ToolStripMenuItem { Text = temp };
|
||||
item.Click += (o, ev) => loadFileCallback(temp);
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
items.Add(new ToolStripSeparator());
|
||||
|
||||
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
||||
clearitem.Click += (o, ev) => recent.Clear();
|
||||
items.Add(clearitem);
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
public static void HandleLoadError(RecentFiles recent, string path)
|
||||
{
|
||||
Global.Sound.StopSound();
|
||||
DialogResult result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
recent.Remove(path);
|
||||
}
|
||||
|
||||
Global.Sound.StartSound();
|
||||
}
|
||||
|
||||
public static ToolStripMenuItem[] GenerateMemoryDomainMenuItems(Action<int> SetCallback, string SelectedDomain = "", int? maxSize = null)
|
||||
{
|
||||
var items = new List<ToolStripMenuItem>();
|
||||
|
|
|
@ -474,7 +474,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
if (!file.Exists)
|
||||
{
|
||||
Global.Config.RecentSearches.HandleLoadError(path);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentSearches, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -901,7 +901,9 @@ namespace BizHawk.MultiClient
|
|||
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(Global.Config.RecentSearches.GenerateRecentMenu(LoadFileFromRecent));
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentSearches, LoadFileFromRecent)
|
||||
);
|
||||
}
|
||||
|
||||
private void OpenMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -362,7 +362,7 @@ namespace BizHawk.MultiClient
|
|||
bool load_result = Watches.Load(path, append: false);
|
||||
if (!load_result)
|
||||
{
|
||||
Global.Config.RecentWatches.HandleLoadError(path);
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentWatches, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -813,8 +813,12 @@ namespace BizHawk.MultiClient
|
|||
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
recentToolStripMenuItem.DropDownItems.Clear();
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentWatches.GenerateRecentMenu(LoadFileFromRecent));
|
||||
recentToolStripMenuItem.DropDownItems.Add(Global.Config.RecentWatches.GenerateAutoLoadItem());
|
||||
recentToolStripMenuItem.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentWatches, LoadFileFromRecent)
|
||||
);
|
||||
recentToolStripMenuItem.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentWatches)
|
||||
);
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue