Skip to content
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

Feature: Removed accent color from non-selected items in the column layout #10818

Merged
merged 19 commits into from
Dec 28, 2022
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
7 changes: 4 additions & 3 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@
<ListView.ItemTemplate>
<DataTemplate x:DataType="local2:ListedItem">
<Grid
x:Name="FilesRootGrid"
Height="30"
Margin="0"
Padding="8,0,0,0"
Padding="20,0,12,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Transparent"
CornerRadius="{StaticResource ControlCornerRadius}"
IsRightTapEnabled="True"
Loaded="Grid_Loaded"
Expand Down Expand Up @@ -389,6 +389,7 @@
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="1" />
<Setter Property="Height" Value="{ThemeResource ListItemHeight}" />
<Setter Property="Padding" Value="4,0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
Expand Down Expand Up @@ -462,7 +463,7 @@
Width="0"
Height="0"
Fill="{ThemeResource SystemAccentColor}"
Opacity=".5"
Opacity="0.5"
Stroke="{ThemeResource SystemAccentColorLight1}"
StrokeThickness="1" />
</Canvas>
Expand Down
57 changes: 57 additions & 0 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
Expand All @@ -33,12 +34,43 @@ public sealed partial class ColumnViewBase : BaseLayout

protected override ItemsControl ItemsControl => FileList;

private ColumnViewBrowser? columnsOwner;
private ListViewItem? openedFolderPresenter;

public ColumnViewBase() : base()
{
this.InitializeComponent();
var selectionRectangle = RectangleSelection.Create(FileList, SelectionRectangle, FileList_SelectionChanged);
selectionRectangle.SelectionEnded += SelectionRectangle_SelectionEnded;
tapDebounceTimer = DispatcherQueue.CreateTimer();
this.ItemInvoked += ColumnViewBase_ItemInvoked;
this.GotFocus += ColumnViewBase_GotFocus;
}

private void ColumnViewBase_GotFocus(object sender, RoutedEventArgs e)
{
if(FileList.SelectedItem == null && openedFolderPresenter != null)
{
openedFolderPresenter.Focus(FocusState.Programmatic);
FileList.SelectedItem = FileList.ItemFromContainer(openedFolderPresenter);
}
}

private void ColumnViewBase_ItemInvoked(object? sender, EventArgs e)
{
ClearOpenedFolderSelectionIndicator();
openedFolderPresenter = FileList.ContainerFromItem(FileList.SelectedItem) as ListViewItem;
}

private void ClearOpenedFolderSelectionIndicator()
{
if (openedFolderPresenter is null)
return;

openedFolderPresenter.Background = new SolidColorBrush(Microsoft.UI.Colors.Transparent);
var presenter = openedFolderPresenter.FindDescendant<Grid>()!;
presenter!.Background = new SolidColorBrush(Microsoft.UI.Colors.Transparent);
openedFolderPresenter = null;
}

protected override void HookEvents()
Expand Down Expand Up @@ -148,7 +180,10 @@ protected override void UnhookEvents()
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
{
if (eventArgs.Parameter is NavigationArguments navArgs)
{
navArgs.FocusOnNavigation = (navArgs.AssociatedTabInstance as ColumnShellPage)?.ColumnParams?.Column == 0; // Focus filelist only if first column
columnsOwner = (navArgs.AssociatedTabInstance as FrameworkElement)?.FindAscendant<ColumnViewBrowser>();
}

base.OnNavigatedTo(eventArgs);

Expand Down Expand Up @@ -296,6 +331,7 @@ public override void Dispose()
base.Dispose();
UnhookEvents();
CommandsViewModel?.Dispose();
columnsOwner = null;
}

#endregion IDisposable
Expand All @@ -306,8 +342,21 @@ private async void FileList_SelectionChanged(object sender, SelectionChangedEven

if (SelectedItems.Count == 1 && App.AppModel.IsQuickLookAvailable)
await QuickLookHelpers.ToggleQuickLook(ParentShellPageInstance, true);

if (e != null)
{
if (e.AddedItems.Count > 0)
columnsOwner?.HandleSelectionChange(this);

if (e.RemovedItems.Count > 0 && openedFolderPresenter != null)
{
var presenter = openedFolderPresenter.FindDescendant<Grid>()!;
presenter!.Background = this.Resources["ListViewItemBackgroundSelected"] as SolidColorBrush;
}
}
}


private void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
if (!IsRenamingItem)
Expand Down Expand Up @@ -404,6 +453,8 @@ private async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)

var currentBladeIndex = (ParentShellPageInstance is ColumnShellPage associatedColumnShellPage) ? associatedColumnShellPage.ColumnParams.Column : 0;
this.FindAscendant<ColumnViewBrowser>()?.MoveFocusToPreviousBlade(currentBladeIndex);
FileList.SelectedItem = null;
ClearOpenedFolderSelectionIndicator();
e.Handled = true;
}
else if (e.Key == VirtualKey.Right) // Right arrow: switch focus to next column
Expand Down Expand Up @@ -499,6 +550,7 @@ private void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
var item = (e.OriginalSource as FrameworkElement)?.DataContext as ListedItem;


// Allow for Ctrl+Shift selection
if (ctrlPressed || shiftPressed)
return;
Expand Down Expand Up @@ -568,5 +620,10 @@ protected override void BaseFolderSettings_LayoutModeChangeRequested(object send
break;
}
}

internal void ClearSelectionIndicator()
{
FileList.SelectedItem = null;
}
}
}
10 changes: 10 additions & 0 deletions src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public ColumnViewBrowser() : base()
this.InitializeComponent();
}

public void HandleSelectionChange(ColumnViewBase initiator)
{
foreach (var blade in ColumnHost.ActiveBlades)
{
var columnView = blade.FindDescendant<ColumnViewBase>();
if (columnView != null && columnView != initiator)
columnView.ClearSelectionIndicator();
}
}

protected override void HookEvents()
{
}
Expand Down