Skip to content

Multple files: add files match rule support#248

Merged
ikas-mc merged 4 commits into
mainfrom
dev
May 17, 2026
Merged

Multple files: add files match rule support#248
ikas-mc merged 4 commits into
mainfrom
dev

Conversation

@ikas-mc
Copy link
Copy Markdown
Owner

@ikas-mc ikas-mc commented May 14, 2026

fix #27

Copy link
Copy Markdown

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

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) plus MenuItem.AcceptMultipleFilesRuleFlag field, 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 selected IShellItem against the rule (Any short-circuits today's behavior, One = at least one match, All = every item must match).
  • Minor refactors: Accept now takes std::wstring_view, fix to PathIsRoot precedence bug, comment cleanups, and a stable ::towlower qualification.

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;
}
}
}
}
}
@ikas-mc ikas-mc merged commit 9cbc464 into main May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multple files - only show entry if any of the files are matching

2 participants