From 5c674e5f8fc1f07374e1492648c4d152ff8ee629 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 27 Oct 2019 18:02:06 -0500 Subject: [PATCH] Watch UI classes - some cleanups, mostly C#7isms --- .../tools/Watch/WatchList/WatchList.cs | 20 +--- .../Lua/Libraries/EmuLuaLibrary.Client.cs | 12 +- .../tools/Watch/RamSearch.cs | 14 +-- .../tools/Watch/RamWatch.cs | 33 +----- .../tools/Watch/WatchEditor.cs | 103 +++++++++--------- .../tools/Watch/WatchValueBox.cs | 12 +- BizHawk.sln.DotSettings | 1 + 7 files changed, 72 insertions(+), 123 deletions(-) diff --git a/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs b/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs index 833e3595e8..96999aa9b1 100644 --- a/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs +++ b/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs @@ -388,15 +388,8 @@ namespace BizHawk.Client.Common /// at the specified index public Watch this[int index] { - get - { - return _watchList[index]; - } - - set - { - _watchList[index] = value; - } + get => _watchList[index]; + set => _watchList[index] = value; } #endregion IList @@ -607,14 +600,7 @@ namespace BizHawk.Client.Common CurrentFileName = path; } - if (!append) - { - Changes = false; - } - else - { - Changes = true; - } + Changes = append; return true; } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs index 3ebe0aeccc..f8523ea8a4 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs @@ -404,12 +404,12 @@ namespace BizHawk.Client.EmuHawk return GlobalWin.MainForm.DesktopLocation.Y; } - [LuaMethodExample("local incbhver = client.getversion( );")] - [LuaMethod("getversion", "Returns the current stable BizHawk version")] - public static string GetVersion() - { - return VersionInfo.Mainversion; - } + [LuaMethodExample("local incbhver = client.getversion( );")] + [LuaMethod("getversion", "Returns the current stable BizHawk version")] + public static string GetVersion() + { + return VersionInfo.Mainversion; + } [LuaMethodExample("local nlcliget = client.getavailabletools( );")] [LuaMethod("getavailabletools", "Returns a list of the tools currently open")] diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index c398b89730..6d455a25a9 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -565,15 +565,9 @@ namespace BizHawk.Client.EmuHawk private IEnumerable SelectedIndices => WatchListView.SelectedRows; - private IEnumerable SelectedItems - { - get { return SelectedIndices.Select(index => _searches[index]); } - } + private IEnumerable SelectedItems => SelectedIndices.Select(index => _searches[index]); - private IEnumerable SelectedWatches - { - get { return SelectedItems.Where(x => !x.IsSeparator); } - } + private IEnumerable SelectedWatches => SelectedItems.Where(x => !x.IsSeparator); private void SetRemovedMessage(int val) { @@ -771,8 +765,8 @@ namespace BizHawk.Client.EmuHawk private void SetReboot(bool rebootNeeded) { RebootToolBarSeparator.Visible = - RebootToolbarButton.Visible = - rebootNeeded; + RebootToolbarButton.Visible = + rebootNeeded; } private void SetToDetailedMode() diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index b29c6137e2..71b1439ea7 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -96,32 +96,11 @@ namespace BizHawk.Client.EmuHawk } private IEnumerable SelectedIndices => WatchListView.SelectedRows; + private IEnumerable SelectedItems => SelectedIndices.Select(index => _watches[index]); + private IEnumerable SelectedWatches => SelectedItems.Where(x => !x.IsSeparator); + private IEnumerable SelectedSeparators => SelectedItems.Where(x => x.IsSeparator); - private IEnumerable SelectedItems - { - get { return SelectedIndices.Select(index => _watches[index]); } - } - - private IEnumerable SelectedWatches - { - get { return SelectedItems.Where(x => !x.IsSeparator); } - } - - private IEnumerable SelectedSeparators - { - get - { - return SelectedItems.Where(x => x.IsSeparator); - } - } - - public IEnumerable Watches - { - get - { - return _watches.Where(x => !x.IsSeparator); - } - } + public IEnumerable Watches => _watches.Where(x => !x.IsSeparator); public bool UpdateBefore => false; @@ -775,8 +754,8 @@ namespace BizHawk.Client.EmuHawk private MemoryDomain CurrentDomain { - get { return _currentDomain ?? MemoryDomains.MainMemory; } - set { _currentDomain = value; } + get => _currentDomain ?? MemoryDomains.MainMemory; + set => _currentDomain = value; } private void MemoryDomainsSubMenu_DropDownOpened(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs index 9e6a457be7..ef5484ea50 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchEditor.cs @@ -13,8 +13,6 @@ namespace BizHawk.Client.EmuHawk { public enum Mode { New, Duplicate, Edit } - private readonly List _watchList = new List(); - public Emu.IMemoryDomains MemoryDomains { get; set; } private Mode _mode = Mode.New; @@ -23,7 +21,7 @@ namespace BizHawk.Client.EmuHawk private bool _changedSize; private bool _changedDisplayType; - public List Watches => _watchList; + public List Watches { get; } = new List(); public Point InitialLocation { get; set; } = new Point(0, 0); @@ -63,7 +61,7 @@ namespace BizHawk.Client.EmuHawk break; case Mode.Duplicate: case Mode.Edit: - switch (_watchList[0].Size) + switch (Watches[0].Size) { case WatchSize.Byte: SizeDropDown.SelectedItem = SizeDropDown.Items[0]; @@ -76,28 +74,28 @@ namespace BizHawk.Client.EmuHawk break; } - var index = DisplayTypeDropDown.Items.IndexOf(Watch.DisplayTypeToString(_watchList[0].Type)); + var index = DisplayTypeDropDown.Items.IndexOf(Watch.DisplayTypeToString(Watches[0].Type)); DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[index]; - if (_watchList.Count > 1) + if (Watches.Count > 1) { NotesBox.Enabled = false; NotesBox.Text = ""; AddressBox.Enabled = false; - AddressBox.Text = _watchList.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => $"{addrStr},{nextStr}"); + AddressBox.Text = Watches.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => $"{addrStr},{nextStr}"); BigEndianCheckBox.ThreeState = true; - if (_watchList.Select(s => s.Size).Distinct().Count() > 1) + if (Watches.Select(s => s.Size).Distinct().Count() > 1) { DisplayTypeDropDown.Enabled = false; } } else { - NotesBox.Text = _watchList[0].Notes; - AddressBox.SetFromLong(_watchList[0].Address); + NotesBox.Text = Watches[0].Notes; + AddressBox.SetFromLong(Watches[0].Address); } SetBigEndianCheckBox(); @@ -110,7 +108,7 @@ namespace BizHawk.Client.EmuHawk { if (watches != null) { - _watchList.AddRange(watches); + Watches.AddRange(watches); } _mode = mode; @@ -134,7 +132,7 @@ namespace BizHawk.Client.EmuHawk Text = "New Watch"; break; case Mode.Edit: - Text = $"Edit {(_watchList.Count == 1 ? "Watch" : "Watches")}"; + Text = $"Edit {(Watches.Count == 1 ? "Watch" : "Watches")}"; break; case Mode.Duplicate: Text = "Duplicate Watch"; @@ -188,37 +186,34 @@ namespace BizHawk.Client.EmuHawk private void SetBigEndianCheckBox() { - if (_watchList != null) + if (Watches.Count > 1) { - if (_watchList.Count > 1) - { - // Aggregate state - var hasBig = _watchList.Any(x => x.BigEndian); - var hasLittle = _watchList.Any(x => x.BigEndian == false); + // Aggregate state + var hasBig = Watches.Any(x => x.BigEndian); + var hasLittle = Watches.Any(x => x.BigEndian == false); - if (hasBig && hasLittle) - { - BigEndianCheckBox.Checked = true; - BigEndianCheckBox.CheckState = CheckState.Indeterminate; - } - else if (hasBig) - { - BigEndianCheckBox.Checked = true; - } - else - { - BigEndianCheckBox.Checked = false; - } - } - else if (_watchList.Count == 1) + if (hasBig && hasLittle) { - BigEndianCheckBox.Checked = _watchList[0].BigEndian; - return; + BigEndianCheckBox.Checked = true; + BigEndianCheckBox.CheckState = CheckState.Indeterminate; + } + else if (hasBig) + { + BigEndianCheckBox.Checked = true; + } + else + { + BigEndianCheckBox.Checked = false; } } + else if (Watches.Count == 1) + { + BigEndianCheckBox.Checked = Watches[0].BigEndian; + return; + } - var domain = MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString()) ?? - MemoryDomains.MainMemory; + var domain = MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString()) + ?? MemoryDomains.MainMemory; BigEndianCheckBox.Checked = domain.EndianType == Emu.MemoryDomain.Endian.Big; } @@ -246,13 +241,13 @@ namespace BizHawk.Client.EmuHawk switch (SizeDropDown.SelectedIndex) { case 0: - _watchList.Add(Watch.GenerateWatch(domain, address, WatchSize.Byte, type, bigEndian, notes)); + Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.Byte, type, bigEndian, notes)); break; case 1: - _watchList.Add(Watch.GenerateWatch(domain, address, WatchSize.Word, type, bigEndian, notes)); + Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.Word, type, bigEndian, notes)); break; case 2: - _watchList.Add(Watch.GenerateWatch(domain, address, WatchSize.DWord, type, bigEndian, notes)); + Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.DWord, type, bigEndian, notes)); break; } @@ -262,11 +257,11 @@ namespace BizHawk.Client.EmuHawk break; case Mode.Duplicate: var tempWatchList = new List(); - tempWatchList.AddRange(_watchList); - _watchList.Clear(); + tempWatchList.AddRange(Watches); + Watches.Clear(); foreach (var watch in tempWatchList) { - _watchList.Add(Watch.GenerateWatch( + Watches.Add(Watch.GenerateWatch( watch.Domain, watch.Address, watch.Size, @@ -284,14 +279,14 @@ namespace BizHawk.Client.EmuHawk private void DoEdit() { - if (_watchList.Count == 1) + if (Watches.Count == 1) { - _watchList[0].Notes = NotesBox.Text; + Watches[0].Notes = NotesBox.Text; } if (_changedSize) { - for (var i = 0; i < _watchList.Count; i++) + for (var i = 0; i < Watches.Count; i++) { var size = WatchSize.Byte; switch (SizeDropDown.SelectedIndex) @@ -307,24 +302,24 @@ namespace BizHawk.Client.EmuHawk break; } - _watchList[i] = Watch.GenerateWatch( - _watchList[i].Domain, - _watchList.Count == 1 ? AddressBox.ToRawInt() ?? 0 : _watchList[i].Address, + Watches[i] = Watch.GenerateWatch( + Watches[i].Domain, + Watches.Count == 1 ? AddressBox.ToRawInt() ?? 0 : Watches[i].Address, size, - _watchList[i].Type, - _watchList[i].BigEndian, - _watchList[i].Notes); + Watches[i].Type, + Watches[i].BigEndian, + Watches[i].Notes); } } if (_changedDisplayType) { - _watchList.ForEach(x => x.Type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString())); + Watches.ForEach(x => x.Type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString())); } if (BigEndianCheckBox.CheckState != CheckState.Indeterminate) { - _watchList.ForEach(x => x.BigEndian = BigEndianCheckBox.Checked); + Watches.ForEach(x => x.BigEndian = BigEndianCheckBox.Checked); } } diff --git a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs index 9ff28c358a..61a31de47c 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/WatchValueBox.cs @@ -23,10 +23,7 @@ namespace BizHawk.Client.EmuHawk public WatchSize ByteSize { - get - { - return _size; - } + get => _size; set { @@ -65,15 +62,12 @@ namespace BizHawk.Client.EmuHawk public DisplayType Type { - get - { - return _type; - } + get => _type; set { var val = ToRawInt(); - _type = value; + _type = value; SetMaxLength(); SetFromRawInt(val); } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index a23de6417a..d27343588e 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -241,6 +241,7 @@ True True True + True True True True