PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

New+ Support for variables in template filenames (35287)

Open cgaarden opened this issue 11 months ago • 13 comments

Summary of the Pull Request

Added support for variables in template filenames

Variables supported includes

  1. Date and time component variables, such as $YYYY, $YY, $MM, $DD, - using the same syntax and implementation as in PowerRename
  2. $PARENT_FOLDER_NAME - will replace variable with the name of the parent folder
  3. %environment-variable% - will replace variable with the value of the corresponding environment variable

Example: Template filename: $YYYY-$MM-%DD, $hh - $PARENT_FOLDER_NAME by %USERNAME%

Filename on create becomes: 2025-01-25, 02 - PowerShell project by cgaarden

PR Checklist

  • [x] Closes: #35287
  • [x] Also closes:
  • [x] **35287
  • [x] **35984
  • [x] **36615
  • [x] **36425
  • [x] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [n/a] Tests: Added/updated and all pass
  • [x] Localization: All end user facing strings can be localized
  • [n/a] Dev docs: Added/updated
  • [n/a] New binaries: Added on the required places
  • [x] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #5285 https://github.com/MicrosoftDocs/windows-dev-docs/pull/5285

Detailed Description of the Pull Request / Additional comments

SHFileOperation API related

Still using SHFileOperation API - may change this in a future PR as the current implementation requires iterating through files multiple times (not really that impactful unless a template folder contains 100s+ of files/subfolders Fixed an issue on ARM64 when depending on SHFileOperation to provide filename remapping

Minor refactoring

To help with support the variable support

Minor exception handling logic

To help get information on where New+ menu isn't being displayed

Validation Steps Performed

  1. Windows 10 clean install, with lots of different template permutations
  2. Windows 11 clean and update install, with lots of different template permutations
  3. Windows 11 ARM64 and x64, with lots of different template permutations
  4. Template folders with subitems with multiple variables within filenames
  5. Template items starting with digits and spaces, e.g. 13. $YYYY-$MM-$DD PTA meeting minutes and actions
  6. Rename mode is entered as expected for files and folder based templates, also when creating template with same name multiple times (x) in Arabic script
  7. Validated that GPO ConfigureEnabledUtilityNewPlus, NewPlusHideTemplateFilenameExtension, NewPlusReplaceVariablesInTemplateFilenames are working as intended

Example template folder + corresponding context menu

image

Example of project including subitems

image

New+ settings

(debug) image

New+ related GPO policies

image

cgaarden avatar Jan 25 '25 22:01 cgaarden

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.

Unrecognized words (1)

Examaples

These words are not needed and should be removed AMPROPERTY AMPROPSETID Breadcrumb CDEF comdef ddf devenum DEVMON DEVSOURCE DGR DIIRFLAG dshow DVH DVHD DVSD DVSL EData ERole fdw FILEINFOSIG Filtergraph Filterx HCERTSTORE IKs iljxck IYUV KSPROPERTY lcb ldx lld LONGLONG LTRB majortype makecab MEDIASUBTYPE mediatype mfplat mic mjpg Msimg msiquery ORAW outpin overlaywindow PAUDIO PINDIR Pnp ppmt previouscamera PROPBAG propvarutil reencode reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr shmem SHNAMEMAPPING sizeread stl strsafe strutil subquery SYNCMFT TMPVAR vcdl vdi vid VIDCAP VIDEOINFOHEADER vih WANTMAPPINGHANDLE webcam wistd WVC

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:cgaarden/PowerToys.git repository on the New+feature-35287-support-for-variables-in-templates branch (:information_source: how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/12969083641/attempts/1'

If the flagged items are :exploding_head: false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar Jan 25 '25 22:01 github-actions[bot]

Has conflicts

crutkas avatar Feb 14 '25 03:02 crutkas

Has conflicts

Recent conflicts with GPO settings are now resolved again

cgaarden avatar Feb 15 '25 15:02 cgaarden

/azp run

jaimecbernardo avatar Feb 25 '25 11:02 jaimecbernardo

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Feb 25 '25 11:02 azure-pipelines[bot]

/azp run

jaimecbernardo avatar Feb 25 '25 11:02 jaimecbernardo

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Feb 25 '25 11:02 azure-pipelines[bot]

Hi @cgaarden , Thank you for opening the PR.

I think the code looks good and I like the approach. I tried to use the docs and not everything worked for me:

"$YYYY-$MM-%DD, $hh $mm $ss - $PARENT_FOLDER_NAME by %USERNAME%" I tried this and saw that there's a error in %DD instead of $DD , but still couldn't get $PARENT_FOLDER_NAME to work for me. I left some smaller comments a bit before writing this review. Thank you :)

Re %DD Fixed %DD in the documentation.

Re $PARENT_FOLDER_NAME $PARENT_FOLDER_NAME only works in subfolders, e.g. Templates\Key project$PARENT_FOLDER_NAME intro.md

will expand to \Key project\Key project intro.md

and doesn't work at the "root" of the template folder, e.g. Templates$PARENT_FOLDER_NAME intro.md

Updated the documentation to call this out.

Thank you!

cgaarden avatar Feb 26 '25 01:02 cgaarden

Thank you @jaimecbernardo for review and feedback!

I've updated the PR and also the documentation PR.

Thank you!

cgaarden avatar Feb 26 '25 01:02 cgaarden

/azp run

jaimecbernardo avatar Mar 11 '25 17:03 jaimecbernardo

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 11 '25 17:03 azure-pipelines[bot]

/azp run

jaimecbernardo avatar Mar 11 '25 22:03 jaimecbernardo

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 11 '25 22:03 azure-pipelines[bot]

Hi Christian. Gave it another try, but seems like the new setting doesn't do anything. Variables will be replaced whether that setting is off or on. Can you please take a look? Thank you!

Thank you Jaime for having yet another look.

I fixed the issue and fixed a similar issue that I completely missed for optionally hiding file extensions.

Thank you for the feedback and patience with my mistakes here.

cgaarden avatar Mar 15 '25 21:03 cgaarden

/azp run

jaimecbernardo avatar Mar 17 '25 22:03 jaimecbernardo

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 17 '25 22:03 azure-pipelines[bot]