Skip to content

Commit 3d0d1df

Browse files
committed
Created an Interface IGitItem and derived class from it.
1 parent 45aa133 commit 3d0d1df

File tree

7 files changed

+168
-19
lines changed

7 files changed

+168
-19
lines changed

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

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ public override string ToString()
405405

406406
public bool IsFolder => PrimaryItemAttribute is StorageItemTypes.Folder;
407407
public bool IsRecycleBinItem => this is RecycleBinItem;
408-
public bool IsShortcut => this is ShortcutItem;
408+
public bool IsShortcut => this is IShortcutItem;
409409
public bool IsLibrary => this is LibraryItem;
410-
public bool IsLinkItem => IsShortcut && ((ShortcutItem)this).IsUrl;
410+
public bool IsLinkItem => IsShortcut && ((IShortcutItem)this).IsUrl;
411411
public bool IsFtpItem => this is FtpItem;
412412
public bool IsArchive => this is ZipItem;
413413
public bool IsAlternateStream => this is AlternateStreamItem;
414-
public bool IsGitItem => this is GitItem;
414+
public bool IsGitItem => this is IGitItem;
415415
public virtual bool IsExecutable => !IsFolder && FileExtensionHelpers.IsExecutableFile(ItemPath);
416416
public virtual bool IsScriptFile => FileExtensionHelpers.IsScriptFile(ItemPath);
417417
public bool IsPinned => App.QuickAccessManager.Model.PinnedFolders.Contains(itemPath);
@@ -428,7 +428,7 @@ public BaseStorageFile ItemFile
428428
// This is a hack used because x:Bind casting did not work properly
429429
public RecycleBinItem AsRecycleBinItem => this as RecycleBinItem;
430430

431-
public GitItem AsGitItem => this as GitItem;
431+
public IGitItem AsGitItem => this as IGitItem;
432432

433433
public string Key { get; set; }
434434

@@ -507,7 +507,7 @@ public FtpItem(FtpListItem item, string folder) : base(null)
507507
};
508508
}
509509

510-
public sealed class ShortcutItem : ListedItem
510+
public sealed class ShortcutItem : ListedItem, IShortcutItem
511511
{
512512
public ShortcutItem(string folderRelativeId) : base(folderRelativeId)
513513
{
@@ -602,7 +602,7 @@ public override string Name
602602
}
603603
}
604604

605-
public sealed class GitItem : ListedItem
605+
public sealed class GitItem : ListedItem, IGitItem
606606
{
607607
private volatile int statusPropertiesInitialized = 0;
608608
public bool StatusPropertiesInitialized
@@ -678,4 +678,129 @@ public string? GitLastCommitFullSha
678678
set => SetProperty(ref _GitLastCommitFullSha, value);
679679
}
680680
}
681+
public sealed class GitShortcutItem : ListedItem, IGitItem,IShortcutItem
682+
{
683+
private volatile int statusPropertiesInitialized = 0;
684+
public bool StatusPropertiesInitialized
685+
{
686+
get => statusPropertiesInitialized == 1;
687+
set => Interlocked.Exchange(ref statusPropertiesInitialized, value ? 1 : 0);
688+
}
689+
690+
private volatile int commitPropertiesInitialized = 0;
691+
public bool CommitPropertiesInitialized
692+
{
693+
get => commitPropertiesInitialized == 1;
694+
set => Interlocked.Exchange(ref commitPropertiesInitialized, value ? 1 : 0);
695+
}
696+
697+
private Style? _UnmergedGitStatusIcon;
698+
public Style? UnmergedGitStatusIcon
699+
{
700+
get => _UnmergedGitStatusIcon;
701+
set => SetProperty(ref _UnmergedGitStatusIcon, value);
702+
}
703+
704+
private string? _UnmergedGitStatusName;
705+
public string? UnmergedGitStatusName
706+
{
707+
get => _UnmergedGitStatusName;
708+
set => SetProperty(ref _UnmergedGitStatusName, value);
709+
}
710+
711+
private DateTimeOffset? _GitLastCommitDate;
712+
public DateTimeOffset? GitLastCommitDate
713+
{
714+
get => _GitLastCommitDate;
715+
set
716+
{
717+
SetProperty(ref _GitLastCommitDate, value);
718+
GitLastCommitDateHumanized = value is DateTimeOffset dto ? dateTimeFormatter.ToShortLabel(dto) : "";
719+
}
720+
}
721+
722+
private string? _GitLastCommitDateHumanized;
723+
public string? GitLastCommitDateHumanized
724+
{
725+
get => _GitLastCommitDateHumanized;
726+
set => SetProperty(ref _GitLastCommitDateHumanized, value);
727+
}
728+
729+
private string? _GitLastCommitMessage;
730+
public string? GitLastCommitMessage
731+
{
732+
get => _GitLastCommitMessage;
733+
set => SetProperty(ref _GitLastCommitMessage, value);
734+
}
735+
736+
private string? _GitCommitAuthor;
737+
public string? GitLastCommitAuthor
738+
{
739+
get => _GitCommitAuthor;
740+
set => SetProperty(ref _GitCommitAuthor, value);
741+
}
742+
743+
private string? _GitLastCommitSha;
744+
public string? GitLastCommitSha
745+
{
746+
get => _GitLastCommitSha;
747+
set => SetProperty(ref _GitLastCommitSha, value);
748+
}
749+
750+
private string? _GitLastCommitFullSha;
751+
public string? GitLastCommitFullSha
752+
{
753+
get => _GitLastCommitFullSha;
754+
set => SetProperty(ref _GitLastCommitFullSha, value);
755+
}
756+
757+
public string TargetPath { get; set; }
758+
759+
public override string Name
760+
=> IsSymLink ? base.Name : Path.GetFileNameWithoutExtension(ItemNameRaw); // Always hide extension for shortcuts
761+
762+
public string Arguments { get; set; }
763+
public string WorkingDirectory { get; set; }
764+
public bool RunAsAdmin { get; set; }
765+
public bool IsUrl { get; set; }
766+
public bool IsSymLink { get; set; }
767+
public override bool IsExecutable => FileExtensionHelpers.IsExecutableFile(TargetPath, true);
768+
}
769+
public interface IGitItem
770+
{
771+
public bool StatusPropertiesInitialized { get ; set; }
772+
public bool CommitPropertiesInitialized { get; set; }
773+
774+
public Style? UnmergedGitStatusIcon{ get; set; }
775+
776+
public string? UnmergedGitStatusName{ get; set; }
777+
778+
public DateTimeOffset? GitLastCommitDate{ get; set; }
779+
780+
public string? GitLastCommitDateHumanized{ get; set; }
781+
782+
public string? GitLastCommitMessage{ get; set; }
783+
784+
public string? GitLastCommitAuthor{ get; set; }
785+
786+
public string? GitLastCommitSha{ get; set; }
787+
788+
public string? GitLastCommitFullSha{ get; set; }
789+
790+
public string ItemPath
791+
{
792+
get;
793+
set;
794+
}
795+
}
796+
public interface IShortcutItem
797+
{
798+
public string TargetPath { get; set; }
799+
public string Arguments { get; set; }
800+
public string WorkingDirectory { get; set; }
801+
public bool RunAsAdmin { get; set; }
802+
public bool IsUrl { get; set; }
803+
public bool IsSymLink { get; set; }
804+
805+
}
681806
}

src/Files.App/Utils/Storage/Enumerators/Win32StorageEnumerator.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ CancellationToken cancellationToken
272272
bool isReparsePoint = ((FileAttributes)findData.dwFileAttributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
273273
bool isSymlink = isReparsePoint && findData.dwReserved0 == Win32PInvoke.IO_REPARSE_TAG_SYMLINK;
274274

275-
if (isSymlink)
275+
if (isSymlink && !isGitRepo)
276276
{
277277
var targetPath = Win32Helper.ParseSymLink(itemPath);
278278

@@ -296,6 +296,30 @@ CancellationToken cancellationToken
296296
IsSymLink = true
297297
};
298298
}
299+
else if (isSymlink && isGitRepo)
300+
{
301+
var targetPath = Win32Helper.ParseSymLink(itemPath);
302+
303+
return new GitShortcutItem()
304+
{
305+
PrimaryItemAttribute = StorageItemTypes.File,
306+
FileExtension = itemFileExtension,
307+
IsHiddenItem = isHidden,
308+
Opacity = opacity,
309+
FileImage = null,
310+
LoadFileIcon = itemThumbnailImgVis,
311+
ItemNameRaw = itemName,
312+
ItemDateModifiedReal = itemModifiedDate,
313+
ItemDateAccessedReal = itemLastAccessDate,
314+
ItemDateCreatedReal = itemCreatedDate,
315+
ItemType = "Shortcut".GetLocalizedResource(),
316+
ItemPath = itemPath,
317+
FileSize = itemSize,
318+
FileSizeBytes = itemSizeBytes,
319+
TargetPath = targetPath,
320+
IsSymLink = true,
321+
};
322+
}
299323
else if (FileExtensionHelpers.IsShortcutOrUrlFile(findData.cFileName))
300324
{
301325
var isUrl = FileExtensionHelpers.IsWebLinkFile(findData.cFileName);

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public GitProperties EnabledGitProperties
122122
{
123123
filesAndFolders.ToList().ForEach(async item =>
124124
{
125-
if (item is GitItem gitItem &&
125+
if (item is IGitItem gitItem &&
126126
(!gitItem.StatusPropertiesInitialized && value is GitProperties.All or GitProperties.Status
127127
|| !gitItem.CommitPropertiesInitialized && value is GitProperties.All or GitProperties.Commit))
128128
{
@@ -1273,7 +1273,7 @@ private bool CheckElevationRights(ListedItem item)
12731273
return WindowsSecurityService.IsElevationRequired(item.IsShortcut ? ((ShortcutItem)item).TargetPath : item.ItemPath);
12741274
}
12751275

1276-
public async Task LoadGitPropertiesAsync(GitItem gitItem)
1276+
public async Task LoadGitPropertiesAsync(IGitItem gitItem)
12771277
{
12781278
var getStatus = EnabledGitProperties is GitProperties.All or GitProperties.Status && !gitItem.StatusPropertiesInitialized;
12791279
var getCommit = EnabledGitProperties is GitProperties.All or GitProperties.Commit && !gitItem.CommitPropertiesInitialized;
@@ -2585,7 +2585,7 @@ public void UpdateDateDisplay(bool isFormatChange)
25852585
await dispatcherQueue.EnqueueOrInvokeAsync(() => item.ItemDateModifiedReal = item.ItemDateModifiedReal);
25862586
if (item is RecycleBinItem recycleBinItem && (isFormatChange || IsDateDiff(recycleBinItem.ItemDateDeletedReal)))
25872587
await dispatcherQueue.EnqueueOrInvokeAsync(() => recycleBinItem.ItemDateDeletedReal = recycleBinItem.ItemDateDeletedReal);
2588-
if (item is GitItem gitItem && gitItem.GitLastCommitDate is DateTimeOffset offset && (isFormatChange || IsDateDiff(offset)))
2588+
if (item is IGitItem gitItem && gitItem.GitLastCommitDate is DateTimeOffset offset && (isFormatChange || IsDateDiff(offset)))
25892589
await dispatcherQueue.EnqueueOrInvokeAsync(() => gitItem.GitLastCommitDate = gitItem.GitLastCommitDate);
25902590
});
25912591
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected virtual async Task ReloadSelectedItemIconAsync()
138138
await ParentShellPageInstance.ShellViewModel.LoadExtendedItemPropertiesAsync(ParentShellPageInstance.SlimContentPage.SelectedItem);
139139

140140
if (ParentShellPageInstance.ShellViewModel.EnabledGitProperties is not GitProperties.None &&
141-
ParentShellPageInstance.SlimContentPage.SelectedItem is GitItem gitItem)
141+
ParentShellPageInstance.SlimContentPage.SelectedItem is IGitItem gitItem)
142142
{
143143
await ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
144144
}
@@ -161,7 +161,7 @@ protected virtual async Task ReloadSelectedItemsIconAsync()
161161
{
162162
await Task.WhenAll(ParentShellPageInstance.SlimContentPage.SelectedItems.Select(item =>
163163
{
164-
if (item is GitItem gitItem)
164+
if (item is IGitItem gitItem)
165165
return ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
166166

167167
return Task.CompletedTask;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
12081208
args.RegisterUpdateCallback(callbackPhase, async (s, c) =>
12091209
{
12101210
await ParentShellPageInstance!.ShellViewModel.LoadExtendedItemPropertiesAsync(listedItem);
1211-
if (ParentShellPageInstance.ShellViewModel.EnabledGitProperties is not GitProperties.None && listedItem is GitItem gitItem)
1211+
if (ParentShellPageInstance.ShellViewModel.EnabledGitProperties is not GitProperties.None && listedItem is IGitItem gitItem)
12121212
await ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
12131213
});
12141214
}

src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ await Task.WhenAll(filesAndFolders.Select(listedItem =>
509509
{
510510
await Task.WhenAll(filesAndFolders.Select(item =>
511511
{
512-
if (item is GitItem gitItem)
512+
if (item is IGitItem gitItem)
513513
return ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
514514

515515
return Task.CompletedTask;
@@ -696,10 +696,10 @@ private void ResizeColumnToFit(int columnToResize)
696696
{
697697
1 => 40, // Check all items columns
698698
2 => FileList.Items.Cast<ListedItem>().Select(x => x.Name?.Length ?? 0).Max(), // file name column
699-
4 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitDateHumanized?.Length ?? 0).Max(), // git
700-
5 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitMessage?.Length ?? 0).Max(), // git
701-
6 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitAuthor?.Length ?? 0).Max(), // git
702-
7 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitSha?.Length ?? 0).Max(), // git
699+
4 => FileList.Items.Cast<ListedItem>().Select(x => (x as IGitItem)?.GitLastCommitDateHumanized?.Length ?? 0).Max(), // git
700+
5 => FileList.Items.Cast<ListedItem>().Select(x => (x as IGitItem)?.GitLastCommitMessage?.Length ?? 0).Max(), // git
701+
6 => FileList.Items.Cast<ListedItem>().Select(x => (x as IGitItem)?.GitLastCommitAuthor?.Length ?? 0).Max(), // git
702+
7 => FileList.Items.Cast<ListedItem>().Select(x => (x as IGitItem)?.GitLastCommitSha?.Length ?? 0).Max(), // git
703703
8 => FileList.Items.Cast<ListedItem>().Select(x => x.FileTagsUI?.Sum(x => x?.Name?.Length ?? 0) ?? 0).Max(), // file tag column
704704
9 => FileList.Items.Cast<ListedItem>().Select(x => x.ItemPath?.Length ?? 0).Max(), // path column
705705
10 => FileList.Items.Cast<ListedItem>().Select(x => (x as RecycleBinItem)?.ItemOriginalPath?.Length ?? 0).Max(), // original path column

src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ private async Task ReloadItemIconsAsync()
519519
{
520520
await Task.WhenAll(filesAndFolders.Select(item =>
521521
{
522-
if (item is GitItem gitItem)
522+
if (item is IGitItem gitItem)
523523
return ParentShellPageInstance.ShellViewModel.LoadGitPropertiesAsync(gitItem);
524524

525525
return Task.CompletedTask;

0 commit comments

Comments
 (0)