Code Quality: Enforced usage of FileExtensionHelpers #18050
Code Quality: Enforced usage of FileExtensionHelpers #18050Lamparter wants to merge 7 commits intofiles-community:mainfrom
FileExtensionHelpers #18050Conversation
FileExtensionHelpers across the codebase
FileExtensionHelpers across the codebaseFileExtensionHelpers
|
Please fill out the PR template and the steps taken to test each file format and extension. |
There was a problem hiding this comment.
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 fromCodePreviewViewModel - Removes duplicate
ContainsExtensionmethods from all preview view models (TextPreviewViewModel, RichTextPreviewViewModel, PDFPreviewViewModel, MarkdownPreviewViewModel, ImagePreviewViewModel, HtmlPreviewViewModel, CodePreviewViewModel) - Updates call sites in
InfoPaneViewModelandAdaptiveLayoutHelpersto 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.
|
@yaira2 requesting your review |
|
Please fill out the PR template and the steps taken to test each file format and extension. |
| } | ||
|
|
||
| // TODO: Use existing helper mothods | ||
| public static bool ContainsExtension(string extension) |
There was a problem hiding this comment.
IsImageFile contains more extensions than this list. Did you check that all of the extensions work with the preview pane?
Resolved / Related Issues
FileExtensionHelpersto check file extensions across codebase #18049Steps used to test these changes
FileExtensionHelperisn't working correctlySee the images below where I've demonstrated this
Generic file
Code file
Markdown file (unsure whether this is the expected behaviour for the markdown preview, but this PR wouldn't affect that)
RTF file
Plaintext file