Skip to content

Commit

Permalink
- Issue #20: Incorrect context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Feb 4, 2023
1 parent abb516a commit 5278e7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions shell-x/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var item in collection)
action(item);
return collection;
}

public static string GetTitle(this Assembly assembly) => assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title;

public static bool IsDir(this string path) => File.GetAttributes(path).HasFlag(FileAttributes.Directory);
Expand Down
20 changes: 15 additions & 5 deletions shell-x/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
}
}
Expand Down

0 comments on commit 5278e7a

Please sign in to comment.