Skip to content

Commit 0e7528f

Browse files
authored
ColumnView improvements (#6648)
1 parent acb9596 commit 0e7528f

14 files changed

+159
-1049
lines changed

Files/BaseLayout.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
451451
ParentShellPageInstance.InstanceViewModel.IsPageTypeZipFolder = false;
452452
ParentShellPageInstance.InstanceViewModel.IsPageTypeLibrary = false;
453453
ParentShellPageInstance.InstanceViewModel.IsPageTypeSearchResults = true;
454+
455+
await ParentShellPageInstance.FilesystemViewModel.SetWorkingDirectoryAsync(navigationArguments.SearchPathParam);
456+
454457
if (!navigationArguments.IsLayoutSwitch)
455458
{
456459
var displayName = App.LibraryManager.TryGetLibrary(navigationArguments.SearchPathParam, out var lib) ? lib.Text : navigationArguments.SearchPathParam;

Files/Helpers/NativeFileOperationsHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static extern bool GetFileAttributesExFromApp(
148148
[return: MarshalAs(UnmanagedType.Bool)]
149149
public static extern bool SetFileAttributesFromApp(
150150
string lpFileName,
151-
System.IO.FileAttributes dwFileAttributes);
151+
FileAttributes dwFileAttributes);
152152

153153
[DllImport("api-ms-win-core-file-l1-2-1.dll", ExactSpelling = true,
154154
CallingConvention = CallingConvention.StdCall,
@@ -202,15 +202,15 @@ public enum GET_FILEEX_INFO_LEVELS
202202
[StructLayout(LayoutKind.Sequential)]
203203
public struct WIN32_FILE_ATTRIBUTE_DATA
204204
{
205-
public System.IO.FileAttributes dwFileAttributes;
205+
public FileAttributes dwFileAttributes;
206206
public FILETIME ftCreationTime;
207207
public FILETIME ftLastAccessTime;
208208
public FILETIME ftLastWriteTime;
209209
public uint nFileSizeHigh;
210210
public uint nFileSizeLow;
211211
}
212212

213-
public static bool HasFileAttribute(string lpFileName, System.IO.FileAttributes dwAttrs)
213+
public static bool HasFileAttribute(string lpFileName, FileAttributes dwAttrs)
214214
{
215215
if (GetFileAttributesExFromApp(
216216
lpFileName, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
@@ -220,7 +220,7 @@ public static bool HasFileAttribute(string lpFileName, System.IO.FileAttributes
220220
return false;
221221
}
222222

223-
public static bool SetFileAttribute(string lpFileName, System.IO.FileAttributes dwAttrs)
223+
public static bool SetFileAttribute(string lpFileName, FileAttributes dwAttrs)
224224
{
225225
if (!GetFileAttributesExFromApp(
226226
lpFileName, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
@@ -230,7 +230,7 @@ public static bool SetFileAttribute(string lpFileName, System.IO.FileAttributes
230230
return SetFileAttributesFromApp(lpFileName, lpFileInfo.dwFileAttributes | dwAttrs);
231231
}
232232

233-
public static bool UnsetFileAttribute(string lpFileName, System.IO.FileAttributes dwAttrs)
233+
public static bool UnsetFileAttribute(string lpFileName, FileAttributes dwAttrs)
234234
{
235235
if (!GetFileAttributesExFromApp(
236236
lpFileName, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo))
@@ -267,10 +267,10 @@ public static string ReadStringFromFile(string filePath)
267267
return str;
268268
}
269269

270-
public static bool WriteStringToFile(string filePath, string str)
270+
public static bool WriteStringToFile(string filePath, string str, File_Attributes flags = 0)
271271
{
272272
IntPtr hStream = CreateFileFromApp(filePath,
273-
GENERIC_WRITE, 0, IntPtr.Zero, CREATE_ALWAYS, (uint)File_Attributes.BackupSemantics, IntPtr.Zero);
273+
GENERIC_WRITE, 0, IntPtr.Zero, CREATE_ALWAYS, (uint)(File_Attributes.BackupSemantics | flags), IntPtr.Zero);
274274
if (hStream.ToInt64() == -1)
275275
{
276276
return false;

Files/UserControls/NavigationToolbar.xaml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
Background="{ThemeResource NavigationToolbarBackgroundBrush}"
336336
ColumnSpacing="0"
337337
CornerRadius="{StaticResource NavToolbarCornerRadius}">
338-
339338
<Grid Padding="8,0,8,8" ColumnSpacing="4">
340339
<Grid.ColumnDefinitions>
341340
<ColumnDefinition Width="Auto" />
@@ -558,7 +557,11 @@
558557
</Flyout>
559558
</Button.Flyout>
560559
</Button>
561-
<muxc:InfoBadge x:Name="StatusInfoBadge" HorizontalAlignment="Right" VerticalAlignment="Top" Value="{x:Bind OngoingTasksViewModel.InfoBadgeValue, Mode=OneWay}" />
560+
<muxc:InfoBadge
561+
x:Name="StatusInfoBadge"
562+
HorizontalAlignment="Right"
563+
VerticalAlignment="Top"
564+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeValue, Mode=OneWay}" />
562565
</Grid>
563566

564567
<Button
@@ -607,38 +610,49 @@
607610
<VisualStateGroup>
608611
<VisualState x:Name="TasksSuccess">
609612
<VisualState.StateTriggers>
610-
<triggers:CompareStateTrigger Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}" Comparison="Equal" To="0" />
613+
<triggers:CompareStateTrigger
614+
Comparison="Equal"
615+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
616+
To="0" />
611617
</VisualState.StateTriggers>
612618
<VisualState.Setters>
613619
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource SuccessIconInfoBadgeStyle}" />
614620
</VisualState.Setters>
615621
</VisualState>
616622
<VisualState x:Name="TasksOnging">
617623
<VisualState.StateTriggers>
618-
<triggers:CompareStateTrigger Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}" Comparison="Equal" To="1" />
624+
<triggers:CompareStateTrigger
625+
Comparison="Equal"
626+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
627+
To="1" />
619628
</VisualState.StateTriggers>
620629
<VisualState.Setters>
621630
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource AttentionValueInfoBadgeStyle}" />
622631
</VisualState.Setters>
623632
</VisualState>
624633
<VisualState x:Name="TasksFailure">
625634
<VisualState.StateTriggers>
626-
<triggers:CompareStateTrigger Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}" Comparison="Equal" To="2" />
635+
<triggers:CompareStateTrigger
636+
Comparison="Equal"
637+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
638+
To="2" />
627639
</VisualState.StateTriggers>
628640
<VisualState.Setters>
629641
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource CriticalValueInfoBadgeStyle}" />
630642
</VisualState.Setters>
631643
</VisualState>
632644
<VisualState x:Name="TasksCompletionWithFailure">
633645
<VisualState.StateTriggers>
634-
<triggers:CompareStateTrigger Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}" Comparison="Equal" To="3" />
646+
<triggers:CompareStateTrigger
647+
Comparison="Equal"
648+
Value="{x:Bind OngoingTasksViewModel.InfoBadgeState, Mode=OneWay}"
649+
To="3" />
635650
</VisualState.StateTriggers>
636651
<VisualState.Setters>
637652
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource CriticalIconInfoBadgeStyle}" />
638653
</VisualState.Setters>
639654
</VisualState>
640655
</VisualStateGroup>
641656
</VisualStateManager.VisualStateGroups>
642-
643657
</Grid>
644658
</UserControl>

Files/ViewModels/FolderSettingsViewModel.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Toolkit.Mvvm.Input;
99
using Newtonsoft.Json;
1010
using System;
11+
using System.IO;
1112
using System.Linq;
1213
using Windows.Storage;
1314
using static Files.ViewModels.FolderLayoutInformation;
@@ -538,7 +539,7 @@ public void UpdateLayoutPreferencesForPath(string folderPath, LayoutPreferences
538539

539540
private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath)
540541
{
541-
var str = NativeFileOperationsHelper.ReadStringFromFile($"{folderPath}:files_layoutmode");
542+
var str = NativeFileOperationsHelper.ReadStringFromFile(Path.Combine(folderPath, "desktop.files.json"));
542543
try
543544
{
544545
return string.IsNullOrEmpty(str) ? null : JsonConvert.DeserializeObject<LayoutPreferences>(str);
@@ -551,12 +552,14 @@ private static LayoutPreferences ReadLayoutPreferencesFromAds(string folderPath)
551552

552553
private static bool WriteLayoutPreferencesToAds(string folderPath, LayoutPreferences prefs)
553554
{
555+
var prefsFilePath = Path.Combine(folderPath, "desktop.files.json");
554556
if (LayoutPreferences.DefaultLayoutPreferences.Equals(prefs))
555557
{
556-
NativeFileOperationsHelper.DeleteFileFromApp($"{folderPath}:files_layoutmode");
558+
NativeFileOperationsHelper.DeleteFileFromApp(prefsFilePath);
557559
return false;
558560
}
559-
return NativeFileOperationsHelper.WriteStringToFile($"{folderPath}:files_layoutmode", JsonConvert.SerializeObject(prefs));
561+
return NativeFileOperationsHelper.WriteStringToFile(
562+
prefsFilePath, JsonConvert.SerializeObject(prefs), NativeFileOperationsHelper.File_Attributes.Hidden);
560563
}
561564

562565
private static LayoutPreferences ReadLayoutPreferencesFromSettings(string folderPath)

Files/Views/ColumnParam.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace Files.Views
44
{
5-
public class ColumnParam
5+
public class ColumnParam : NavigationArguments
66
{
77
public int Column { get; set; }
8-
public string Path { get; set; }
98
public ListView ListView { get; set; }
109
}
1110
}

Files/Views/ColumnShellPage.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@
105105
Invoked="KeyboardAccelerator_Invoked"
106106
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
107107
Modifiers="Control" />
108+
<KeyboardAccelerator
109+
Key="F"
110+
Invoked="KeyboardAccelerator_Invoked"
111+
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}"
112+
Modifiers="Control" />
113+
<KeyboardAccelerator
114+
Key="F3"
115+
Invoked="KeyboardAccelerator_Invoked"
116+
IsEnabled="{x:Bind IsCurrentInstance, Mode=OneWay}" />
108117
<KeyboardAccelerator
109118
Key="F1"
110119
Invoked="KeyboardAccelerator_Invoked"

Files/Views/ColumnShellPage.xaml.cs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
using System.Threading;
2525
using System.Threading.Tasks;
2626
using Windows.ApplicationModel.Core;
27-
using Windows.ApplicationModel.DataTransfer;
2827
using Windows.ApplicationModel.Resources.Core;
2928
using Windows.Storage;
3029
using Windows.System;
@@ -328,8 +327,7 @@ private void ColumnShellPage_BackNavRequested(object sender, EventArgs e)
328327
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
329328
{
330329
base.OnNavigatedTo(eventArgs);
331-
Column = (eventArgs.Parameter as ColumnParam).Column;
332-
NavParams = new NavigationParams { NavPath = (eventArgs.Parameter as ColumnParam).Path.ToString() };
330+
ColumnParams = eventArgs.Parameter as ColumnParam;
333331
}
334332

335333
private void AppSettings_SortDirectionPreferenceUpdated(object sender, SortDirection e)
@@ -435,17 +433,16 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
435433
}
436434
}
437435

438-
private NavigationParams navParams;
439-
private int Column;
436+
private ColumnParam columnParams;
440437

441-
public NavigationParams NavParams
438+
public ColumnParam ColumnParams
442439
{
443-
get => navParams;
440+
get => columnParams;
444441
set
445442
{
446-
if (value != navParams)
443+
if (value != columnParams)
447444
{
448-
navParams = value;
445+
columnParams = value;
449446
if (IsLoaded)
450447
{
451448
OnNavigationParamsChanged();
@@ -456,25 +453,16 @@ public NavigationParams NavParams
456453

457454
private void OnNavigationParamsChanged()
458455
{
459-
if (string.IsNullOrEmpty(NavParams?.NavPath) || NavParams.NavPath == "Home".GetLocalized())
460-
{
461-
ItemDisplayFrame.Navigate(typeof(WidgetsPage),
462-
new NavigationArguments()
463-
{
464-
NavPathParam = NavParams?.NavPath,
465-
AssociatedTabInstance = this
466-
});
467-
}
468-
else
469-
{
470-
ItemDisplayFrame.Navigate(typeof(ColumnViewBase),
471-
new NavigationArguments()
472-
{
473-
NavPathParam = NavParams.NavPath,
474-
SelectItems = !string.IsNullOrWhiteSpace(NavParams.SelectItem) ? new[] { NavParams.SelectItem } : null,
475-
AssociatedTabInstance = this
476-
});
477-
}
456+
ItemDisplayFrame.Navigate(typeof(ColumnViewBase),
457+
new NavigationArguments()
458+
{
459+
IsSearchResultPage = columnParams.IsSearchResultPage,
460+
SearchQuery = columnParams.SearchQuery,
461+
NavPathParam = columnParams.NavPathParam,
462+
SearchUnindexedItems = columnParams.SearchUnindexedItems,
463+
SearchPathParam = columnParams.SearchPathParam,
464+
AssociatedTabInstance = this
465+
});
478466
}
479467

480468
public static readonly DependencyProperty NavParamsProperty =
@@ -617,6 +605,11 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
617605
break;
618606
}
619607

608+
case (false, false, false, true, VirtualKey.F3): //f3
609+
case (true, false, false, true, VirtualKey.F): // ctrl + f
610+
NavToolbarViewModel.SwitchSearchBoxVisibility();
611+
break;
612+
620613
case (true, true, false, true, VirtualKey.N): // ctrl + shift + n, new item
621614
if (InstanceViewModel.CanCreateFileInPage)
622615
{
@@ -705,8 +698,8 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
705698
}
706699
break;
707700

708-
case (false, false, true, _, VirtualKey.D): // alt + d, select address bar (english)
709-
case (true, false, false, _, VirtualKey.L): // ctrl + l, select address bar
701+
case (false, false, true, true, VirtualKey.D): // alt + d, select address bar (english)
702+
case (true, false, false, true, VirtualKey.L): // ctrl + l, select address bar
710703
NavToolbarViewModel.IsEditModeEnabled = true;
711704
break;
712705

@@ -718,9 +711,9 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
718711
switch (args.KeyboardAccelerator.Key)
719712
{
720713
case VirtualKey.F2: //F2, rename
721-
if (CurrentPageType == typeof(DetailsLayoutBrowser)
722-
|| CurrentPageType == typeof(GridViewBrowser)
723-
|| CurrentPageType == typeof(ColumnViewBrowser)
714+
if (CurrentPageType == typeof(DetailsLayoutBrowser)
715+
|| CurrentPageType == typeof(GridViewBrowser)
716+
|| CurrentPageType == typeof(ColumnViewBrowser)
724717
|| CurrentPageType == typeof(ColumnViewBase))
725718
{
726719
if (ContentPage.IsItemSelected)
@@ -835,7 +828,6 @@ public void Dispose()
835828
NavToolbarViewModel.EditModeEnabled -= NavigationToolbar_EditModeEnabled;
836829
NavToolbarViewModel.ItemDraggedOverPathItem -= ColumnShellPage_NavigationRequested;
837830
NavToolbarViewModel.PathBoxQuerySubmitted -= NavigationToolbar_QuerySubmitted;
838-
//NavToolbarViewModel.RefreshWidgetsRequested -= ColumnShellPage_RefreshWidgetsRequested;
839831

840832
NavToolbarViewModel.SearchBox.TextChanged -= ColumnShellPage_TextChanged;
841833
NavToolbarViewModel.SearchBox.SuggestionChosen -= ColumnShellPage_SuggestionChosen;

0 commit comments

Comments
 (0)