Skip to content

Commit 96143bb

Browse files
Fix: Fixed errors that occurred with shortcut items in git repositories (#17015)
1 parent b3aea84 commit 96143bb

File tree

16 files changed

+105
-28
lines changed

16 files changed

+105
-28
lines changed

src/Files.App/Actions/FileSystem/OpenFileLocationAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async Task ExecuteAsync(object? parameter = null)
3535
if (context.ShellPage?.ShellViewModel is null)
3636
return;
3737

38-
var item = context.SelectedItem as ShortcutItem;
38+
var item = context.SelectedItem as IShortcutItem;
3939

4040
if (string.IsNullOrWhiteSpace(item?.TargetPath))
4141
return;

src/Files.App/Actions/Navigation/OpenInNewTab/BaseOpenInNewTabAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
4242
{
4343
await NavigationHelpers.AddNewTabByPathAsync(
4444
typeof(ShellPanesPage),
45-
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath,
45+
(listedItem as IShortcutItem)?.TargetPath ?? listedItem.ItemPath,
4646
false);
4747
},
4848
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);

src/Files.App/Actions/Navigation/OpenInNewWindow/BaseOpenInNewWindowAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public virtual async Task ExecuteAsync(object? parameter = null)
4848

4949
foreach (ListedItem listedItem in items)
5050
{
51-
var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath;
51+
var selectedItemPath = (listedItem as IShortcutItem)?.TargetPath ?? listedItem.ItemPath;
5252
var folderUri = new Uri($"files-dev:?folder={@selectedItemPath}");
5353

5454
await Launcher.LaunchUriAsync(folderUri);

src/Files.App/Actions/Start/PinToStartAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ await SafetyExtensions.IgnoreExceptions(async () =>
3939
IStorable storable = listedItem.IsFolder switch
4040
{
4141
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
42-
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
42+
_ => await StorageService.GetFileAsync((listedItem as IShortcutItem)?.TargetPath ?? listedItem.ItemPath)
4343
};
4444
await StartMenuService.PinAsync(storable, listedItem.Name);
4545
});

src/Files.App/Actions/Start/UnpinFromStartAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ await SafetyExtensions.IgnoreExceptions(async () =>
3636
IStorable storable = listedItem.IsFolder switch
3737
{
3838
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
39-
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
39+
_ => await StorageService.GetFileAsync((listedItem as IShortcutItem)?.TargetPath ?? listedItem.ItemPath)
4040
};
4141
await StartMenuService.UnpinAsync(storable);
4242
});
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Files.App.ViewModels.Properties;
5+
using Microsoft.UI.Xaml.Media.Imaging;
6+
using Windows.Storage;
7+
8+
namespace Files.App.Utils
9+
{
10+
public interface IListedItem
11+
{
12+
GitItem AsGitItem { get; }
13+
RecycleBinItem AsRecycleBinItem { get; }
14+
bool ContainsFilesOrFolders { get; set; }
15+
string ContextualProperty { get; set; }
16+
BitmapImage CustomIcon { get; set; }
17+
Uri CustomIconSource { get; set; }
18+
ObservableCollection<FileProperty> FileDetails { get; set; }
19+
string FileExtension { get; set; }
20+
ulong? FileFRN { get; set; }
21+
BitmapImage FileImage { get; set; }
22+
string FileSize { get; set; }
23+
long FileSizeBytes { get; set; }
24+
string FileSizeDisplay { get; }
25+
string[] FileTags { get; set; }
26+
IList<TagViewModel>? FileTagsUI { get; }
27+
string FileVersion { get; set; }
28+
string FolderRelativeId { get; set; }
29+
bool HasTags { get; set; }
30+
BitmapImage IconOverlay { get; set; }
31+
string ImageDimensions { get; set; }
32+
bool IsAlternateStream { get; }
33+
bool IsArchive { get; }
34+
bool IsDriveRoot { get; }
35+
bool IsElevationRequired { get; set; }
36+
bool IsExecutable { get; }
37+
bool IsFolder { get; }
38+
bool IsFtpItem { get; }
39+
bool IsGitItem { get; }
40+
bool IsHiddenItem { get; set; }
41+
bool IsItemPinnedToStart { get; }
42+
bool IsLibrary { get; }
43+
bool IsLinkItem { get; }
44+
bool IsPinned { get; }
45+
bool IsRecycleBinItem { get; }
46+
bool IsScriptFile { get; }
47+
bool IsShortcut { get; }
48+
string ItemDateAccessed { get; }
49+
DateTimeOffset ItemDateAccessedReal { get; set; }
50+
string ItemDateCreated { get; }
51+
DateTimeOffset ItemDateCreatedReal { get; set; }
52+
string ItemDateModified { get; }
53+
DateTimeOffset ItemDateModifiedReal { get; set; }
54+
BaseStorageFile ItemFile { get; set; }
55+
string ItemNameRaw { get; set; }
56+
string ItemPath { get; set; }
57+
ObservableCollection<FileProperty> ItemProperties { get; set; }
58+
bool ItemPropertiesInitialized { get; set; }
59+
string ItemTooltipText { get; }
60+
string ItemType { get; set; }
61+
string Key { get; set; }
62+
bool LoadCustomIcon { get; set; }
63+
bool LoadFileIcon { get; set; }
64+
ByteSizeLib.ByteSize MaxSpace { get; set; }
65+
string MediaDuration { get; set; }
66+
string Name { get; }
67+
bool NeedsPlaceholderGlyph { get; set; }
68+
double Opacity { get; set; }
69+
StorageItemTypes PrimaryItemAttribute { get; set; }
70+
BitmapImage ShieldIcon { get; set; }
71+
bool ShowDriveStorageDetails { get; set; }
72+
ByteSizeLib.ByteSize SpaceUsed { get; set; }
73+
string SyncStatusString { get; }
74+
CloudDriveSyncStatusUI SyncStatusUI { get; set; }
75+
76+
string ToString();
77+
void UpdateContainsFilesFolders();
78+
}
79+
}

src/Files.App/Data/Items/ListedItem.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Files.App.Utils
1818
{
19-
public partial class ListedItem : ObservableObject, IGroupableItem
19+
public partial class ListedItem : ObservableObject, IGroupableItem, IListedItem
2020
{
2121
protected static IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2222

@@ -187,7 +187,7 @@ public BitmapImage FileImage
187187
}
188188
}
189189

190-
public bool IsItemPinnedToStart => StartMenuService.IsPinned((this as ShortcutItem)?.TargetPath ?? ItemPath);
190+
public bool IsItemPinnedToStart => StartMenuService.IsPinned((this as IShortcutItem)?.TargetPath ?? ItemPath);
191191

192192
private BitmapImage iconOverlay;
193193
public BitmapImage IconOverlay
@@ -352,7 +352,7 @@ public ByteSize SpaceUsed
352352
set => SetProperty(ref spaceUsed, value);
353353

354354
}
355-
355+
356356
private string imageDimensions;
357357
public string ImageDimensions
358358
{
@@ -427,7 +427,7 @@ public override string ToString()
427427
public bool IsRecycleBinItem => this is RecycleBinItem;
428428
public bool IsShortcut => this is IShortcutItem;
429429
public bool IsLibrary => this is LibraryItem;
430-
public bool IsLinkItem => IsShortcut && ((ShortcutItem)this).IsUrl;
430+
public bool IsLinkItem => IsShortcut && ((IShortcutItem)this).IsUrl;
431431
public bool IsFtpItem => this is FtpItem;
432432
public bool IsArchive => this is ZipItem;
433433
public bool IsAlternateStream => this is AlternateStreamItem;
@@ -788,7 +788,7 @@ public override string Name
788788
public bool IsSymLink { get; set; }
789789
public override bool IsExecutable => FileExtensionHelpers.IsExecutableFile(TargetPath, true);
790790
}
791-
public interface IGitItem
791+
public interface IGitItem : IListedItem
792792
{
793793
public bool StatusPropertiesInitialized { get; set; }
794794
public bool CommitPropertiesInitialized { get; set; }
@@ -815,7 +815,7 @@ public string ItemPath
815815
set;
816816
}
817817
}
818-
public interface IShortcutItem
818+
public interface IShortcutItem : IListedItem
819819
{
820820
public string TargetPath { get; set; }
821821
public string Name { get; }

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem
330330
if (associatedInstance is null || listedItem is null)
331331
return;
332332

333-
associatedInstance.PaneHolder?.OpenSecondaryPane((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
333+
associatedInstance.PaneHolder?.OpenSecondaryPane((listedItem as IShortcutItem)?.TargetPath ?? listedItem.ItemPath);
334334
}
335335

336336
public static Task LaunchNewWindowAsync()

src/Files.App/Helpers/ShareItemHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async void Manager_DataRequested(DataTransferManager sender, DataRequestedEventA
5959

6060
foreach (ListedItem item in itemsToShare)
6161
{
62-
if (item is ShortcutItem shItem)
62+
if (item is IShortcutItem shItem)
6363
{
6464
if (shItem.IsLinkItem && !string.IsNullOrEmpty(shItem.TargetPath))
6565
{

src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private async Task ItemPointerPressedAsync(PointerRoutedEventArgs e)
6565
_associatedInstance.SlimContentPage.IsMiddleClickToScrollEnabled = true;
6666

6767
if (Item.IsShortcut)
68-
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as ShortcutItem)?.TargetPath ?? Item.ItemPath);
68+
await NavigationHelpers.OpenPathInNewTab(((e.OriginalSource as FrameworkElement)?.DataContext as IShortcutItem)?.TargetPath ?? Item.ItemPath);
6969
else
7070
await NavigationHelpers.OpenPathInNewTab(Item.ItemPath);
7171
}

src/Files.App/ViewModels/Properties/Items/FileProperties.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public override void GetBaseProperties()
5252
if (!Item.IsShortcut)
5353
return;
5454

55-
var shortcutItem = (ShortcutItem)Item;
55+
var shortcutItem = (IShortcutItem)Item;
5656

5757
var isApplication =
5858
FileExtensionHelpers.IsExecutableFile(shortcutItem.TargetPath) ||
@@ -78,7 +78,6 @@ public override void GetBaseProperties()
7878
{
7979
if (Item.IsLinkItem)
8080
{
81-
var tmpItem = (ShortcutItem)Item;
8281
await Win32Helper.InvokeWin32ComponentAsync(ViewModel.ShortcutItemPath, AppInstance, ViewModel.ShortcutItemArguments, ViewModel.RunAsAdmin, ViewModel.ShortcutItemWorkingDir);
8382
}
8483
else
@@ -125,14 +124,14 @@ public override async Task GetSpecialPropertiesAsync()
125124
{
126125
ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
127126
ViewModel.ItemAccessedTimestampReal = Item.ItemDateAccessedReal;
128-
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath))
127+
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((IShortcutItem)Item).TargetPath))
129128
{
130129
// Can't show any other property
131130
return;
132131
}
133132
}
134133

135-
string filePath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
134+
string filePath = (Item as IShortcutItem)?.TargetPath ?? Item.ItemPath;
136135
BaseStorageFile file = await AppInstance.ShellViewModel.GetFileFromPathAsync(filePath);
137136

138137
// Couldn't access the file and can't load any other properties

src/Files.App/ViewModels/Properties/Items/FolderProperties.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ public override void GetBaseProperties()
4848
ViewModel.LoadFileIcon = Item.LoadFileIcon;
4949
ViewModel.ContainsFilesOrFolders = Item.ContainsFilesOrFolders;
5050

51-
if (Item.IsShortcut)
51+
if (Item.IsShortcut && Item is IShortcutItem shortcutItem)
5252
{
53-
var shortcutItem = (ShortcutItem)Item;
5453
ViewModel.ShortcutItemType = Strings.Folder.GetLocalizedResource();
5554
ViewModel.ShortcutItemPath = shortcutItem.TargetPath;
5655
ViewModel.IsShortcutItemPathReadOnly = false;
@@ -104,14 +103,14 @@ public async override Task GetSpecialPropertiesAsync()
104103

105104
ViewModel.ItemCreatedTimestampReal = Item.ItemDateCreatedReal;
106105
ViewModel.ItemAccessedTimestampReal = Item.ItemDateAccessedReal;
107-
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath))
106+
if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((IShortcutItem)Item).TargetPath))
108107
{
109108
// Can't show any other property
110109
return;
111110
}
112111
}
113112

114-
string folderPath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
113+
string folderPath = (Item as IShortcutItem)?.TargetPath ?? Item.ItemPath;
115114
BaseStorageFolder storageFolder = await AppInstance.ShellViewModel.GetFolderFromPathAsync(folderPath);
116115

117116
if (storageFolder is not null)
@@ -222,12 +221,12 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
222221
case nameof(ViewModel.ShortcutItemWorkingDir):
223222
case nameof(ViewModel.ShowWindowCommand):
224223
case nameof(ViewModel.ShortcutItemArguments):
225-
var tmpItem = (ShortcutItem)Item;
224+
var shortcutItem = (IShortcutItem)Item;
226225

227226
if (string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath))
228227
return;
229228

230-
await FileOperationsHelpers.CreateOrUpdateLinkAsync(Item.ItemPath, ViewModel.ShortcutItemPath, ViewModel.ShortcutItemArguments, ViewModel.ShortcutItemWorkingDir, tmpItem.RunAsAdmin, ViewModel.ShowWindowCommand);
229+
await FileOperationsHelpers.CreateOrUpdateLinkAsync(Item.ItemPath, ViewModel.ShortcutItemPath, ViewModel.ShortcutItemArguments, ViewModel.ShortcutItemWorkingDir, shortcutItem.RunAsAdmin, ViewModel.ShowWindowCommand);
231230
break;
232231
}
233232
}

src/Files.App/ViewModels/ShellViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ private bool CheckElevationRights(ListedItem item)
13571357
if (item.SyncStatusUI.LoadSyncStatus)
13581358
return false;
13591359

1360-
return WindowsSecurityService.IsElevationRequired(item.IsShortcut ? ((ShortcutItem)item).TargetPath : item.ItemPath);
1360+
return WindowsSecurityService.IsElevationRequired(item.IsShortcut ? ((IShortcutItem)item).TargetPath : item.ItemPath);
13611361
}
13621362

13631363
public async Task LoadGitPropertiesAsync(IGitItem gitItem)

src/Files.App/ViewModels/UserControls/Previews/ShortcutPreviewViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public ShortcutPreviewViewModel(ListedItem item) : base(item) { }
1111

1212
public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
1313
{
14-
var item = Item as ShortcutItem;
14+
var item = Item as IShortcutItem;
1515
var details = new List<FileProperty>
1616
{
1717
GetFileProperty("PropertyParsingPath", item.ItemPath),

src/Files.App/Views/Layouts/BaseLayoutPage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ protected virtual async void Item_Drop(object sender, DragEventArgs e)
11741174

11751175
var item = GetItemFromElement(sender);
11761176
if (item is not null)
1177-
await ParentShellPageInstance!.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (item as ShortcutItem)?.TargetPath ?? item.ItemPath, false, true, item.IsExecutable, item.IsScriptFile);
1177+
await ParentShellPageInstance!.FilesystemHelpers.PerformOperationTypeAsync(e.AcceptedOperation, e.DataView, (item as IShortcutItem)?.TargetPath ?? item.ItemPath, false, true, item.IsExecutable, item.IsScriptFile);
11781178
}
11791179
finally
11801180
{

src/Files.App/Views/Properties/ShortcutPage.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override async Task<bool> SaveChangesAsync()
1919
FileProperties properties => properties.Item,
2020
FolderProperties properties => properties.Item,
2121
_ => null
22-
} as ShortcutItem;
22+
} as IShortcutItem;
2323

2424
if (shortcutItem is null)
2525
return true;

0 commit comments

Comments
 (0)