diff --git a/src/Files.App/Views/ColumnParam.cs b/src/Files.App/Views/ColumnParam.cs index 3b1514034792..9bedf748491e 100644 --- a/src/Files.App/Views/ColumnParam.cs +++ b/src/Files.App/Views/ColumnParam.cs @@ -1,3 +1,4 @@ +using Files.App.Views.LayoutModes; using Microsoft.UI.Xaml.Controls; namespace Files.App.Views @@ -7,5 +8,7 @@ public class ColumnParam : NavigationArguments public int Column { get; set; } public ListView ListView { get; set; } + + public ColumnViewBase? Source { get; set; } } } diff --git a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs index edfce65521ec..03f8b2437d3b 100644 --- a/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs +++ b/src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs @@ -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 { @@ -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; @@ -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) @@ -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) @@ -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) { @@ -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) @@ -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) @@ -405,6 +413,7 @@ 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 }, @@ -412,17 +421,28 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e) } 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(); diff --git a/src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs b/src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs index ecdc2688d87b..6513f18d6782 100644 --- a/src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs +++ b/src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs @@ -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; @@ -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); } @@ -435,19 +435,37 @@ private void ColumnViewBase_ItemTapped(object? sender, EventArgs e) var column = sender as ColumnParam; if (column?.ListView.FindAscendant() != 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(); + 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()?.ClearOpenedFolderSelectionIndicator();