Skip to content

Commit

Permalink
Fix: Fixed cannot select Files in columns view (#12124)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo authored Apr 21, 2023
1 parent fa9e57d commit bdc1b68
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/Files.App/Views/ColumnParam.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Files.App.Views.LayoutModes;
using Microsoft.UI.Xaml.Controls;

namespace Files.App.Views
Expand All @@ -7,5 +8,7 @@ public class ColumnParam : NavigationArguments
public int Column { get; set; }

public ListView ListView { get; set; }

public ColumnViewBase? Source { get; set; }
}
}
40 changes: 30 additions & 10 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
using Windows.Storage;
using Windows.System;
using Windows.UI.Core;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
using static Files.App.Constants;
using Microsoft.UI.Dispatching;

namespace Files.App.Views.LayoutModes
{
Expand All @@ -31,6 +33,8 @@ public sealed partial class ColumnViewBase : StandardViewBase

protected override SemanticZoom RootZoom => RootGridZoom;

private readonly DispatcherQueueTimer doubleClickTimer;

private ColumnViewBrowser? columnsOwner;

private ListViewItem? openedFolderPresenter;
Expand All @@ -42,6 +46,8 @@ public ColumnViewBase() : base()
selectionRectangle.SelectionEnded += SelectionRectangle_SelectionEnded;
ItemInvoked += ColumnViewBase_ItemInvoked;
GotFocus += ColumnViewBase_GotFocus;

doubleClickTimer = DispatcherQueue.CreateTimer();
}

private void ColumnViewBase_GotFocus(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -234,7 +240,7 @@ private void FileList_PreviewKeyUp(object sender, KeyRoutedEventArgs e)
{
// Open selected directory
if (IsItemSelected && SelectedItem?.PrimaryItemAttribute == StorageItemTypes.Folder)
ItemInvoked?.Invoke(new ColumnParam { NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty);
ItemInvoked?.Invoke(new ColumnParam { Source = this, NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty);
}

protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
Expand All @@ -259,7 +265,7 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv
e.Handled = true;

if (IsItemSelected && SelectedItem.PrimaryItemAttribute == StorageItemTypes.Folder)
ItemInvoked?.Invoke(new ColumnParam { NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty);
ItemInvoked?.Invoke(new ColumnParam { Source = this, NavPathParam = (SelectedItem is ShortcutItem sht ? sht.TargetPath : SelectedItem.ItemPath), ListView = FileList }, EventArgs.Empty);
}
else if (e.Key == VirtualKey.Enter && e.KeyStatus.IsMenuKeyDown)
{
Expand Down Expand Up @@ -316,6 +322,8 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv

private void FileList_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
doubleClickTimer.Stop();

var clickedItem = e.OriginalSource as FrameworkElement;

if (clickedItem?.DataContext is ListedItem item)
Expand All @@ -328,7 +336,7 @@ private void FileList_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
break;
case StorageItemTypes.Folder:
if (!UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick)
ItemInvoked?.Invoke(new ColumnParam { NavPathParam = (item is ShortcutItem sht ? sht.TargetPath : item.ItemPath), ListView = FileList }, EventArgs.Empty);
ItemInvoked?.Invoke(new ColumnParam { Source = this, NavPathParam = (item is ShortcutItem sht ? sht.TargetPath : item.ItemPath), ListView = FileList }, EventArgs.Empty);
break;
default:
if (UserSettingsService.FoldersSettingsService.DoubleClickToGoUp)
Expand Down Expand Up @@ -405,24 +413,36 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
ItemInvoked?.Invoke(
new ColumnParam
{
Source = this,
NavPathParam = (item is ShortcutItem sht ? sht.TargetPath : item!.ItemPath),
ListView = FileList
},
EventArgs.Empty);
}
else if (!IsRenamingItem && (isItemFile || isItemFolder))
{
ClearOpenedFolderSelectionIndicator();

var itemPath = item!.ItemPath.EndsWith('\\')
? item.ItemPath.Substring(0, item.ItemPath.Length - 1)
: item.ItemPath;

ItemTapped?.Invoke(new ColumnParam { NavPathParam = Path.GetDirectoryName(itemPath), ListView = FileList }, EventArgs.Empty);
CheckDoubleClick(item!);
}
}
}

private void CheckDoubleClick(ListedItem item)
{
doubleClickTimer.Debounce(() =>
{
ClearOpenedFolderSelectionIndicator();

var itemPath = item!.ItemPath.EndsWith('\\')
? item.ItemPath.Substring(0, item.ItemPath.Length - 1)
: item.ItemPath;

ItemTapped?.Invoke(new ColumnParam { Source = this, NavPathParam = Path.GetDirectoryName(itemPath), ListView = FileList }, EventArgs.Empty);

doubleClickTimer.Stop();
},
TimeSpan.FromMilliseconds(200));
}

private void Grid_Loaded(object sender, RoutedEventArgs e)
{
var itemContainer = (sender as Grid)?.FindAscendant<ListViewItem>();
Expand Down
34 changes: 26 additions & 8 deletions src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using Windows.Storage;
using Windows.System.Threading.Core;
using static Files.App.Constants;
using static Files.App.Helpers.PathNormalization;

Expand Down Expand Up @@ -77,8 +78,7 @@ private void ColumnViewBase_ItemInvoked(object? sender, EventArgs e)
navigationArguments.NavPathParam = column.NavPathParam;
ParentShellPageInstance.TabItemArguments.NavigationArg = column.NavPathParam;
}
else if (UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick &&
arePathsDifferent)
else if (UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick)
{
CloseUnnecessaryColumns(column);
}
Expand Down Expand Up @@ -435,19 +435,37 @@ private void ColumnViewBase_ItemTapped(object? sender, EventArgs e)
var column = sender as ColumnParam;
if (column?.ListView.FindAscendant<ColumnViewBrowser>() != this || string.IsNullOrEmpty(column.NavPathParam))
return;

CloseUnnecessaryColumns(column);
}

private void CloseUnnecessaryColumns(ColumnParam column)
{
var columnPath = ((ColumnHost.ActiveBlades.Last().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel?.WorkingDirectory;
var columnFirstPath = ((ColumnHost.ActiveBlades.First().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
if (string.IsNullOrEmpty(columnPath) || string.IsNullOrEmpty(columnFirstPath))
if (string.IsNullOrEmpty(column.NavPathParam))
return;

var destComponents = StorageFileExtensions.GetDirectoryPathComponents(column.NavPathParam);
var (_, relativeIndex) = GetLastCommonAndRelativeIndex(destComponents, columnPath, columnFirstPath);
var relativeIndex = column.Column is not 0 ? column.Column : -1;

if (column.Source is not null)
{
for (var i = 0; i < ColumnHost.ActiveBlades.Count && relativeIndex is -1; i++)
{
var bladeColumn = ColumnHost.ActiveBlades[i].FindDescendant<ColumnViewBase>();
if (bladeColumn is not null && bladeColumn == column.Source)
relativeIndex = i;
}
}

if (relativeIndex is -1)
{
// Get the index of the blade with the same path as the requested
var blade = ColumnHost.ActiveBlades.FirstOrDefault(b =>
column.NavPathParam.Equals(((b.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel?.WorkingDirectory));

if (blade is not null)
relativeIndex = ColumnHost.ActiveBlades.IndexOf(blade);
}

if (relativeIndex >= 0)
{
ColumnHost.ActiveBlades[relativeIndex].FindDescendant<ColumnViewBase>()?.ClearOpenedFolderSelectionIndicator();
Expand Down

0 comments on commit bdc1b68

Please sign in to comment.