Skip to content

Commit

Permalink
Match GtkSharp behaviour for switching to Single from Multi
Browse files Browse the repository at this point in the history
If the cursor is on an unselected row then select nothing.
  • Loading branch information
Lee Richardson committed Apr 15, 2024
1 parent dd06536 commit 7953a2d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Eto.Gtk/Forms/Controls/GridHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,24 +725,25 @@ private void SetSelectionMode(bool allowEmptySelection, bool allowMultipleSelect
{
(true, true) => Gtk.SelectionMode.Multiple,
(true, false) => Gtk.SelectionMode.Single,
(false, true) => Gtk.SelectionMode.Multiple, // Handled by SelectFunction
(false, true) => Gtk.SelectionMode.Multiple, // Handled by Selection Changed event in Initialize().
(false, false) => Gtk.SelectionMode.Browse
};

if (newMode != currentMode)
{
// Workaround to not lose the ability to select after switching to Multi, unselecting everything,
// then switching back to Single or Browse. Cause unknown but reproduced in GtkSharp.
if (currentMode == Gtk.SelectionMode.Multiple && newMode != Gtk.SelectionMode.Multiple)
if (currentMode == Gtk.SelectionMode.Multiple
&& newMode is Gtk.SelectionMode.Single or Gtk.SelectionMode.Browse)
{
var anyWereSelected = Control.Selection.CountSelectedRows() > 0;
Control.GetCursor(out var cursorRowPath, out _);
var cursorWasSelected = Control.Selection.PathIsSelected(cursorRowPath);

Control.Selection.Mode = Gtk.SelectionMode.None;
Control.Selection.Mode = newMode;
if (anyWereSelected)
if (cursorWasSelected)
{
Control.GetCursor(out var cursorRow, out _);
Control.Selection.SelectPath(cursorRow);
Control.Selection.SelectPath(cursorRowPath);
}
}
Control.Selection.Mode = newMode;
Expand Down

0 comments on commit 7953a2d

Please sign in to comment.