diff --git a/SourceGenWPF/DisplayList.cs b/SourceGenWPF/DisplayList.cs index d4a5600..104e5ee 100644 --- a/SourceGenWPF/DisplayList.cs +++ b/SourceGenWPF/DisplayList.cs @@ -16,13 +16,9 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Diagnostics; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SourceGenWPF { /// @@ -66,12 +62,18 @@ namespace SourceGenWPF { /// public LineListGen ListGen { get; set; } + /// + /// Set of selected items, by list index. + /// + public DisplayListSelection SelectedIndices { get; private set; } + /// /// Constructs an empty collection, with the default initial capacity. /// public DisplayList() { mList = new List(); + SelectedIndices = new DisplayListSelection(); } @@ -254,12 +256,13 @@ namespace SourceGenWPF { FormattedParts parts = mList[index]; if (parts == null) { parts = mList[index] = ListGen.GetFormattedParts(index); + parts.ListIndex = index; } return parts; } /// - /// Resets the list, filling it with empty elements. + /// Resets the list, filling it with empty elements. Also resets the selected indices. /// /// New size of the list. public void ResetList(int size) { @@ -275,6 +278,8 @@ namespace SourceGenWPF { OnPropertyChanged(CountString); OnPropertyChanged(IndexerName); OnCollectionReset(); + + SelectedIndices = new DisplayListSelection(size); } public class FormattedParts { @@ -289,6 +294,8 @@ namespace SourceGenWPF { public string Comment { get; private set; } public bool IsLongComment { get; private set; } + public int ListIndex { get; set; } = -1; + // Private constructor -- create instances with factory methods. private FormattedParts() { } diff --git a/SourceGenWPF/VirtualListViewSelection.cs b/SourceGenWPF/DisplayListSelection.cs similarity index 63% rename from SourceGenWPF/VirtualListViewSelection.cs rename to SourceGenWPF/DisplayListSelection.cs index 8bb05c9..bc25a3b 100644 --- a/SourceGenWPF/VirtualListViewSelection.cs +++ b/SourceGenWPF/DisplayListSelection.cs @@ -17,16 +17,17 @@ using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; - +using System.Windows.Controls; using CommonUtil; namespace SourceGenWPF { /// - /// Tracks the items selected in a list view. + /// Tracks the items selected in the DisplayList. /// - /// Forward the ItemSelectionChanged and VirtualItemsSelectionRangeChanged. + /// Forward the SelectionChanged event. In WPF you can't get indices, only items, so we + /// have to store the item index in the item itself. /// - public class VirtualListViewSelection { + public class DisplayListSelection { private BitArray mSelection; /// @@ -47,11 +48,11 @@ namespace SourceGenWPF { } } - public VirtualListViewSelection() { + public DisplayListSelection() { mSelection = new BitArray(0); } - public VirtualListViewSelection(int length) { + public DisplayListSelection(int length) { mSelection = new BitArray(length); } @@ -68,46 +69,20 @@ namespace SourceGenWPF { mSelection.Length = length; } -#if false // TODO /// - /// Handle a state change for a single item. + /// Handles selection change. /// - public void ItemSelectionChanged(ListViewItemSelectionChangedEventArgs e) { - //Debug.WriteLine("ItemSelectionChanged: " + e.ItemIndex + " (" + e.IsSelected + ")"); - if (e.ItemIndex >= mSelection.Length) { - Debug.WriteLine("GLITCH: selection index " + e.ItemIndex + " out of range"); - Debug.Assert(false); - return; + /// Argument from SelectionChanged event. + public void SelectionChanged(SelectionChangedEventArgs e) { + foreach (DisplayList.FormattedParts parts in e.AddedItems) { + Debug.Assert(parts.ListIndex >= 0 && parts.ListIndex < mSelection.Length); + mSelection.Set(parts.ListIndex, true); } - mSelection.Set(e.ItemIndex, e.IsSelected); - } - - /// - /// Handle a state change for a range of items. - /// - public void VirtualItemsSelectionRangeChanged( - ListViewVirtualItemsSelectionRangeChangedEventArgs e) { - //Debug.WriteLine("VirtualRangeChange: " + e.StartIndex + " - " + e.EndIndex + - // " (" + e.IsSelected + ")"); - - if (e.StartIndex == 0 && e.EndIndex == mSelection.Length - 1) { - // Set all elements. The list view control seems to like to set all elements - // to false whenever working with multi-select, so this should be fast. - //Debug.WriteLine("VirtualRangeChange: set all to " + e.IsSelected); - mSelection.SetAll(e.IsSelected); - } else { - if (e.EndIndex >= mSelection.Length) { - Debug.WriteLine("GLITCH: selection end index " + e.EndIndex + " out of range"); - Debug.Assert(false); - return; - } - bool val = e.IsSelected; - for (int i = e.StartIndex; i <= e.EndIndex; i++) { - mSelection.Set(i, val); - } + foreach (DisplayList.FormattedParts parts in e.RemovedItems) { + Debug.Assert(parts.ListIndex >= 0 && parts.ListIndex < mSelection.Length); + mSelection.Set(parts.ListIndex, false); } } -#endif /// /// Confirms that the selection count matches the number of set bits. Pass diff --git a/SourceGenWPF/LineListGen.cs b/SourceGenWPF/LineListGen.cs index 89edb79..b3182aa 100644 --- a/SourceGenWPF/LineListGen.cs +++ b/SourceGenWPF/LineListGen.cs @@ -231,7 +231,7 @@ namespace SourceGenWPF { /// Display list, with list of Lines. /// Bit vector specifying which lines are selected. /// New SavedSelection object. - public static SavedSelection Generate(LineListGen dl, VirtualListViewSelection sel, + public static SavedSelection Generate(LineListGen dl, DisplayListSelection sel, int topOffset) { SavedSelection savedSel = new SavedSelection(); //Debug.Assert(topOffset >= 0); @@ -297,9 +297,9 @@ namespace SourceGenWPF { /// /// Display list, with list of Lines. /// Set of selected lines. - public VirtualListViewSelection Restore(LineListGen dl, out int topIndex) { + public DisplayListSelection Restore(LineListGen dl, out int topIndex) { List lineList = dl.mLineList; - VirtualListViewSelection sel = new VirtualListViewSelection(lineList.Count); + DisplayListSelection sel = new DisplayListSelection(lineList.Count); topIndex = -1; diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 90e8d00..8fa13da 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -822,7 +822,7 @@ namespace SourceGenWPF { } mReanalysisTimer.EndTask(refreshTaskStr); - VirtualListViewSelection newSel = savedSel.Restore(CodeListGen, out int topIndex); + DisplayListSelection newSel = savedSel.Restore(CodeListGen, out int topIndex); //newSel.DebugDump(); // Refresh the various windows, and restore the selection. diff --git a/SourceGenWPF/ProjWin/CodeListItemStyle.xaml b/SourceGenWPF/ProjWin/CodeListItemStyle.xaml index 49bba26..212ed31 100644 --- a/SourceGenWPF/ProjWin/CodeListItemStyle.xaml +++ b/SourceGenWPF/ProjWin/CodeListItemStyle.xaml @@ -133,6 +133,12 @@ See also https://github.com/fadden/DisasmUiTest