Skip to content

Commit

Permalink
- Issue #12: Icon too big on nested context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Jan 6, 2023
1 parent 3c3b423 commit d1d11c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion shell-x/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ public static string ToFileMenuText(this string path) => path.GetFileName()
.Replace(".bat", "")
.Replace(".ps1", "");

public static string ToDirMenuText(this string path) => path.GetFileName().Split(new[] { '.' }, 2).Last();
public static string ToDirMenuText(this string path) => path.GetFileName().Split(new[] { '.' }, 2).Last();

public static int ToStandardIconSize(this int customSize)
{
var standardSizes = new[] { 16, 32, 48, 256 };
return standardSizes.OrderBy(x => Math.Abs((long)x - customSize)).First();
}

public static string GetFileNameWithoutExtension(this string path) => Path.GetFileNameWithoutExtension(path);

Expand Down
10 changes: 9 additions & 1 deletion shell-x/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ internal static ToolStripItem[] BuildMenuFrom(string configDir, string invokeArg
Image = LookupImageFor(item)
};

try
{
var size = parentMenu.ContentRectangle.Height.ToStandardIconSize();
parentMenu.Image = parentMenu.Image?.Resize(size, size);
}
catch { }

current.AddItem(parentMenu);
dirsToProcess.Enqueue(new BuildItem
{
Expand All @@ -316,7 +323,8 @@ internal static ToolStripItem[] BuildMenuFrom(string configDir, string invokeArg

try
{
menu.Image = menu.Image?.Resize(menu.ContentRectangle.Height, menu.ContentRectangle.Height);
var size = menu.ContentRectangle.Height.ToStandardIconSize();
menu.Image = menu.Image?.Resize(size, size);
}
catch { }

Expand Down

0 comments on commit d1d11c5

Please sign in to comment.