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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -89,7 +89,7 @@ static bool IsFolder(ListedItem item)

static bool IsImage(ListedItem item)
=> !string.IsNullOrEmpty(item.FileExtension)
&& ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant());
&& FileExtensionHelpers.IsImageFile(item.FileExtension.ToLowerInvariant());

static bool IsMedia(ListedItem item)
=> !string.IsNullOrEmpty(item.FileExtension)
Expand Down
16 changes: 8 additions & 8 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 @@ -284,55 +284,55 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
return new MediaPreview(model);
}

if (MarkdownPreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsMarkdownFile(ext))
{
var model = new MarkdownPreviewViewModel(item);
await model.LoadAsync();

return new MarkdownPreview(model);
}

if (ImagePreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsImageFile(ext))
{
var model = new ImagePreviewViewModel(item);
await model.LoadAsync();

return new ImagePreview(model);
}

if (TextPreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsTextFile(ext))
{
var model = new TextPreviewViewModel(item);
await model.LoadAsync();

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();

return new HtmlPreview(model);
}*/

if (RichTextPreviewViewModel.ContainsExtension(ext))
if (FileExtensionHelpers.IsRichTextFile(ext))
{
var model = new RichTextPreviewViewModel(item);
await model.LoadAsync();

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)
=> 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 All @@ -19,9 +19,6 @@ public MarkdownPreviewViewModel(ListedItem item)
{
}

public static bool ContainsExtension(string extension)
=> extension is ".md" or ".markdown";

public override async Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
var text = await ReadFileAsTextAsync(Item.ItemFile);
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 All @@ -12,9 +12,6 @@ public sealed partial class RichTextPreviewViewModel : BasePreviewModel

public RichTextPreviewViewModel(ListedItem item) : base(item) { }

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

public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
Stream = 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.UserControls.FilePreviews;
Expand All @@ -20,9 +20,6 @@ public TextPreviewViewModel(ListedItem item)
{
}

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

public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
var details = new List<FileProperty>();
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