Refactor Recent Files to handle a load error message and logic to remove from list, refactored all the places that do this to use this single unified function

This commit is contained in:
adelikat 2013-09-09 21:36:26 +00:00
parent 4682c326e4
commit fad71b1d98
7 changed files with 77 additions and 88 deletions

View File

@ -723,32 +723,19 @@ namespace BizHawk.MultiClient
private void LoadRomFromRecent(string rom)
{
bool r = LoadRom(rom);
if (!r)
if (!LoadRom(rom))
{
Global.Sound.StopSound();
DialogResult result = MessageBox.Show("Could not open " + rom + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
Global.Config.RecentRoms.Remove(rom);
}
Global.Sound.StartSound();
Global.Config.RecentRoms.HandleLoadError(rom);
}
}
private void LoadMoviesFromRecent(string movie)
private void LoadMoviesFromRecent(string path)
{
Movie m = new Movie(movie);
Movie m = new Movie(path);
if (!m.Loaded)
{
Global.Sound.StopSound();
DialogResult result = MessageBox.Show("Could not open " + movie + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
Global.Config.RecentMovies.Remove(movie);
}
Global.Sound.StartSound();
Global.Config.RecentMovies.HandleLoadError(path);
}
else
{

View File

@ -96,6 +96,18 @@ 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>();

View File

@ -236,23 +236,27 @@ namespace BizHawk.MultiClient
Global.MainForm.HexEditor1.UpdateValues();
}
public void LoadCheatFromRecent(string file)
public void LoadCheatFromRecent(string path)
{
bool z = true;
bool doload = true;
if (Global.CheatList.Changes) z = AskSave();
if (z)
if (Global.CheatList.Changes)
{
bool r = LoadCheatFile(file, false);
if (!r)
doload = AskSave();
}
if (doload)
{
bool result = LoadCheatFile(path, false);
if (!result)
{
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
Global.Config.RecentCheats.Remove(file);
Global.Config.RecentCheats.HandleLoadError(path);
}
else
{
DisplayCheatsList();
Global.CheatList.Changes = false;
}
DisplayCheatsList();
Global.CheatList.Changes = false;
}
}

View File

@ -973,14 +973,7 @@ namespace BizHawk.MultiClient
private void fileToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (!changes)
{
saveToolStripMenuItem.Enabled = false;
}
else
{
saveToolStripMenuItem.Enabled = true;
}
saveToolStripMenuItem.Enabled = changes;
}
private void recentSessionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
@ -989,26 +982,25 @@ namespace BizHawk.MultiClient
recentSessionsToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentLuaSession.GenerateRecentMenu(LoadSessionFromRecent));
}
public void LoadSessionFromRecent(string file)
public void LoadSessionFromRecent(string path)
{
bool z = true;
if (changes) z = AskSave();
bool doload = true;
if (changes) doload = AskSave();
if (z)
if (doload)
{
bool r = LoadLuaSession(file);
if (!r)
if (!LoadLuaSession(path))
{
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
Global.Config.RecentLuaSession.Remove(file);
Global.Config.RecentLuaSession.HandleLoadError(path);
}
else
{
RunLuaScripts();
DisplayLuaList();
LuaListView.Refresh();
currentSessionFile = path;
Changes(false);
}
RunLuaScripts();
DisplayLuaList();
//ClearOutput();
LuaListView.Refresh();
currentSessionFile = file;
Changes(false);
}
}

View File

@ -298,7 +298,7 @@ namespace BizHawk.MultiClient
}
}
public void LoadWatchFromRecent(string file)
public void LoadWatchFromRecent(string path)
{
bool ask_result = true;
if (Watches.Changes)
@ -308,26 +308,19 @@ namespace BizHawk.MultiClient
if (ask_result)
{
bool load_result = Watches.Load(file, details: true, append: false);
if (load_result)
bool load_result = Watches.Load(path, details: true, append: false);
if (!load_result)
{
Global.Config.RecentWatches.Add(file);
Global.Config.RecentWatches.HandleLoadError(path);
}
else
{
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
Global.Config.RecentWatches.Remove(file);
}
Global.Config.RecentWatches.Add(path);
DisplayWatches();
UpdateWatchCount();
MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " *";
Watches.Changes = false;
}
DisplayWatches();
UpdateWatchCount();
MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " *";
Watches.Changes = false;
}
}

View File

@ -1819,16 +1819,16 @@ namespace BizHawk.MultiClient
}
}
private void LoadSearchFromRecent(string file)
private void LoadSearchFromRecent(string path)
{
bool r = LoadSearchFile(file, false, Searches);
if (!r)
if (!LoadSearchFile(path, false, Searches))
{
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
Global.Config.RecentSearches.Remove(file);
Global.Config.RecentSearches.HandleLoadError(path);
}
else
{
DisplaySearchList();
}
DisplaySearchList();
}
bool LoadSearchFile(string path, bool append, List<Watch_Legacy> list)
@ -1848,10 +1848,11 @@ namespace BizHawk.MultiClient
Global.Config.RecentSearches.Add(path);
SetMemoryDomain(WatchCommon.GetDomainPos(domain));
return true;
}
else
{
return false;
}
}
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)

View File

@ -290,22 +290,22 @@ namespace BizHawk.MultiClient
return true;
}
public void LoadWatchFromRecent(string file)
public void LoadWatchFromRecent(string path)
{
bool z = true;
if (changes) z = AskSave();
bool ask_result = true;
if (changes) ask_result = AskSave();
if (z)
if (ask_result)
{
bool r = LoadWatchFile(file, false);
if (!r)
if (!LoadWatchFile(path, false))
{
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
Global.Config.RecentWatches.Remove(file);
Global.Config.RecentWatches.HandleLoadError(path);
}
else
{
DisplayWatchList();
changes = false;
}
DisplayWatchList();
changes = false;
}
}