mirror of
https://github.com/fadden/6502bench.git
synced 2025-01-05 23:30:20 +00:00
Wire up selection tracking
Renamed VirtualListViewSelection to DisplayListSelection, because it's now tied to the DisplayList implementation. Hooked it up to handle SelectionChanged events. Also, tweaked the code list item style to remove the one-pixel gap between items. Somehow I manage to click on the dead zone with surprising regularity.
This commit is contained in:
parent
fdbd5b89e9
commit
558f1e4350
@ -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 {
|
||||
/// <summary>
|
||||
@ -66,12 +62,18 @@ namespace SourceGenWPF {
|
||||
/// </remarks>
|
||||
public LineListGen ListGen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set of selected items, by list index.
|
||||
/// </summary>
|
||||
public DisplayListSelection SelectedIndices { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an empty collection, with the default initial capacity.
|
||||
/// </summary>
|
||||
public DisplayList() {
|
||||
mList = new List<FormattedParts>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the list, filling it with empty elements.
|
||||
/// Resets the list, filling it with empty elements. Also resets the selected indices.
|
||||
/// </summary>
|
||||
/// <param name="size">New size of the list.</param>
|
||||
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() { }
|
||||
|
||||
|
@ -17,16 +17,17 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Windows.Controls;
|
||||
using CommonUtil;
|
||||
|
||||
namespace SourceGenWPF {
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class VirtualListViewSelection {
|
||||
public class DisplayListSelection {
|
||||
private BitArray mSelection;
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// Handle a state change for a single item.
|
||||
/// Handles selection change.
|
||||
/// </summary>
|
||||
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;
|
||||
/// <param name="e">Argument from SelectionChanged event.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle a state change for a range of items.
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Confirms that the selection count matches the number of set bits. Pass
|
@ -231,7 +231,7 @@ namespace SourceGenWPF {
|
||||
/// <param name="dl">Display list, with list of Lines.</param>
|
||||
/// <param name="sel">Bit vector specifying which lines are selected.</param>
|
||||
/// <returns>New SavedSelection object.</returns>
|
||||
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 {
|
||||
/// </summary>
|
||||
/// <param name="dl">Display list, with list of Lines.</param>
|
||||
/// <returns>Set of selected lines.</returns>
|
||||
public VirtualListViewSelection Restore(LineListGen dl, out int topIndex) {
|
||||
public DisplayListSelection Restore(LineListGen dl, out int topIndex) {
|
||||
List<Line> lineList = dl.mLineList;
|
||||
VirtualListViewSelection sel = new VirtualListViewSelection(lineList.Count);
|
||||
DisplayListSelection sel = new DisplayListSelection(lineList.Count);
|
||||
|
||||
topIndex = -1;
|
||||
|
||||
|
@ -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.
|
||||
|
@ -133,6 +133,12 @@ See also https://github.com/fadden/DisasmUiTest
|
||||
</ControlTemplate>
|
||||
|
||||
<Style x:Key="codeListItemStyle" TargetType="{x:Type ListViewItem}">
|
||||
<!-- There's a one-pixel gap between items, possibly space for grid lines, that
|
||||
can't seem to be eliminated. Declaring a negative margin removes it. This is
|
||||
necessary because the gap isn't a mouse target, so if your mouse is in just the
|
||||
wrong place you'll feel like you clicked and nothing happened. -->
|
||||
<Setter Property="Margin" Value="0,-1,0,0"/>
|
||||
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=IsLongComment}" Value="True">
|
||||
<Setter Property="Template" Value="{StaticResource longCommentTemplate}"/>
|
||||
|
@ -98,7 +98,7 @@ limitations under the License.
|
||||
</MenuItem>
|
||||
<MenuItem Header="_Edit">
|
||||
<MenuItem Command="Undo"/>
|
||||
<MenuItem Command="Redo"/>
|
||||
<MenuItem Command="Redo"/> <!-- want both Ctrl+Y and Ctrl+Shift+Z -->
|
||||
<Separator/>
|
||||
<MenuItem Command="Copy"/>
|
||||
<Separator/>
|
||||
|
@ -43,10 +43,13 @@ namespace SourceGenWPF.ProjWin {
|
||||
/// </summary>
|
||||
public DisplayList CodeDisplayList { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reference to controller object.
|
||||
/// </summary>
|
||||
private MainController mMainCtrl;
|
||||
|
||||
// Handle to protected ListView.SetSelectedItems() method
|
||||
private MethodInfo listViewSetSelectedItems;
|
||||
|
||||
public MainWindow() {
|
||||
@ -179,7 +182,7 @@ namespace SourceGenWPF.ProjWin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if we should be showing the launch panel.
|
||||
/// Returns the visibility status of the launch panel.
|
||||
/// (Intended for use from XAML.)
|
||||
/// </summary>
|
||||
public Visibility LaunchPanelVisibility {
|
||||
@ -187,7 +190,7 @@ namespace SourceGenWPF.ProjWin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if we should be showing the code ListView.
|
||||
/// Returns the visibility status of the code ListView.
|
||||
/// (Intended for use from XAML.)
|
||||
/// </summary>
|
||||
public Visibility CodeListVisibility {
|
||||
@ -207,6 +210,8 @@ namespace SourceGenWPF.ProjWin {
|
||||
e.CanExecute = mMainCtrl.IsProjectOpen();
|
||||
}
|
||||
|
||||
#region Command handlers
|
||||
|
||||
private void AssembleCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
// test
|
||||
Debug.WriteLine("assembling");
|
||||
@ -262,8 +267,13 @@ namespace SourceGenWPF.ProjWin {
|
||||
mMainCtrl.OpenRecentProject(recentIndex);
|
||||
}
|
||||
|
||||
#endregion Command handlers
|
||||
|
||||
private void CodeListView_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
//Debug.WriteLine("SEL: add " + e.AddedItems.Count + ", rem " + e.RemovedItems.Count);
|
||||
CodeDisplayList.SelectedIndices.SelectionChanged(e);
|
||||
|
||||
//Debug.Assert(CodeDisplayList.SelectedIndices.DebugValidateSelectionCount(
|
||||
// codeListView.SelectedItems.Count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@
|
||||
<Compile Include="SystemDefaults.cs" />
|
||||
<Compile Include="SystemDefs.cs" />
|
||||
<Compile Include="UndoableChange.cs" />
|
||||
<Compile Include="VirtualListViewSelection.cs" />
|
||||
<Compile Include="DisplayListSelection.cs" />
|
||||
<Compile Include="WeakSymbolRef.cs" />
|
||||
<Compile Include="XrefSet.cs" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user