Skip to content

Code Quality: Enforced usage of FileExtensionHelpers #18050

Open
Lamparter wants to merge 8 commits intofiles-community:mainfrom
Lamparter:mothods
Open

Code Quality: Enforced usage of FileExtensionHelpers #18050
Lamparter wants to merge 8 commits intofiles-community:mainfrom
Lamparter:mothods

Conversation

@Lamparter
Copy link
Contributor

@Lamparter Lamparter commented Jan 11, 2026

Resolved / Related Issues

Steps used to test these changes

  • Create a file with any one of the file extension types inside FileExtensionHelpers
  • See that the the file preview mode works correctly
    • Since the file preview pane is one of the heaviest users of the helper changed in this PR, it will fail to preview a file if the FileExtensionHelper isn't working correctly
    • If the file previews correctly, then one can know that the helper works

See the images below where I've demonstrated this


image

Generic file

image

Code file

image

Markdown file (unsure whether this is the expected behaviour for the markdown preview, but this PR wouldn't affect that)

image

RTF file

image

Plaintext file

Copilot AI review requested due to automatic review settings January 11, 2026 21:13
@Lamparter Lamparter changed the title Unify extension helpers Code Quality: Enforce usage of FileExtensionHelpers across the codebase Jan 11, 2026
@Lamparter Lamparter changed the title Code Quality: Enforce usage of FileExtensionHelpers across the codebase Code Quality: Enforced usage of FileExtensionHelpers Jan 11, 2026
@yair100
Copy link
Member

yair100 commented Jan 11, 2026

Please fill out the PR template and the steps taken to test each file format and extension.

Signed-off-by: Lamparter <71598437+Lamparter@users.noreply.github.com>
@yair100 yair100 added the changes requested Changes are needed for this pull request label Jan 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request unifies file extension checking by consolidating extension helper methods from individual preview view models into a central FileExtensionHelpers class, addressing issue #18049.

Changes:

  • Adds new helper methods to FileExtensionHelpers (IsCodeFile, IsPdfFile, IsHtmlFile, IsMarkdownFile, IsRichTextFile, IsTextFile) and migrates the code file extensions dictionary from CodePreviewViewModel
  • Removes duplicate ContainsExtension methods from all preview view models (TextPreviewViewModel, RichTextPreviewViewModel, PDFPreviewViewModel, MarkdownPreviewViewModel, ImagePreviewViewModel, HtmlPreviewViewModel, CodePreviewViewModel)
  • Updates call sites in InfoPaneViewModel and AdaptiveLayoutHelpers to use the centralized helpers

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 22 comments.

Show a summary per file
File Description
src/Files.Shared/Helpers/FileExtensionHelpers.cs Adds new helper methods and CodeFileExtensions dictionary; updates documentation from "Check" to "Checks"
src/Files.Shared/Files.Shared.csproj Adds ColorCode.Core package reference
src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs Removes ContainsExtension method and TODO comment
src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs Removes ContainsExtension method and GetDictionary; uses shared CodeFileExtensions
src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs Updates to use centralized FileExtensionHelpers methods
src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs Updates to use FileExtensionHelpers.IsImageFile
Directory.Packages.props Adds ColorCode.Core version 2.0.15

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Lamparter Lamparter requested a review from yair100 January 11, 2026 21:25
@Lamparter
Copy link
Contributor Author

@yaira2 requesting your review

@yair100
Copy link
Member

yair100 commented Jan 24, 2026

Please fill out the PR template and the steps taken to test each file format and extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes requested Changes are needed for this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Quality: Enforce usage of FileExtensionHelpers to check file extensions across codebase

2 participants

Comments