Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Peek] Add support for .ahk, .csv and .tsv previewing as plaintext files #35538

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

daverayment
Copy link
Contributor

Summary of the Pull Request

This replaces the previous #34824 PR. That PR's feature to allow the previewing of arbitrary plaintext files is not available here and is covered by a separate issue.

This change allows for the previewing of AutoHotKey .ahk script files, Comma-Separated Values .csv files and Tab-Separated Values .tsv files with the Monaco renderer in Peek (via the WebBrowserPreviewer).

PR Checklist

Detailed Description of the Pull Request / Additional comments

.ahk, .csv and .tsv file extensions have been added to the relevant Monaco settings files, in a similar manner to the addition of .srt files previously.

A small fix was made to MonacoHelper.cs by placing a using for the JsonDocument instantiation there, as it was not Disposed previously.

Code has been added to ensure any Shell preview handlers which could render these new file types are not overridden. (This was necessary because ShellPreviewHandlerPreviewer is later than WebBrowserPreviewer in the IsItemSupported() checks in PreviewerFactory.cs.) Most notably, if a user has Office installed then CSV files should still be previewed by Excel's previewer and not by the plaintext previewer here in Peek.

Validation Steps Performed

  • I used the current version of PowerToys to attempt to open .ahk, .csv and .tsv files on my machine, which does not have Microsoft Office installed (so no preview handler for .csv files). I confirmed that the contents were not rendered and the UnsupportedFilePreview was used to show summary information only.
  • I confirmed each of the file types could be opened as plaintext with the updated build.
  • I ran through my test folder, which contains a mix of image files, documents, text files and so on, confirming there were no issues created for other file types.

Please note: I don't own Microsoft Office / Office 365, so could not confirm that the Excel previewer handler for CSV files still works correctly with this update. Could this please be tested by one of the devs with that software installed? Many thanks.

@daverayment
Copy link
Contributor Author

I am currently looking into a bug with the exclusion code. Please hold off from reviewing for now. Thanks.

@daverayment
Copy link
Contributor Author

@htcfreek @crutkas

Could I request some help here, please?

When you add a file extension for previewing with Monaco by editing 'monacoSpecialLanguages.js' and 'monaco_languages.json', PowerToys will create a shellex entry in the Registry for that extension on startup:

image

(With {D8034CFA-F34B-41FE-AD45-62FCBB52A6DA} here referring to the Monaco Preview Handler.)

This is fine for file extensions which don't already have preview handlers defined. However, it looks like PowerToys will overwrite any existing entry present for that extension, too. I've been trying to study the code which registers the Monaco types in the registry (in 'modulesRegistry.h' and 'registry.h'), and I've done some testing to confirm the behaviour, but my C++ isn't very strong and I may be mistaken. In any case, I could use some advice.

If this behaviour is correct, we can't add .csv to Monaco's supported list, as it would overwrite the existing Office-installed Excel previewer handler if someone had that installed. Also, is it intended that PowerToys overwrites any predefined handlers for the other file extensions, too? Shouldn't there be code in getMonacoPreviewHandlerChangeSet to add extensions with existing handlers to the ExtExclusions list?

I'm sorry if this is intended behaviour or I'm misunderstanding, but it seemed suspicious and I wanted to be sure.

@htcfreek htcfreek added the Needs-Team-Response An issue author responded so the team needs to follow up label Oct 23, 2024
@daverayment
Copy link
Contributor Author

This issue seems to confirm that existing preview handler entries are being overwritten by PowerToys. Handlers installed by Office would be common examples, but there could be others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Team-Response An issue author responded so the team needs to follow up
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants