Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
<!-- Copyright (c) Files Community. Licensed under the MIT License. -->
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="ByteSize" Version="2.1.2" />
<PackageVersion Include="ColorCode.Core" Version="2.0.15" />
<PackageVersion Include="ColorCode.WinUI" Version="2.0.15" />
<PackageVersion Include="CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock" Version="0.1.250206-build.2040" />
<PackageVersion Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Previews;
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.UserControls.FilePreviews;
Expand Down Expand Up @@ -319,7 +319,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
return new MarkdownPreview(model);
}

if (ImagePreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsImageFile(ext))
{
var model = new ImagePreviewViewModel(item);
await model.LoadAsync();
Expand All @@ -335,15 +335,15 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
return new TextPreview(model);
}

/*if (PDFPreviewViewModel.ContainsExtension(ext))
/*if (FileExtensionHelpers.IsPdfFile(ext))
{
var model = new PDFPreviewViewModel(item);
await model.LoadAsync();

return new PDFPreview(model);
}*/

/*if (HtmlPreviewViewModel.ContainsExtension(ext))
/*if (FileExtensionHelpers.IsHtmlFile(ext))
{
var model = new HtmlPreviewViewModel(item);
await model.LoadAsync();
Expand All @@ -359,7 +359,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
return new RichTextPreview(model);
}

if (CodePreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsCodeFile(ext))
{
var model = new CodePreviewViewModel(item);
await model.LoadAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using ColorCode;
using Files.App.ViewModels.Properties;
using Files.Shared.Helpers;
using System.Collections.Frozen;

namespace Files.App.ViewModels.Previews
{
public sealed partial class CodePreviewViewModel : BasePreviewModel
{
private static readonly FrozenDictionary<string, ILanguage> extensions = GetDictionary();

private string textValue;
public string TextValue
{
Expand All @@ -30,9 +29,6 @@ public CodePreviewViewModel(ListedItem item)
{
}

public static bool ContainsExtension(string extension)
=> extensions.ContainsKey(extension);

public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
var details = new List<FileProperty>();
Expand All @@ -42,7 +38,7 @@ public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
var text = TextValue ?? await ReadFileAsTextAsync(Item.ItemFile);
details.Add(GetFileProperty("PropertyLineCount", text.Split('\n').Length));

CodeLanguage = extensions[Item.FileExtension.ToLowerInvariant()];
CodeLanguage = FileExtensionHelpers.CodeFileExtensions[Item.FileExtension.ToLowerInvariant()];
TextValue = text.Left(Constants.PreviewPane.TextCharacterLimit);
}
catch (Exception e)
Expand All @@ -52,40 +48,5 @@ public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()

return details;
}

private static FrozenDictionary<string, ILanguage> GetDictionary()
{
var items = new Dictionary<ILanguage, string>
{
[Languages.Aspx] = "aspx",
[Languages.AspxCs] = "acsx",
[Languages.Cpp] = "cpp,c++,cc,cp,cxx,h,h++,hh,hpp,hxx,inc,inl,ino,ipp,re,tcc,tpp",
[Languages.CSharp] = "cs,cake,csx,linq",
[Languages.Css] = "css,scss",
[Languages.FSharp] = "fs,fsi,fsx",
[Languages.Haskell] = "hs",
[Languages.Html] = "razor,cshtml,vbhtml,svelte",
[Languages.Java] = "java",
[Languages.JavaScript] = "js,jsx",
[Languages.Php] = "php",
[Languages.PowerShell] = "pwsh,ps1,psd1,psm1",
[Languages.Typescript] = "ts,tsx",
[Languages.VbDotNet] = "vb,vbs",
[Languages.Xml] = "xml,axml,xaml,xsd,xsl,xslt,xlf",
};

var dictionary = new Dictionary<string, ILanguage>();

foreach (var item in items)
{
var extensions = item.Value.Split(',').Select(ext => $".{ext}");
foreach (var extension in extensions)
{
dictionary.Add(extension, item.Key);
}
}

return dictionary.ToFrozenDictionary();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Properties;
Expand All @@ -12,9 +12,6 @@ public HtmlPreviewViewModel(ListedItem item)
{
}

public static bool ContainsExtension(string extension)
=> extension is ".htm" or ".html" or ".svg";

public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
=> [];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Properties;
Expand All @@ -23,10 +23,6 @@ public ImagePreviewViewModel(ListedItem item)
{
}

// TODO: Use existing helper mothods
public static bool ContainsExtension(string extension)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsImageFile contains more extensions than this list. Did you check that all of the extensions work with the preview pane?

Copy link
Copy Markdown
Contributor Author

@Lamparter Lamparter Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new file extension I added to that method is JFIF, which I can confirm works:
image

=> extension is ".png" or ".jpg" or ".jpeg" or ".bmp" or ".gif" or ".tiff" or ".ico" or ".webp" or ".jxr";

public override async Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
using IRandomAccessStream stream = await Item.ItemFile.OpenAsync(FileAccessMode.Read);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Properties;
Expand Down Expand Up @@ -34,9 +34,6 @@ public PDFPreviewViewModel(ListedItem item)
{
}

public static bool ContainsExtension(string extension)
=> extension is ".pdf";

public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
var fileStream = await Item.ItemFile.OpenReadAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.UserControls.FilePreviews;
Expand Down
1 change: 1 addition & 0 deletions src/Files.Shared/Files.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="System.IO.Hashing" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
<PackageReference Include="ColorCode.Core" />
</ItemGroup>

</Project>
Loading
Loading