Browse Source

Fix datagrid right click selection

pull/6394/head
0x90d 5 years ago
parent
commit
8526d98d28
  1. 35
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  2. 39
      src/Avalonia.Controls.DataGrid/DataGridCell.cs
  3. 15
      src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs
  4. 17
      src/Avalonia.Controls.DataGrid/DataGridRowHeader.cs

35
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -3002,6 +3002,12 @@ namespace Avalonia.Controls
} }
} }
//TODO: Ensure right button is checked for
internal bool UpdateStateOnMouseRightButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit)
{
KeyboardHelper.GetMetaKeyState(pointerPressedEventArgs.KeyModifiers, out bool ctrl, out bool shift);
return UpdateStateOnMouseRightButtonDown(pointerPressedEventArgs, columnIndex, slot, allowEdit, shift, ctrl);
}
//TODO: Ensure left button is checked for //TODO: Ensure left button is checked for
internal bool UpdateStateOnMouseLeftButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit) internal bool UpdateStateOnMouseLeftButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit)
{ {
@ -5674,6 +5680,35 @@ namespace Avalonia.Controls
VerticalScroll?.Invoke(sender, e); VerticalScroll?.Invoke(sender, e);
} }
//TODO: Ensure right button is checked for
private bool UpdateStateOnMouseRightButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit, bool shift, bool ctrl)
{
Debug.Assert(slot >= 0);
if (shift || ctrl)
{
return true;
}
if (IsSlotOutOfBounds(slot))
{
return true;
}
if (GetRowSelection(slot))
{
return true;
}
// Unselect everything except the row that was clicked on
try
{
UpdateSelectionAndCurrency(columnIndex, slot, DataGridSelectionAction.SelectCurrent, scrollIntoView: false);
}
finally
{
NoSelectionChangeCount--;
}
return true;
}
//TODO: Ensure left button is checked for //TODO: Ensure left button is checked for
private bool UpdateStateOnMouseLeftButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit, bool shift, bool ctrl) private bool UpdateStateOnMouseLeftButtonDown(PointerPressedEventArgs pointerPressedEventArgs, int columnIndex, int slot, bool allowEdit, bool shift, bool ctrl)
{ {

39
src/Avalonia.Controls.DataGrid/DataGridCell.cs

@ -161,21 +161,34 @@ namespace Avalonia.Controls
private void DataGridCell_PointerPressed(PointerPressedEventArgs e) private void DataGridCell_PointerPressed(PointerPressedEventArgs e)
{ {
// OwningGrid is null for TopLeftHeaderCell and TopRightHeaderCell because they have no OwningRow // OwningGrid is null for TopLeftHeaderCell and TopRightHeaderCell because they have no OwningRow
if (OwningGrid != null) if (OwningGrid == null)
{ {
OwningGrid.OnCellPointerPressed(new DataGridCellPointerPressedEventArgs(this, OwningRow, OwningColumn, e)); return;
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) }
OwningGrid.OnCellPointerPressed(new DataGridCellPointerPressedEventArgs(this, OwningRow, OwningColumn, e));
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
if (!e.Handled)
//if (!e.Handled && OwningGrid.IsTabStop)
{ {
if (!e.Handled) OwningGrid.Focus();
//if (!e.Handled && OwningGrid.IsTabStop) }
{ if (OwningRow != null)
OwningGrid.Focus(); {
} e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled);
if (OwningRow != null) OwningGrid.UpdatedStateOnMouseLeftButtonDown = true;
{ }
e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled); }
OwningGrid.UpdatedStateOnMouseLeftButtonDown = true; else if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed)
} {
if (!e.Handled)
//if (!e.Handled && OwningGrid.IsTabStop)
{
OwningGrid.Focus();
}
if (OwningRow != null)
{
e.Handled = OwningGrid.UpdateStateOnMouseRightButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled);
} }
} }
} }

15
src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs

@ -283,7 +283,11 @@ namespace Avalonia.Controls
//TODO TabStop //TODO TabStop
private void DataGridRowGroupHeader_PointerPressed(PointerPressedEventArgs e) private void DataGridRowGroupHeader_PointerPressed(PointerPressedEventArgs e)
{ {
if (OwningGrid != null && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) if (OwningGrid == null)
{
return;
}
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{ {
if (OwningGrid.IsDoubleClickRecordsClickOnCall(this) && !e.Handled) if (OwningGrid.IsDoubleClickRecordsClickOnCall(this) && !e.Handled)
{ {
@ -300,6 +304,15 @@ namespace Avalonia.Controls
e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, OwningGrid.CurrentColumnIndex, RowGroupInfo.Slot, allowEdit: false); e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, OwningGrid.CurrentColumnIndex, RowGroupInfo.Slot, allowEdit: false);
} }
} }
else if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed)
{
if (!e.Handled)
{
OwningGrid.Focus();
}
e.Handled = OwningGrid.UpdateStateOnMouseRightButtonDown(e, OwningGrid.CurrentColumnIndex, RowGroupInfo.Slot, allowEdit: false);
}
} }
private void EnsureChildClip(Visual child, double frozenLeftEdge) private void EnsureChildClip(Visual child, double frozenLeftEdge)

17
src/Avalonia.Controls.DataGrid/DataGridRowHeader.cs

@ -179,12 +179,12 @@ namespace Avalonia.Controls.Primitives
//TODO TabStop //TODO TabStop
private void DataGridRowHeader_PointerPressed(object sender, PointerPressedEventArgs e) private void DataGridRowHeader_PointerPressed(object sender, PointerPressedEventArgs e)
{ {
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) if (OwningGrid == null)
{ {
return; return;
} }
if (OwningGrid != null) if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{ {
if (!e.Handled) if (!e.Handled)
//if (!e.Handled && OwningGrid.IsTabStop) //if (!e.Handled && OwningGrid.IsTabStop)
@ -199,6 +199,19 @@ namespace Avalonia.Controls.Primitives
OwningGrid.UpdatedStateOnMouseLeftButtonDown = true; OwningGrid.UpdatedStateOnMouseLeftButtonDown = true;
} }
} }
else if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed)
{
if (!e.Handled)
{
OwningGrid.Focus();
}
if (OwningRow != null)
{
Debug.Assert(sender is DataGridRowHeader);
Debug.Assert(sender == this);
e.Handled = OwningGrid.UpdateStateOnMouseRightButtonDown(e, -1, Slot, false);
}
}
} }
} }

Loading…
Cancel
Save