Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for a "multiple files match rule" (Any / One / All) so that when a context menu is invoked on multiple files, the menu can be shown only when any/one/all of the selected files match the configured extension/regex filters (resolves issue #27). UI, model and host (shell extension) sides are all extended to plumb the new flag through.
Changes:
- New
FilesMatchRuleFlagEnum(Any/One/All) plusMenuItem.AcceptMultipleFilesRuleFlagfield, surfaced in the editor UI via a new combo box and visibility helpers. - Host (
CustomExplorerCommand/CustomSubExplorerCommand) reworked to first build all candidate commands, then evaluate each selectedIShellItemagainst the rule (Any short-circuits today's behavior, One = at least one match, All = every item must match). - Minor refactors:
Acceptnow takesstd::wstring_view, fix toPathIsRootprecedence bug, comment cleanups, and a stable::towlowerqualification.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ContextMenuCustom/ContextMenuCustomShare/Service/Menu/FilesMatchRuleFlagEnum.cs | New enum defining Any/One/All rule values. |
| ContextMenuCustom/ContextMenuCustomShare/Service/Menu/MenuItem.cs | Adds AcceptMultipleFilesRuleFlag property serialized into the menu JSON. |
| ContextMenuCustom/ContextMenuCustomShare/ContextMenuCustomShare.projitems | Includes the new enum file in the shared project. |
| ContextMenuCustom/ContextMenuCustomShare/Common/AppLang.cs | Adds localizable strings for the new UI option labels. |
| ContextMenuCustom/ContextMenuCustomShare/View/Menu/MenuPageViewModel.cs | Default new flag value (Any) for newly created menu items. |
| ContextMenuCustom/ContextMenuCustomShare/View/Menu/MenuEditorControl.xaml(.cs) | Adds the rule combo box, populates options, and adds visibility helpers; switches grid to a stack panel. |
| ContextMenuCustom/ContextMenuCustomHost/CustomSubExplorerCommand.{h,cpp} | Adds m_accept_multiple_files_rule_flag, parses it from JSON (key mismatch — see comment), changes Accept to take wstring_view. |
| ContextMenuCustom/ContextMenuCustomHost/CustomExplorerCommand.{h,cpp} | Defers Accept filtering until after all menus are loaded, then applies rule by iterating each IShellItem. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| //TODO | ||
| m_accept_multiple_files_rule_flag = static_cast<FilesMatchRuleFlagEnum>(result.GetNamedNumber(L"acceptMultipleFilesMatchFlag", FILES_RULE_ANY)); |
Comment on lines
+279
to
+322
| winrt::com_ptr<IShellItem> item; | ||
| DWORD count; | ||
| if (SUCCEEDED(selection->GetCount(&count)) && count > 0) { | ||
| bool itemResult = false; | ||
| for (DWORD i = 0; i < count; i++) { | ||
| if (SUCCEEDED(selection->GetItemAt(i, item.put()))) { | ||
| wil::unique_cotaskmem_string path; | ||
| if (SUCCEEDED(item->GetDisplayName(SIGDN_FILESYSPATH, path.put()))) { | ||
| std::wstring itemExt; | ||
| std::wstring_view itemName; | ||
| FileType itemFileType; | ||
|
|
||
| SFGAOF attributes; | ||
| item->GetAttributes(SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_STREAM, &attributes); | ||
| const bool isDirectory = (SFGAO_FILESYSTEM & attributes) == SFGAO_FILESYSTEM && (SFGAO_FOLDER & attributes) == SFGAO_FOLDER && (SFGAO_STREAM & attributes) != SFGAO_STREAM; | ||
| if (!isDirectory) { | ||
| itemName = PathFindFileName(path.get()); | ||
| if (!itemName.starts_with(L".")) { | ||
| itemExt = PathFindExtension(itemName.data()); | ||
| if (!itemExt.empty()) { | ||
| std::ranges::transform(itemExt, itemExt.begin(), ::towlower); // TODO check | ||
| } | ||
| } | ||
| itemFileType = FileType::File; | ||
| } | ||
| else { | ||
| itemFileType = FileType::Directory; | ||
| } | ||
|
|
||
| if (command->Accept(false, itemFileType, itemName, itemExt)) { | ||
| itemResult = true; | ||
| if (command->m_accept_multiple_files_rule_flag == FilesMatchRuleFlagEnum::FILES_RULE_ONE) { | ||
| break; | ||
| } | ||
| } | ||
| else { | ||
| itemResult = false; | ||
| if (command->m_accept_multiple_files_rule_flag == FilesMatchRuleFlagEnum::FILES_RULE_ALL) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #27