Skip to content

Commit

Permalink
node centering only on user's action (#44)
Browse files Browse the repository at this point in the history
isUserInitiatedSelection to flag if the nodes in DataGrid are selected by the user
  • Loading branch information
ivaylo-matov authored Jul 16, 2024
1 parent eee7cbe commit 5ec3826
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion TuneUp/TuneUpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@
CanUserResizeColumns="True"
CanUserSortColumns="True"
HeadersVisibility="Column"
SelectionChanged="NodeAnalysisTable_SelectionChanged">
SelectionChanged="NodeAnalysisTable_SelectionChanged"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
MouseLeave="NodeAnalysisTable_MouseLeave" >

<DataGrid.GroupStyle>
<GroupStyle>
Expand Down
26 changes: 26 additions & 0 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public partial class TuneUpWindow : Window
/// </summary>
private string uniqueId;

/// <summary>
/// A flag indicating whether the current selection change in the DataGrid
/// is initiated by the user (true) or programmatically (false).
/// </summary>
private bool isUserInitiatedSelection = false;

/// <summary>
/// Since there is no API for height offset comparing to
/// DynamoWindow height. Define it as static for now.
Expand Down Expand Up @@ -58,6 +64,8 @@ private void DynamoWindow_SizeChanged(object sender, System.Windows.SizeChangedE

private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isUserInitiatedSelection) return;

// Get NodeModel(s) that correspond to selected row(s)
var selectedNodes = new List<NodeModel>();
foreach (var item in e.AddedItems)
Expand All @@ -81,6 +89,24 @@ private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedE
}
}

/// <summary>
/// Handles the PreviewMouseDown event for the NodeAnalysisTable DataGrid.
/// Sets a flag to indicate that the selection change is user-initiated.
/// </summary>
private void NodeAnalysisTable_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
isUserInitiatedSelection = true;
}

/// <summary>
/// Handles the MouseLeave event for the NodeAnalysisTable DataGrid.
/// Resets the flag to indicate that the selection change is no longer user-initiated.
/// </summary>
private void NodeAnalysisTable_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
isUserInitiatedSelection = false;
}

internal void Dispose()
{
viewLoadedParams.DynamoWindow.SizeChanged -= DynamoWindow_SizeChanged;
Expand Down

0 comments on commit 5ec3826

Please sign in to comment.