diff --git a/shell-x/GenericExtensions.cs b/shell-x/GenericExtensions.cs index e679eb2..91559e2 100644 --- a/shell-x/GenericExtensions.cs +++ b/shell-x/GenericExtensions.cs @@ -64,6 +64,13 @@ internal static bool EndsWithAny(this string text, params string[] patterns) public static string PathJoin(this string path, params string[] paths) => Path.Combine(new[] { path }.Concat(paths).ToArray()); + public static IEnumerable ForEach(this IEnumerable collection, Action action) + { + foreach (var item in collection) + action(item); + return collection; + } + public static string GetTitle(this Assembly assembly) => assembly.GetCustomAttribute()?.Title; public static bool IsDir(this string path) => File.GetAttributes(path).HasFlag(FileAttributes.Directory); diff --git a/shell-x/Program.cs b/shell-x/Program.cs index da6eee7..b1361fc 100644 --- a/shell-x/Program.cs +++ b/shell-x/Program.cs @@ -228,14 +228,24 @@ protected override ContextMenuStrip CreateMenu() items = items.Concat(extraItems).ToArray(); } - var multipleItemsCFE = ConfiguredFileExtensions.ParseMultipleExt().Where(x => x.Any(xe => selectedItemPaths.All(e => Path.GetExtension(e)?.Matching(xe) != null))); + var multiItemConfiguredFileExt = ConfiguredFileExtensions.ParseMultipleExt().Where(x => x.Any(xe => selectedItemPaths.All(e => Path.GetExtension(e)?.Matching(xe) != null))); - if (multipleItemsCFE.Count() > 0) + if (multiItemConfiguredFileExt.Count() > 0) { - multipleItemsCFE.ToList().ForEach(dir => + multiItemConfiguredFileExt.ForEach(extList => { - var extraItems = BuildMenuFrom(GetConfigDirByPath("[" + string.Join(",", dir) + "]"), selectedItemPaths.ToArgumentsString()); - items = items.Concat(extraItems).ToArray(); + if (selectedItemPaths.All(File.Exists)) // all files, not dirs + { + bool selectedExtensionIsConfigured = selectedItemPaths.Select(Path.GetExtension) // .ext + .Select(x => x.TrimStart('.')) // ext + .All(x => extList.Contains(x)); // present in the configured extensions + + if (selectedExtensionIsConfigured) + { + var extraItems = BuildMenuFrom(GetConfigDirByPath("[" + string.Join(",", extList) + "]"), selectedItemPaths.ToArgumentsString()); + items = items.Concat(extraItems).ToArray(); + } + } }); } }