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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
});
Lines changed: 79 additions & 0 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)