Skip to content

Feature: Close column when selecting a file #11003

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 19 commits into from
Feb 7, 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
92 changes: 46 additions & 46 deletions src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.WinUI.UI;
using Files.App.EventArguments;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.Interacts;
using Files.App.UserControls.Selection;
using Files.Backend.Services.Settings;
using Files.Shared.Enums;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
Expand All @@ -14,6 +12,7 @@
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.IO;
using System.Linq;
using Windows.Storage;
using Windows.System;
Expand All @@ -25,8 +24,6 @@ namespace Files.App.Views.LayoutModes
{
public sealed partial class ColumnViewBase : StandardViewBase
{
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();

protected override uint IconSize => Browser.ColumnViewBrowser.ColumnViewSizeSmall;

protected override ListViewBase ListViewBase => FileList;
Expand Down Expand Up @@ -104,6 +101,8 @@ protected override void ItemManipulationModel_RemoveSelectedItemInvoked(object?

public event EventHandler? ItemInvoked;

public event EventHandler? ItemTapped;

protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
{
if (eventArgs.Parameter is NavigationArguments navArgs)
Expand Down Expand Up @@ -153,17 +152,13 @@ private void ItemNameTextBox_BeforeTextChanging(TextBox textBox, TextBoxBeforeTe

protected override void EndRename(TextBox textBox)
{
if (textBox is null || textBox.Parent is null)
{
// Navigating away, do nothing
}
else
if (textBox is not null && textBox.Parent is not null)
{
// Re-focus selected list item
ListViewItem? listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
var listViewItem = FileList.ContainerFromItem(RenamingItem) as ListViewItem;
listViewItem?.Focus(FocusState.Programmatic);

TextBlock? textBlock = listViewItem?.FindDescendant("ItemName") as TextBlock;
var textBlock = listViewItem?.FindDescendant("ItemName") as TextBlock;
textBox!.Visibility = Visibility.Collapsed;
textBlock!.Visibility = Visibility.Visible;
}
Expand Down Expand Up @@ -212,21 +207,10 @@ private void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)

private void HandleRightClick(object sender, RightTappedRoutedEventArgs e)
{
var objectPressed = ((FrameworkElement)e.OriginalSource).DataContext as ListedItem;
if (objectPressed is not null)
return;
// Check if RightTapped row is currently selected
if (IsItemSelected)
{
if (SelectedItems.Contains(objectPressed))
return;
}

// The following code is only reachable when a user RightTapped an unselected row
ItemManipulationModel.SetSelectedItem(objectPressed);
HandleRightClick(e.OriginalSource);
}

private DispatcherQueueTimer tapDebounceTimer;
private readonly DispatcherQueueTimer tapDebounceTimer;

private void FileList_PreviewKeyUp(object sender, KeyRoutedEventArgs e)
{
Expand Down Expand Up @@ -289,6 +273,8 @@ protected override async void FileList_PreviewKeyDown(object sender, KeyRoutedEv
}
else if (e.Key == VirtualKey.Up || e.Key == VirtualKey.Down)
{
ClearOpenedFolderSelectionIndicator();

// If list has only one item, select it on arrow down/up (#5681)
if (!IsItemSelected)
{
Expand Down Expand Up @@ -340,9 +326,8 @@ private void FileList_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
break;
}
}
else
else if (UserSettingsService.FoldersSettingsService.DoubleClickToGoUp)
{
if (UserSettingsService.FoldersSettingsService.DoubleClickToGoUp)
ParentShellPageInstance.Up_Click();
}

Expand All @@ -356,17 +341,16 @@ private void FileList_Holding(object sender, HoldingRoutedEventArgs e)

private void HandleRightClick(object sender, HoldingRoutedEventArgs e)
{
var objectPressed = ((FrameworkElement)e.OriginalSource).DataContext as ListedItem;
HandleRightClick(e.OriginalSource);
}

if (objectPressed is not null)
return;
private void HandleRightClick(object pressed)
{
var objectPressed = ((FrameworkElement)pressed).DataContext as ListedItem;

// Check if RightTapped row is currently selected
if (IsItemSelected)
{
if (SelectedItems.Contains(objectPressed))
return;
}
if (objectPressed is not null || (IsItemSelected && SelectedItems.Contains(objectPressed)))
return;

// The following code is only reachable when a user RightTapped an unselected row
ItemManipulationModel.SetSelectedItem(objectPressed);
Expand All @@ -383,9 +367,11 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
if (ctrlPressed || shiftPressed)
return;

var isItemFile = item?.PrimaryItemAttribute is StorageItemTypes.File;
var isItemFolder = item?.PrimaryItemAttribute is StorageItemTypes.Folder;

// Check if the setting to open items with a single click is turned on
if (item is not null
&& (UserSettingsService.FoldersSettingsService.OpenItemsWithOneClick && item.PrimaryItemAttribute == StorageItemTypes.File))
if (UserSettingsService.FoldersSettingsService.OpenItemsWithOneClick && isItemFile)
{
ResetRenameDoubleClick();
_ = NavigationHelpers.OpenSelectedItems(ParentShellPageInstance, false);
Expand All @@ -397,18 +383,32 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
{
CheckRenameDoubleClick(clickedItem.DataContext);
}
else if (IsRenamingItem)
else if (IsRenamingItem &&
FileList.ContainerFromItem(RenamingItem) is ListViewItem listViewItem &&
listViewItem.FindDescendant("ListViewTextBoxItemName") is TextBox textBox)
{
if (FileList.ContainerFromItem(RenamingItem) is ListViewItem listViewItem
&& listViewItem.FindDescendant("ListViewTextBoxItemName") is TextBox textBox)
{
await CommitRename(textBox);
}
await CommitRename(textBox);
}
if (item is not null && item.PrimaryItemAttribute == StorageItemTypes.Folder &&
UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick)

if (isItemFolder && UserSettingsService.FoldersSettingsService.ColumnLayoutOpenFoldersWithOneClick)
{
ItemInvoked?.Invoke(new ColumnParam { NavPathParam = (item is ShortcutItem sht ? sht.TargetPath : item.ItemPath), ListView = FileList }, EventArgs.Empty);
ItemInvoked?.Invoke(
new ColumnParam
{
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);
}
}
}
Expand All @@ -423,7 +423,7 @@ private void Grid_Loaded(object sender, RoutedEventArgs e)
itemContainer.ContextFlyout = ItemContextMenuFlyout;
}

protected override void BaseFolderSettings_LayoutModeChangeRequested(object sender, LayoutModeEventArgs e)
protected override void BaseFolderSettings_LayoutModeChangeRequested(object? sender, LayoutModeEventArgs e)
{
var parent = this.FindAscendant<ModernShellPage>();

Expand Down
Loading