Skip to content

Commit c96378f

Browse files
authored
Feature: Improve Column View (#11344)
1 parent cda8b99 commit c96378f

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/Files.App/Views/LayoutModes/ColumnViewBase.xaml.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
107107
{
108108
if (eventArgs.Parameter is NavigationArguments navArgs)
109109
{
110-
navArgs.FocusOnNavigation = (navArgs.AssociatedTabInstance as ColumnShellPage)?.ColumnParams?.Column == 0; // Focus filelist only if first column
111110
columnsOwner = (navArgs.AssociatedTabInstance as FrameworkElement)?.FindAscendant<ColumnViewBrowser>();
111+
var index = (navArgs.AssociatedTabInstance as ColumnShellPage)?.ColumnParams?.Column;
112+
navArgs.FocusOnNavigation = index == columnsOwner?.FocusIndex;
113+
114+
if (index < columnsOwner?.FocusIndex)
115+
FileList.ContainerContentChanging += HighlightPathDirectory;
112116
}
113117

114118
base.OnNavigatedTo(eventArgs);
@@ -117,6 +121,17 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
117121
FolderSettings.GroupOptionPreferenceUpdated += ZoomIn;
118122
}
119123

124+
private void HighlightPathDirectory(ListViewBase sender, ContainerContentChangingEventArgs args)
125+
{
126+
if (args.Item is ListedItem item && columnsOwner?.OwnerPath is string ownerPath
127+
&& (ownerPath == item.ItemPath || ownerPath.StartsWith(item.ItemPath) && ownerPath[item.ItemPath.Length] is '/' or '\\'))
128+
{
129+
var presenter = args.ItemContainer.FindDescendant<Grid>()!;
130+
presenter!.Background = this.Resources["ListViewItemBackgroundSelected"] as SolidColorBrush;
131+
FileList.ContainerContentChanging -= HighlightPathDirectory;
132+
}
133+
}
134+
120135
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
121136
{
122137
base.OnNavigatingFrom(e);
@@ -454,4 +469,4 @@ internal void ClearSelectionIndicator()
454469
FileList.SelectedItem = null;
455470
}
456471
}
457-
}
472+
}

src/Files.App/Views/LayoutModes/ColumnViewBrowser.xaml.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Linq;
1414
using static Files.App.Constants;
15+
using static Files.App.Helpers.PathNormalization;
1516

1617
namespace Files.App.Views.LayoutModes
1718
{
@@ -20,6 +21,9 @@ public sealed partial class ColumnViewBrowser : BaseLayout
2021
protected override uint IconSize => Browser.ColumnViewBrowser.ColumnViewSizeSmall;
2122
protected override ItemsControl ItemsControl => ColumnHost;
2223

24+
public string? OwnerPath { get; private set; }
25+
public int FocusIndex { get; private set; }
26+
2327
public ColumnViewBrowser() : base()
2428
{
2529
InitializeComponent();
@@ -66,6 +70,8 @@ private void ColumnViewBase_ItemInvoked(object? sender, EventArgs e)
6670
Column = ColumnHost.ActiveBlades.IndexOf(newblade),
6771
NavPathParam = column.NavPathParam
6872
});
73+
navigationArguments.NavPathParam = column.NavPathParam;
74+
ParentShellPageInstance.TabItemArguments.NavigationArg = column.NavPathParam;
6975
}
7076
}
7177

@@ -78,7 +84,21 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
7884
{
7985
base.OnNavigatedTo(eventArgs);
8086

81-
var navigationArguments = (NavigationArguments)eventArgs.Parameter;
87+
var path = navigationArguments.NavPathParam;
88+
var pathStack = new Stack<string>();
89+
90+
if (path is not null)
91+
{
92+
var rootPathList = App.QuickAccessManager.Model.FavoriteItems.Select(x => NormalizePath(x)).ToList();
93+
rootPathList.Add(NormalizePath(GetPathRoot(path)));
94+
95+
while (!rootPathList.Contains(NormalizePath(path)))
96+
{
97+
pathStack.Push(path);
98+
path = GetParentDir(path);
99+
}
100+
}
101+
82102
MainPageFrame.Navigated += Frame_Navigated;
83103
MainPageFrame.Navigate(typeof(ColumnShellPage), new ColumnParam
84104
{
@@ -87,8 +107,21 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
87107
SearchQuery = navigationArguments.SearchQuery,
88108
SearchUnindexedItems = navigationArguments.SearchUnindexedItems,
89109
SearchPathParam = navigationArguments.SearchPathParam,
90-
NavPathParam = navigationArguments.NavPathParam
110+
NavPathParam = path
91111
});
112+
OwnerPath = navigationArguments.NavPathParam;
113+
FocusIndex = pathStack.Count;
114+
var index = 0;
115+
while (pathStack.TryPop(out path))
116+
{
117+
var (frame, _) = CreateAndAddNewBlade();
118+
119+
frame.Navigate(typeof(ColumnShellPage), new ColumnParam
120+
{
121+
Column = ++index,
122+
NavPathParam = path
123+
});
124+
}
92125
}
93126

94127
protected override void InitializeCommandsViewModel()
@@ -163,6 +196,11 @@ private void DismissOtherBlades(int index)
163196
ColumnHost.Items.RemoveAt(index + 1);
164197
ColumnHost.ActiveBlades.RemoveAt(index + 1);
165198
}
199+
if ((ColumnHost.ActiveBlades[index].Content as Frame)?.Content is ColumnShellPage s)
200+
{
201+
navigationArguments.NavPathParam = s.FilesystemViewModel.WorkingDirectory;
202+
ParentShellPageInstance.TabItemArguments.NavigationArg = s.FilesystemViewModel.WorkingDirectory;
203+
}
166204
});
167205
}
168206
ContentChanged(ActiveColumnShellPage);
@@ -242,6 +280,7 @@ public void MoveFocusToPreviousBlade(int currentBladeIndex)
242280

243281
var activeBlade = ColumnHost.ActiveBlades[currentBladeIndex - 1];
244282
activeBlade.Focus(FocusState.Programmatic);
283+
FocusIndex = currentBladeIndex - 1;
245284

246285
var activeBladeColumnViewBase = RetrieveBladeColumnViewBase(activeBlade);
247286
if (activeBladeColumnViewBase is null)
@@ -260,6 +299,7 @@ public void MoveFocusToNextBlade(int currentBladeIndex)
260299

261300
var activeBlade = ColumnHost.ActiveBlades[currentBladeIndex];
262301
activeBlade.Focus(FocusState.Programmatic);
302+
FocusIndex = currentBladeIndex;
263303

264304
var activeBladeColumnViewBase = RetrieveBladeColumnViewBase(activeBlade);
265305
if (activeBladeColumnViewBase is not null)

0 commit comments

Comments
 (0)