Skip to content

Commit ea89bc3

Browse files
committed
Context
1 parent 27a8378 commit ea89bc3

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,22 +365,6 @@ public string DimensionsDisplay
365365
}
366366
}
367367

368-
/// <summary>
369-
/// Contextual property that changes based on the item type
370-
/// </summary>
371-
public string ContextualPropertyString => FileExtension switch
372-
{
373-
// Image files are on hold until DimensionsDisplay switches to 'System.Kind', otherwise it causes OneDrive files to be downloaded.
374-
// Images
375-
//_ when FileExtensionHelpers.IsImageFile(FileExtension) => !string.IsNullOrEmpty(DimensionsDisplay)
376-
// ? $"{Strings.PropertyDimensions.GetLocalizedResource()}: {DimensionsDisplay}"
377-
// : string.Empty,
378-
379-
// Other file formats
380-
_ => !string.IsNullOrEmpty(ItemDateModified)
381-
? $"{Strings.Modified.GetLocalizedResource()}: {ItemDateModified}"
382-
: string.Empty
383-
};
384368

385369
/// <summary>
386370
/// Initializes a new instance of the <see cref="ListedItem" /> class.
@@ -443,6 +427,17 @@ public BaseStorageFile ItemFile
443427
set => SetProperty(ref itemFile, value);
444428
}
445429

430+
431+
private string contextualProperty;
432+
/// <summary>
433+
/// Contextual property that changes based on the item type.
434+
/// </summary>
435+
public string ContextualProperty
436+
{
437+
get => contextualProperty;
438+
set => SetProperty(ref contextualProperty, value);
439+
}
440+
446441
// This is a hack used because x:Bind casting did not work properly
447442
public RecycleBinItem AsRecycleBinItem => this as RecycleBinItem;
448443

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ public async Task LoadExtendedItemPropertiesAsync(ListedItem item)
11411141
var fileFRN = await FileTagsHelper.GetFileFRN(matchingStorageFile);
11421142
var fileTag = FileTagsHelper.ReadFileTag(item.ItemPath);
11431143
var itemType = (item.ItemType == "Folder".GetLocalizedResource()) ? item.ItemType : matchingStorageFile.DisplayType;
1144+
var contextualProperty = await GetContextualPropertyString(matchingStorageFile, item);
11441145

11451146
cts.Token.ThrowIfCancellationRequested();
11461147

@@ -1152,6 +1153,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11521153
item.FileFRN = fileFRN;
11531154
item.FileTags = fileTag;
11541155
item.IsElevationRequired = CheckElevationRights(item);
1156+
item.ContextualProperty = contextualProperty;
11551157
},
11561158
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
11571159

@@ -1187,6 +1189,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11871189
var fileFRN = await FileTagsHelper.GetFileFRN(matchingStorageFolder);
11881190
var fileTag = FileTagsHelper.ReadFileTag(item.ItemPath);
11891191
var itemType = (item.ItemType == "Folder".GetLocalizedResource()) ? item.ItemType : matchingStorageFolder.DisplayType;
1192+
var contextualProperty = await GetContextualPropertyString(matchingStorageFile, item);
1193+
11901194
cts.Token.ThrowIfCancellationRequested();
11911195

11921196
await dispatcherQueue.EnqueueOrInvokeAsync(() =>
@@ -1196,6 +1200,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11961200
item.SyncStatusUI = CloudDriveSyncStatusUI.FromCloudDriveSyncStatus(syncStatus);
11971201
item.FileFRN = fileFRN;
11981202
item.FileTags = fileTag;
1203+
item.ContextualProperty = contextualProperty;
11991204
},
12001205
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
12011206

@@ -1908,6 +1913,43 @@ public async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageI
19081913
return (CloudDriveSyncStatus)syncStatus;
19091914
}
19101915

1916+
private async Task<string> GetContextualPropertyString(IStorageItem matchingStorageItem, ListedItem listedItem)
1917+
{
1918+
var contextualProperty = string.Empty;
1919+
1920+
if (matchingStorageItem is BaseStorageFile file && file.Properties != null)
1921+
{
1922+
if (FileExtensionHelpers.IsImageFile(listedItem.FileExtension))
1923+
{
1924+
var properties = await FilesystemTasks.Wrap(() => file.Properties.RetrievePropertiesAsync(["System.Image.Dimensions"]).AsTask());
1925+
var value = properties.Result["System.Image.Dimensions"]?.ToString();
1926+
1927+
if (!string.IsNullOrEmpty(value))
1928+
contextualProperty = $"{Strings.PropertyDimensions.GetLocalizedResource()}: {value}";
1929+
}
1930+
else if (FileExtensionHelpers.IsAudioFile(listedItem.FileExtension) || FileExtensionHelpers.IsVideoFile(listedItem.FileExtension))
1931+
{
1932+
var properties = await FilesystemTasks.Wrap(() => file.Properties.RetrievePropertiesAsync(["System.Media.Duration"]).AsTask());
1933+
var value = TimeSpan.FromTicks((long)(ulong)properties.Result["System.Media.Duration"]).ToString(@"hh\:mm\:ss");
1934+
1935+
if (!string.IsNullOrEmpty(value))
1936+
contextualProperty = $"{Strings.PropertyDuration.GetLocalizedResource()}: {value}";
1937+
}
1938+
else if (FileExtensionHelpers.IsExecutableFile(listedItem.FileExtension, true))
1939+
{
1940+
var properties = await FilesystemTasks.Wrap(() => file.Properties.RetrievePropertiesAsync(["System.FileVersion"]).AsTask());
1941+
var value = properties.Result["System.FileVersion"]?.ToString();
1942+
1943+
if (!string.IsNullOrEmpty(value))
1944+
contextualProperty = $"{Strings.PropertyVersion.GetLocalizedResource()}: {value}";
1945+
}
1946+
}
1947+
1948+
return !string.IsNullOrEmpty(contextualProperty)
1949+
? contextualProperty
1950+
: $"{Strings.Modified.GetLocalizedResource()}: {listedItem.ItemDateModified}";
1951+
}
1952+
19111953
private async Task WatchForStorageFolderChangesAsync(BaseStorageFolder? rootFolder)
19121954
{
19131955
if (rootFolder is null)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
<TextBlock
608608
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
609609
Style="{ThemeResource CaptionTextBlockStyle}"
610-
Text="{x:Bind ContextualPropertyString, Mode=OneWay}"
610+
Text="{x:Bind ContextualProperty, Mode=OneWay}"
611611
TextTrimming="CharacterEllipsis"
612612
TextWrapping="NoWrap"
613613
Visibility="{Binding ElementName=PageRoot, Path=CardsViewShowContextualProperty, Mode=OneWay}" />

0 commit comments

Comments
 (0)