private void MoveUp(bool fromUpDownArrow) { if (lstWatch.SelectedIndices.Count == 0) { return; } int index = lstWatch.SelectedIndices[0]; if (Program.IsMono && fromUpDownArrow) { //Mono appears to move the selection up before processing this index++; } if (index > 0 && index < lstWatch.Items.Count - 1) { string currentEntry = lstWatch.Items[index].SubItems[0].Text; string entryAbove = lstWatch.Items[index - 1].SubItems[0].Text; SetSelectedItem(index - 1); WatchManager.UpdateWatch(index - 1, currentEntry); WatchManager.UpdateWatch(index, entryAbove); } else { SetSelectedItem(index); } }
public static WatchManager GetWatchManager(CpuType cpuType) { WatchManager manager; if(!_watchManagers.TryGetValue(cpuType, out manager)) { manager = new WatchManager(); _watchManagers[cpuType] = manager; } return manager; }
private void ApplyEdit() { if (lstWatch.SelectedItems.Count > 0) { lstWatch.SelectedItems[0].Text = txtEdit.Text; WatchManager.UpdateWatch(lstWatch.SelectedIndices[0], txtEdit.Text); } lstWatch.Focus(); }
private void mnuExport_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.SetFilter("Watch files (*.mwf)|*.mwf"); if (sfd.ShowDialog() == DialogResult.OK) { WatchManager.Export(sfd.FileName); } } }
private void mnuImport_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter("Watch files (*.mwf)|*.mwf"); if (ofd.ShowDialog() == DialogResult.OK) { WatchManager.Import(ofd.FileName); } } }
private void mnuRemoveWatch_Click(object sender, EventArgs e) { if (lstWatch.SelectedItems.Count >= 1) { var itemsToRemove = new List <int>(); foreach (ListViewItem item in lstWatch.SelectedItems) { itemsToRemove.Add(item.Index); } WatchManager.RemoveWatch(itemsToRemove.ToArray()); } }
public void UpdateWatch() { List <WatchValueInfo> watchContent = WatchManager.GetWatchContent(mnuHexDisplay.Checked); lstWatch.BeginUpdate(); if (watchContent.Count != lstWatch.Items.Count - 1) { lstWatch.Items.Clear(); List <ListViewItem> itemsToAdd = new List <ListViewItem>(); foreach (WatchValueInfo watch in watchContent) { ListViewItem item = new ListViewItem(watch.Expression); item.UseItemStyleForSubItems = false; item.SubItems.Add(watch.Value).ForeColor = watch.HasChanged ? Color.Red : Color.Black; itemsToAdd.Add(item); } var lastItem = new ListViewItem(""); lastItem.SubItems.Add(""); itemsToAdd.Add(lastItem); lstWatch.Items.AddRange(itemsToAdd.ToArray()); } else { for (int i = 0; i < watchContent.Count; i++) { ListViewItem item = lstWatch.Items[i]; item.SubItems[0].Text = watchContent[i].Expression; item.SubItems[1].Text = watchContent[i].Value.ToString(); item.SubItems[1].ForeColor = watchContent[i].HasChanged ? Color.Red : Color.Black; } } lstWatch.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent); if (colValue.Width < 100) { colValue.Width = 100; } lstWatch.EndUpdate(); if (_currentSelection >= 0 && lstWatch.Items.Count > _currentSelection) { lstWatch.FocusedItem = lstWatch.Items[_currentSelection]; lstWatch.Items[_currentSelection].Selected = true; _currentSelection = -1; } }
private void SetSelectionFormat(string formatString) { List <string> entries = WatchManager.WatchEntries; foreach (int i in lstWatch.SelectedIndices) { if (i < entries.Count) { Match match = WatchManager.FormatSuffixRegex.Match(entries[i]); if (match.Success) { WatchManager.UpdateWatch(i, match.Groups[1].Value + formatString); } else { WatchManager.UpdateWatch(i, entries[i] + formatString); } } } }
private void MoveDown() { if (lstWatch.SelectedIndices.Count == 0) { return; } int index = lstWatch.SelectedIndices[0]; if (index < lstWatch.Items.Count - 2) { string currentEntry = lstWatch.Items[index].SubItems[0].Text; string entryBelow = lstWatch.Items[index + 1].SubItems[0].Text; SetSelectedItem(index + 1); WatchManager.UpdateWatch(index + 1, currentEntry); WatchManager.UpdateWatch(index, entryBelow); } else { SetSelectedItem(index); } }
public void UpdateWatch(bool autoResizeColumns = true) { List <WatchValueInfo> watchContent = WatchManager.GetWatchContent(mnuHexDisplay.Checked); bool updating = false; if (watchContent.Count != lstWatch.Items.Count - 1) { lstWatch.BeginUpdate(); lstWatch.Items.Clear(); List <ListViewItem> itemsToAdd = new List <ListViewItem>(); foreach (WatchValueInfo watch in watchContent) { ListViewItem item = new ListViewItem(watch.Expression); item.UseItemStyleForSubItems = false; item.SubItems.Add(watch.Value).ForeColor = watch.HasChanged ? Color.Red : Color.Black; itemsToAdd.Add(item); } var lastItem = new ListViewItem(""); lastItem.SubItems.Add(""); itemsToAdd.Add(lastItem); lstWatch.Items.AddRange(itemsToAdd.ToArray()); updating = true; } else { for (int i = 0; i < watchContent.Count; i++) { ListViewItem item = lstWatch.Items[i]; bool needUpdate = ( item.SubItems[0].Text != watchContent[i].Expression || item.SubItems[1].Text != watchContent[i].Value || item.SubItems[1].ForeColor != (watchContent[i].HasChanged ? Color.Red : Color.Black) ); if (needUpdate) { updating = true; item.SubItems[0].Text = watchContent[i].Expression; item.SubItems[1].Text = watchContent[i].Value; item.SubItems[1].ForeColor = watchContent[i].HasChanged ? Color.Red : Color.Black; } } } if (updating) { if (watchContent.Count > 0) { int maxLength = watchContent.Select(info => info.Value.Length).Max(); if (_previousMaxLength != maxLength) { if (autoResizeColumns) { lstWatch.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent); } if (colValue.Width < 100) { colValue.Width = 100; } _previousMaxLength = maxLength; } } lstWatch.EndUpdate(); } if (_currentSelection >= 0 && lstWatch.Items.Count > _currentSelection) { lstWatch.FocusedItem = lstWatch.Items[_currentSelection]; lstWatch.Items[_currentSelection].Selected = true; _currentSelection = -1; } }
private void lstWatch_AfterEdit(object sender, LabelEditEventArgs e) { _currentSelection = e.Item; WatchManager.UpdateWatch(e.Item, e.Label); }
public void UpdateWatch(bool autoResizeColumns = true) { List <WatchValueInfo> watchContent = WatchManager.GetWatchContent(_previousValues); _previousValues = watchContent; bool updating = false; if (watchContent.Count != lstWatch.Items.Count - 1) { int currentFocus = lstWatch.FocusedItem?.Selected == true ? (lstWatch.FocusedItem?.Index ?? -1) : -1; lstWatch.BeginUpdate(); lstWatch.Items.Clear(); List <ListViewItem> itemsToAdd = new List <ListViewItem>(); foreach (WatchValueInfo watch in watchContent) { ListViewItem item = new ListViewItem(watch.Expression); item.UseItemStyleForSubItems = false; item.SubItems.Add(watch.Value).ForeColor = watch.HasChanged ? ThemeHelper.Theme.ErrorTextColor : ThemeHelper.Theme.LabelForeColor; itemsToAdd.Add(item); } var lastItem = new ListViewItem(""); lastItem.SubItems.Add(""); itemsToAdd.Add(lastItem); lstWatch.Items.AddRange(itemsToAdd.ToArray()); if (currentFocus >= 0 && currentFocus < lstWatch.Items.Count) { SetSelectedItem(currentFocus); } updating = true; } else { for (int i = 0; i < watchContent.Count; i++) { ListViewItem item = lstWatch.Items[i]; bool needUpdate = ( item.SubItems[0].Text != watchContent[i].Expression || item.SubItems[1].Text != watchContent[i].Value || item.SubItems[1].ForeColor != (watchContent[i].HasChanged ? ThemeHelper.Theme.ErrorTextColor : ThemeHelper.Theme.LabelForeColor) ); if (needUpdate) { updating = true; item.SubItems[0].Text = watchContent[i].Expression; item.SubItems[1].Text = watchContent[i].Value; item.SubItems[1].ForeColor = watchContent[i].HasChanged ? ThemeHelper.Theme.ErrorTextColor : ThemeHelper.Theme.LabelForeColor; } } } if (updating) { if (watchContent.Count > 0) { int maxLength = watchContent.Select(info => info.Value.Length).Max(); if (_previousMaxLength != maxLength) { if (autoResizeColumns) { lstWatch.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent); } if (colValue.Width < 100) { colValue.Width = 100; } _previousMaxLength = maxLength; } } lstWatch.EndUpdate(); } }
private void ctrlHexViewer_InitializeContextMenu(object sender, EventArgs evt) { HexBox hexBox = (HexBox)sender; var mnuEditLabel = new ToolStripMenuItem(); mnuEditLabel.Click += (s, e) => { UInt32 address = (UInt32)hexBox.SelectionStart; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(address, ref info); ctrlLabelList.EditLabel((UInt32)info.Address, info.Type); } else { ctrlLabelList.EditLabel(address, GetAddressType().Value); } }; var mnuEditBreakpoint = new ToolStripMenuItem(); mnuEditBreakpoint.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); BreakpointAddressType addressType = startAddress == endAddress ? BreakpointAddressType.SingleAddress : BreakpointAddressType.AddressRange; Breakpoint bp = BreakpointManager.GetMatchingBreakpoint(startAddress, endAddress, this._memoryType == DebugMemoryType.PpuMemory); if (bp == null) { bp = new Breakpoint() { Address = startAddress, StartAddress = startAddress, EndAddress = endAddress, AddressType = addressType, IsAbsoluteAddress = false }; if (this._memoryType == DebugMemoryType.CpuMemory) { bp.BreakOnWrite = bp.BreakOnRead = true; } else { bp.BreakOnWriteVram = bp.BreakOnReadVram = true; } } BreakpointManager.EditBreakpoint(bp); }; var mnuAddWatch = new ToolStripMenuItem(); mnuAddWatch.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); string[] toAdd = Enumerable.Range((int)startAddress, (int)(endAddress - startAddress + 1)).Select((num) => $"[${num.ToString("X4")}]").ToArray(); WatchManager.AddWatch(toAdd); }; var mnuMarkSelectionAs = new ToolStripMenuItem(); var mnuMarkAsCode = new ToolStripMenuItem(); mnuMarkAsCode.Text = "Verified Code"; mnuMarkAsCode.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Code); }; var mnuMarkAsData = new ToolStripMenuItem(); mnuMarkAsData.Text = "Verified Data"; mnuMarkAsData.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.Data); }; var mnuMarkAsUnidentifiedData = new ToolStripMenuItem(); mnuMarkAsUnidentifiedData.Text = "Unidentified Code/Data"; mnuMarkAsUnidentifiedData.Click += (s, e) => { int startAddress = (int)hexBox.SelectionStart; int endAddress = (int)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); this.MarkSelectionAs(startAddress, endAddress, CdlPrgFlags.None); }; mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsCode); mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsData); mnuMarkSelectionAs.DropDownItems.Add(mnuMarkAsUnidentifiedData); var mnuFreeze = new ToolStripMenuItem(); mnuFreeze.Click += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); for (UInt32 i = startAddress; i <= endAddress; i++) { InteropEmu.DebugSetFreezeState((UInt16)i, (bool)mnuFreeze.Tag); } }; hexBox.ContextMenuStrip.Opening += (s, e) => { UInt32 startAddress = (UInt32)hexBox.SelectionStart; UInt32 endAddress = (UInt32)(hexBox.SelectionStart + (hexBox.SelectionLength == 0 ? 0 : (hexBox.SelectionLength - 1))); string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddWatch.Text = $"Add to Watch ({addressRange})"; if (this._memoryType == DebugMemoryType.CpuMemory) { bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1)); if (freezeState.All((frozen) => frozen)) { mnuFreeze.Text = $"Unfreeze ({addressRange})"; mnuFreeze.Tag = false; } else { mnuFreeze.Text = $"Freeze ({addressRange})"; mnuFreeze.Tag = true; } } else { mnuFreeze.Text = $"Freeze"; mnuFreeze.Tag = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { int absStart = InteropEmu.DebugGetAbsoluteAddress(startAddress); int absEnd = InteropEmu.DebugGetAbsoluteAddress(endAddress); if (absStart >= 0 && absEnd >= 0 && absStart <= absEnd) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } } else if (this._memoryType == DebugMemoryType.PrgRom) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } bool disableEditLabel = false; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, ref info); disableEditLabel = info.Address == -1; } mnuEditLabel.Enabled = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue); mnuEditBreakpoint.Enabled = (this._memoryType == DebugMemoryType.CpuMemory || this._memoryType == DebugMemoryType.PpuMemory) && DebugWindowManager.GetDebugger() != null; mnuAddWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory; mnuFreeze.Enabled = this._memoryType == DebugMemoryType.CpuMemory; }; hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator()); hexBox.ContextMenuStrip.Items.Insert(0, mnuFreeze); hexBox.ContextMenuStrip.Items.Insert(0, mnuEditLabel); hexBox.ContextMenuStrip.Items.Insert(0, mnuEditBreakpoint); hexBox.ContextMenuStrip.Items.Insert(0, mnuAddWatch); hexBox.ContextMenuStrip.Items.Insert(0, new ToolStripSeparator()); hexBox.ContextMenuStrip.Items.Insert(0, mnuMarkSelectionAs); }
private void AddWatch() { WatchManager.AddWatch(_newWatchValue); }