mirror of
https://github.com/fadden/6502bench.git
synced 2025-01-22 12:33:56 +00:00
Fix crashing bug in selection management
The fix for Shift+F3 required briefly switching the code list view to single-select mode. Unfortunately, while in that mode the control throws an exception if you touch SelectedItems (plural) rather than SelectedItem (singular), and in an unusual case the selection-changed event handler was doing just that.
This commit is contained in:
parent
e79064709c
commit
7000a5094e
@ -715,6 +715,16 @@ namespace SourceGen.WpfGui {
|
|||||||
// We work around this by temporarily switching to single-select mode.
|
// We work around this by temporarily switching to single-select mode.
|
||||||
//
|
//
|
||||||
// This could cause problems if we wanted to select multiple single lines.
|
// This could cause problems if we wanted to select multiple single lines.
|
||||||
|
//
|
||||||
|
// NOTE: this causes a selection-changed event, which can cause problems
|
||||||
|
// if something tries to fiddle with SelectedItems (you can only do that
|
||||||
|
// when in multi-select mode) instead of SelectedItem. I tried to mitigate this
|
||||||
|
// by setting the selection twice, once in multi-select mode, so that the
|
||||||
|
// selection is unlikely to change, but that restored the Shift+F3 problem.
|
||||||
|
//
|
||||||
|
// (To repro problem: double-clicking a line in the message log about
|
||||||
|
// a reference to a non-existent symbol associated with a self-referential line
|
||||||
|
// blows things up... see test 2010.)
|
||||||
codeListView.SelectionMode = SelectionMode.Single;
|
codeListView.SelectionMode = SelectionMode.Single;
|
||||||
codeListView.SelectedItem = CodeDisplayList[start];
|
codeListView.SelectedItem = CodeDisplayList[start];
|
||||||
codeListView.SelectionMode = SelectionMode.Extended;
|
codeListView.SelectionMode = SelectionMode.Extended;
|
||||||
@ -908,14 +918,23 @@ namespace SourceGen.WpfGui {
|
|||||||
/// <param name="newParts">Replacement parts.</param>
|
/// <param name="newParts">Replacement parts.</param>
|
||||||
private void CodeListView_ReplaceEntry(int index, DisplayList.FormattedParts newParts) {
|
private void CodeListView_ReplaceEntry(int index, DisplayList.FormattedParts newParts) {
|
||||||
bool isSelected = CodeDisplayList.SelectedIndices[index];
|
bool isSelected = CodeDisplayList.SelectedIndices[index];
|
||||||
if (isSelected) {
|
if (isSelected && codeListView.SelectionMode != SelectionMode.Single) {
|
||||||
|
if (codeListView.SelectionMode != SelectionMode.Single) {
|
||||||
|
Debug.WriteLine("HEY: hit unhappy single-select case");
|
||||||
|
codeListView.SelectedIndex = -1;
|
||||||
|
} else {
|
||||||
codeListView.SelectedItems.Remove(CodeDisplayList[index]);
|
codeListView.SelectedItems.Remove(CodeDisplayList[index]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
CodeDisplayList[index] = newParts;
|
CodeDisplayList[index] = newParts;
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
|
if (codeListView.SelectionMode == SelectionMode.Single) {
|
||||||
|
codeListView.SelectedIndex = index;
|
||||||
|
} else {
|
||||||
codeListView.SelectedItems.Add(newParts);
|
codeListView.SelectedItems.Add(newParts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensures the the code ListView control has input focus.
|
/// Ensures the the code ListView control has input focus.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user