Skip to content

Commit

Permalink
Update the logic within SpadeView that enforces a specific TreeViewIt…
Browse files Browse the repository at this point in the history
…em is selected to utilize the TreeViewMultipleSelectionBehavior's SelectSingleItem so that the AnchorItem is correctly reset.
  • Loading branch information
codecadwallader committed Nov 21, 2015
1 parent ef272c8 commit 01e8084
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 3 additions & 6 deletions CodeMaid/UI/ToolWindows/Spade/SpadeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace SteveCadwallader.CodeMaid.UI.ToolWindows.Spade
{
Expand Down Expand Up @@ -430,14 +431,10 @@ private IList<TreeViewItem> GetSelectedTreeViewItemsIncluding(TreeViewItem treeV
// If the specified tree view item is not selected, change the current selection to it.
if (!selectedTreeViewItems.Contains(treeViewItem))
{
foreach (var selectedTreeViewItem in selectedTreeViewItems)
{
TreeViewMultipleSelectionBehavior.SetIsItemSelected(selectedTreeViewItem, false);
}
var behavior = Interaction.GetBehaviors(treeView).OfType<TreeViewMultipleSelectionBehavior>().FirstOrDefault();
behavior?.SelectSingleItem(treeViewItem);

selectedTreeViewItems.Clear();

TreeViewMultipleSelectionBehavior.SetIsItemSelected(treeViewItem, true);
selectedTreeViewItems.Add(treeViewItem);
}

Expand Down
12 changes: 8 additions & 4 deletions CodeMaid/UI/TreeViewMultipleSelectionBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override void OnDetaching()

#endregion Behavior

#region Methods
#region Event Handlers

/// <summary>
/// Called when a TreeViewItem receives a key down event.
Expand Down Expand Up @@ -224,11 +224,15 @@ private void OnTreeViewItemMouseUp(object sender, MouseButtonEventArgs e)
}
}

#endregion Event Handlers

#region Methods

/// <summary>
/// Selects a range of consecutive items from the specified tree view item to the anchor (if exists).
/// </summary>
/// <param name="treeViewItem">The triggering tree view item.</param>
private void SelectMultipleItemsContinuously(TreeViewItem treeViewItem)
public void SelectMultipleItemsContinuously(TreeViewItem treeViewItem)
{
if (AnchorItem != null)
{
Expand Down Expand Up @@ -262,7 +266,7 @@ private void SelectMultipleItemsContinuously(TreeViewItem treeViewItem)
/// Selects the specified tree view item, removing any other selections.
/// </summary>
/// <param name="treeViewItem">The triggering tree view item.</param>
private void SelectSingleItem(TreeViewItem treeViewItem)
public void SelectSingleItem(TreeViewItem treeViewItem)
{
DeSelectAll();
SetIsItemSelected(treeViewItem, true);
Expand All @@ -273,7 +277,7 @@ private void SelectSingleItem(TreeViewItem treeViewItem)
/// Toggles the selection state of the specified tree view item.
/// </summary>
/// <param name="treeViewItem">The triggering tree view item.</param>
private void ToggleSingleItem(TreeViewItem treeViewItem)
public void ToggleSingleItem(TreeViewItem treeViewItem)
{
SetIsItemSelected(treeViewItem, !GetIsItemSelected(treeViewItem));

Expand Down

0 comments on commit 01e8084

Please sign in to comment.