Make an extension method ShowHawkDialog() to use for modal dialog calls that does the Sound Stop/Start methods (and potentially any other EmuHawk specific logic that needs to be done). Use this in the bazillion places we were calling StopSound and StartSound.

This commit is contained in:
adelikat 2013-11-28 22:39:00 +00:00
parent d6954e4209
commit 9ccc214667
18 changed files with 91 additions and 126 deletions

View File

@ -1,20 +1,44 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk
{
public static class Extensions
{
//extension method to make Control.Invoke easier to use
// extension method to make Control.Invoke easier to use
public static void Invoke(this Control control, Action action)
{
control.Invoke((Delegate)action);
control.Invoke(action);
}
}
public static class WinFormExtensions
{
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this Form form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
/// <summary>
/// Handles EmuHawk specific issues before showing a modal dialog
/// </summary>
public static DialogResult ShowHawkDialog(this CommonDialog form)
{
GlobalWin.Sound.StopSound();
var result = form.ShowDialog();
GlobalWin.Sound.StartSound();
return result;
}
}
public static class ListViewExtensions
{
@ -70,27 +94,32 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
public static string CopyItemsAsText(this ListView listViewControl)
{
ListView.SelectedIndexCollection indexes = listViewControl.SelectedIndices;
var indexes = listViewControl.SelectedIndices;
if (indexes.Count <= 0)
return "";
{
return String.Empty;
}
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
//walk over each selected item and subitem within it to generate a string from it
// walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
{
sb.Append(item.Text).Append('\t');
}
}
//remove the last tab
// remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
//remove last newline
// remove last newline
sb.Length -= 2;

View File

@ -413,9 +413,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = false
};
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result == DialogResult.OK)
{
foreach (var fn in ofd.FileNames)
@ -481,9 +479,7 @@ namespace BizHawk.Client.EmuHawk
Filter = "PNG File (*.png)|*.png"
};
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result == DialogResult.OK)
{
TakeScreenshot(sfd.FileName);

View File

@ -1787,10 +1787,7 @@ namespace BizHawk.Client.EmuHawk
file.Directory.Create();
}
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result == DialogResult.OK)
{
SaveStateFile(sfd.FileName, sfd.FileName, false);
@ -1811,10 +1808,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result != DialogResult.OK)
return;
@ -1991,11 +1985,12 @@ namespace BizHawk.Client.EmuHawk
ofd.RestoreDirectory = false;
ofd.FilterIndex = _lastOpenRomFilter;
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return;
}
var file = new FileInfo(ofd.FileName);
Global.Config.LastRomPath = file.DirectoryName;
_lastOpenRomFilter = ofd.FilterIndex;
@ -2725,10 +2720,7 @@ namespace BizHawk.Client.EmuHawk
}
sfd.Filter = String.Format("{0} (*.{0})|*.{0}|All Files|*.*", aw.DesiredExtension());
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result == DialogResult.Cancel)
{
aw.Dispose();

View File

@ -74,9 +74,7 @@ namespace BizHawk.Client.EmuHawk
var filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
ofd.Filter = filter;
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result == DialogResult.OK)
{
var file = new FileInfo(ofd.FileName);

View File

@ -210,10 +210,7 @@ namespace BizHawk.Client.EmuHawk
var filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
sfd.Filter = filter;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result == DialogResult.OK
&& !String.IsNullOrWhiteSpace(sfd.FileName))
{

View File

@ -963,9 +963,7 @@ namespace BizHawk.Client.EmuHawk
dlg.FullOpen = true;
dlg.Color = spriteback;
GlobalWin.Sound.StopSound();
var result = dlg.ShowDialog();
GlobalWin.Sound.StartSound();
var result = dlg.ShowHawkDialog();
if (result == DialogResult.OK)
{
// force full opaque

View File

@ -383,9 +383,7 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = "Text (*.txt)|*.txt|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
return result == DialogResult.OK ? sfd.FileName : String.Empty;
}
@ -862,9 +860,7 @@ namespace BizHawk.Client.EmuHawk
sfd.InitialDirectory = PathManager.GetPlatformBase(Global.Emulator.SystemId);
sfd.Filter = GetSaveFileFilter();
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
return result == DialogResult.OK ? sfd.FileName : String.Empty;
}
@ -1397,9 +1393,7 @@ namespace BizHawk.Client.EmuHawk
{
var inputPrompt = new InputPrompt { Text = "Go to Address", _Location = GetPromptPoint() };
inputPrompt.SetMessage("Enter a hexadecimal value");
GlobalWin.Sound.StopSound();
inputPrompt.ShowDialog();
GlobalWin.Sound.StartSound();
inputPrompt.ShowHawkDialog();
if (inputPrompt.UserOK && InputValidate.IsValidHexNumber(inputPrompt.UserText))
{
@ -1491,11 +1485,9 @@ namespace BizHawk.Client.EmuHawk
));
poke.SetWatch(watches);
GlobalWin.Sound.StopSound();
poke.ShowDialog();
poke.ShowHawkDialog();
UpdateValues();
GlobalWin.Sound.StartSound();
}
}
@ -1512,9 +1504,7 @@ namespace BizHawk.Client.EmuHawk
private void SetColorsMenuItem_Click(object sender, EventArgs e)
{
GlobalWin.Sound.StopSound();
new HexColorsForm().ShowDialog();
GlobalWin.Sound.StartSound();
new HexColorsForm().ShowHawkDialog();
}
private void ResetColorsToDefaultMenuItem_Click(object sender, EventArgs e)

View File

@ -240,10 +240,7 @@ namespace BizHawk.Client.EmuHawk
Directory.CreateDirectory(ofd.InitialDirectory);
}
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
return result == DialogResult.OK ? new FileInfo(ofd.FileName) : null;
}
@ -435,13 +432,13 @@ namespace BizHawk.Client.EmuHawk
}
sfd.Filter = "Lua Session Files (*.luases)|*.luases|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
var file = new FileInfo(sfd.FileName);
return file;
}
return new FileInfo(sfd.FileName);
}
private void SaveSessionAs()
@ -875,9 +872,7 @@ namespace BizHawk.Client.EmuHawk
private void FunctionsListMenuItem_Click(object sender, EventArgs e)
{
GlobalWin.Sound.StopSound();
new LuaFunctionsForm().Show();
GlobalWin.Sound.StartSound();
}
private void OnlineDocsMenuItem_Click(object sender, EventArgs e)

View File

@ -578,13 +578,13 @@ namespace BizHawk.Client.EmuHawk
}
sfd.Filter = "Watch Files (*.lua)|*.lua|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
var file = new FileInfo(sfd.FileName);
return file;
}
return new FileInfo(sfd.FileName);
}
private void LuaText_KeyUp(object sender, KeyEventArgs e)

View File

@ -76,9 +76,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return;

View File

@ -83,11 +83,11 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return;
}
var file = new FileInfo(sfd.FileName);
Bitmap b = new Bitmap(Width, Height);

View File

@ -44,11 +44,11 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return;
}
var file = new FileInfo(sfd.FileName);
Bitmap b = new Bitmap(Width, Height);

View File

@ -49,11 +49,11 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return;
}
var file = new FileInfo(sfd.FileName);
Bitmap b = new Bitmap(Width, Height);

View File

@ -451,14 +451,12 @@ namespace BizHawk.Client.EmuHawk
string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
sfd.Filter = filter;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result == DialogResult.OK)
{
return sfd.FileName;
}
return "";
return String.Empty;
}
private void TASView_MouseWheel(object sender, MouseEventArgs e)

View File

@ -23,9 +23,7 @@ namespace BizHawk.Client.EmuHawk
ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
ofd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
@ -55,9 +53,7 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
@ -78,9 +74,7 @@ namespace BizHawk.Client.EmuHawk
ofd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
ofd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = ofd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
@ -104,9 +98,7 @@ namespace BizHawk.Client.EmuHawk
sfd.InitialDirectory = PathManager.GetCheatsPath(Global.Game);
sfd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;

View File

@ -323,19 +323,13 @@ namespace BizHawk.Client.EmuHawk
sfd.Filter = "Text Files (*.txt)|*.txt|Log Files (*.log)|*.log|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWin.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWin.Sound.StartSound();
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
}
else
{
return new FileInfo(sfd.FileName);
}
return new FileInfo(sfd.FileName);
}
private void saveLogToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -794,14 +794,12 @@ namespace BizHawk.Client.EmuHawk
{
if (SelectedIndices.Count > 0)
{
GlobalWin.Sound.StopSound();
var poke = new RamPoke();
var watches = SelectedIndices.Select(t => _searches[t]).ToList();
poke.SetWatch(watches);
poke.InitialLocation = GetPromptPoint();
poke.ShowDialog();
poke.ShowHawkDialog();
UpdateValues();
GlobalWin.Sound.StartSound();
}
}
@ -854,9 +852,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.SelectedIndices.Clear();
var prompt = new InputPrompt {Text = "Go to Address", _Location = GetPromptPoint()};
prompt.SetMessage("Enter a hexadecimal value");
GlobalWin.Sound.StopSound();
prompt.ShowDialog();
GlobalWin.Sound.StartSound();
prompt.ShowHawkDialog();
if (prompt.UserOK)
{

View File

@ -295,8 +295,7 @@ namespace BizHawk.Client.EmuHawk
we.SetWatch(_watches.Domain, SelectedWatches, duplicate ? WatchEditor.Mode.Duplicate : WatchEditor.Mode.Edit);
GlobalWin.Sound.StopSound();
var result = we.ShowDialog();
var result = we.ShowHawkDialog();
if (result == DialogResult.OK)
{
Changes();
@ -314,7 +313,6 @@ namespace BizHawk.Client.EmuHawk
}
}
GlobalWin.Sound.StartSound();
UpdateValues();
}
}
@ -672,10 +670,7 @@ namespace BizHawk.Client.EmuHawk
InitialLocation = GetPromptPoint()
};
we.SetWatch(_watches.Domain);
GlobalWin.Sound.StopSound();
we.ShowDialog();
GlobalWin.Sound.StartSound();
we.ShowHawkDialog();
if (we.DialogResult == DialogResult.OK)
{
_watches.Add(we.Watches[0]);
@ -726,13 +721,10 @@ namespace BizHawk.Client.EmuHawk
poke.SetWatch(SelectedWatches);
}
GlobalWin.Sound.StopSound();
if (poke.ShowDialog() == DialogResult.OK)
if (poke.ShowHawkDialog() == DialogResult.OK)
{
UpdateValues();
}
GlobalWin.Sound.StartSound();
}
}