Skip to content

Fix: Fixed an issue where checkbox settings weren't applied in the grid layout #12229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Files.App/Views/LayoutModes/GridViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AutomationProperties.AccessibilityView="Raw"
Checked="ItemSelected_Checked"
DoubleTapped="SelectionCheckbox_DoubleTapped"
Unchecked="ItemSelected_Unchecked"
Visibility="Collapsed" />
Opacity="0"
Unchecked="ItemSelected_Unchecked" />

<Popup x:Name="EditPopup" Grid.Row="1">
<TextBox
Expand All @@ -243,7 +244,7 @@
<VisualState x:Name="HideCheckbox" />
<VisualState x:Name="ShowCheckbox">
<VisualState.Setters>
<Setter Target="SelectionCheckbox.Visibility" Value="Visible" />
<Setter Target="SelectionCheckbox.Opacity" Value="1" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand Down Expand Up @@ -302,10 +303,11 @@
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AutomationProperties.AccessibilityView="Raw"
Checked="ItemSelected_Checked"
DoubleTapped="SelectionCheckbox_DoubleTapped"
Unchecked="ItemSelected_Unchecked"
Visibility="Collapsed" />
Opacity="0"
Unchecked="ItemSelected_Unchecked" />

<Grid
Grid.Column="1"
Expand Down Expand Up @@ -446,7 +448,7 @@
<VisualState x:Name="HideCheckbox" />
<VisualState x:Name="ShowCheckbox">
<VisualState.Setters>
<Setter Target="SelectionCheckbox.Visibility" Value="Visible" />
<Setter Target="SelectionCheckbox.Opacity" Value="1" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand Down
38 changes: 19 additions & 19 deletions src/Files.App/Views/LayoutModes/GridViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,18 @@ checkBox.DataContext is ListedItem item &&

private new void FileList_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
args.ItemContainer.PointerEntered -= ItemRow_PointerEntered;
args.ItemContainer.PointerExited -= ItemRow_PointerExited;
args.ItemContainer.PointerCanceled -= ItemRow_PointerCanceled;
var selectionCheckbox = args.ItemContainer.FindDescendant("SelectionCheckbox")!;

selectionCheckbox.PointerEntered -= SelectionCheckbox_PointerEntered;
selectionCheckbox.PointerExited -= SelectionCheckbox_PointerExited;
selectionCheckbox.PointerCanceled -= SelectionCheckbox_PointerCanceled;

base.FileList_ContainerContentChanging(sender, args);
SetCheckboxSelectionState(args.Item, args.ItemContainer as GridViewItem);

args.ItemContainer.PointerEntered += ItemRow_PointerEntered;
args.ItemContainer.PointerExited += ItemRow_PointerExited;
args.ItemContainer.PointerCanceled += ItemRow_PointerCanceled;
selectionCheckbox.PointerEntered += SelectionCheckbox_PointerEntered;
selectionCheckbox.PointerExited += SelectionCheckbox_PointerExited;
selectionCheckbox.PointerCanceled += SelectionCheckbox_PointerCanceled;
}

private void SetCheckboxSelectionState(object item, GridViewItem? lviContainer = null)
Expand All @@ -464,7 +466,7 @@ private void SetCheckboxSelectionState(object item, GridViewItem? lviContainer =
checkbox.Unchecked += ItemSelected_Unchecked;
}

UpdateCheckboxVisibility(container);
UpdateCheckboxVisibility(container, checkbox?.IsPointerOver ?? false);
}
}

Expand All @@ -481,37 +483,35 @@ private void Grid_Loaded(object sender, RoutedEventArgs e)
itemContainer.ContextFlyout = ItemContextMenuFlyout;
}

private void ItemRow_PointerEntered(object sender, PointerRoutedEventArgs e)
private void SelectionCheckbox_PointerEntered(object sender, PointerRoutedEventArgs e)
{
UpdateCheckboxVisibility(sender, true);
UpdateCheckboxVisibility((sender as FrameworkElement)!.FindAscendant<GridViewItem>()!, true);
}

private void ItemRow_PointerExited(object sender, PointerRoutedEventArgs e)
private void SelectionCheckbox_PointerExited(object sender, PointerRoutedEventArgs e)
{
UpdateCheckboxVisibility(sender, false);
UpdateCheckboxVisibility((sender as FrameworkElement)!.FindAscendant<GridViewItem>()!, false);
}

private void ItemRow_PointerCanceled(object sender, PointerRoutedEventArgs e)
private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEventArgs e)
{
UpdateCheckboxVisibility(sender, false);
UpdateCheckboxVisibility((sender as FrameworkElement)!.FindAscendant<GridViewItem>()!, false);
}

private void UpdateCheckboxVisibility(object sender, bool? isPointerOver = null)
private void UpdateCheckboxVisibility(object sender, bool isPointerOver)
{
if (sender is GridViewItem control && control.FindDescendant<UserControl>() is UserControl userControl)
{
// Save pointer over state accordingly
if (isPointerOver.HasValue)
control.SetValue(IsPointerOverProperty, isPointerOver);
// Handle visual states
// Show checkboxes when items are selected (as long as the setting is enabled)
// Show checkboxes when hovering of the item (regardless of the setting to hide them)
// Show checkboxes when hovering over the checkbox area (regardless of the setting to hide them)
if (UserSettingsService.FoldersSettingsService.ShowCheckboxesWhenSelectingItems && control.IsSelected
|| control.GetValue(IsPointerOverProperty) is not false)
|| isPointerOver)
VisualStateManager.GoToState(userControl, "ShowCheckbox", true);
else
VisualStateManager.GoToState(userControl, "HideCheckbox", true);
}
}

}
}