DisplayMagician/HeliosPlus.ShellExtension/HeliosExecutableMenuExtension.cs

75 lines
2.9 KiB
C#
Raw Normal View History

2017-02-26 19:23:31 +00:00
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using HeliosPlus.Shared;
using HeliosPlus.ShellExtension.Resources;
2017-02-26 19:23:31 +00:00
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;
namespace HeliosPlus.ShellExtension
2017-02-26 19:23:31 +00:00
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, @".exe")]
[Guid("48B49131-2258-4694-879F-A3F96310A220")]
2017-02-26 19:23:31 +00:00
internal class HeliosExecutableMenuExtension : SharpContextMenu
{
protected override bool CanShowMenu()
{
2017-08-10 14:21:45 +00:00
return Helios.IsInstalled &&
2018-10-20 00:27:25 +00:00
SelectedItemPaths.Count() == 1 &&
ProfileItem.LoadAllProfiles().Any() &&
2018-10-20 00:27:25 +00:00
Path.GetExtension(SelectedItemPaths.First())?.ToLower() == @".exe";
2017-02-26 19:23:31 +00:00
}
protected override ContextMenuStrip CreateMenu()
{
var explorerMenu = new ContextMenuStrip();
var extensionMenu = new ToolStripMenuItem(Language.Open_under_Display_Profile,
2017-08-07 16:25:34 +00:00
Properties.Resources.Icon_x16);
2018-10-20 00:27:25 +00:00
if (ProfileItem.LoadAllProfiles().Any())
{
ProfileItem.UpdateCurrentProfile();
2018-10-20 00:27:25 +00:00
foreach (var profile in ProfileItem.LoadAllProfiles())
2018-10-20 00:27:25 +00:00
{
extensionMenu.DropDownItems.Add(CreateProfileMenu(profile));
2018-10-20 00:27:25 +00:00
}
extensionMenu.DropDownItems.Add(new ToolStripSeparator());
}
2018-10-20 00:27:25 +00:00
2017-02-26 19:23:31 +00:00
extensionMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Manage_Profiles,
2017-08-07 16:25:34 +00:00
Properties.Resources.Icon_x16,
2018-10-20 00:27:25 +00:00
(sender, args) =>
{
HeliosPlus.Open();
2018-10-20 00:27:25 +00:00
}));
2017-02-26 19:23:31 +00:00
explorerMenu.Items.Add(extensionMenu);
explorerMenu.Items.Add(new ToolStripSeparator());
2018-10-20 00:27:25 +00:00
2017-02-26 19:23:31 +00:00
return explorerMenu;
}
private ToolStripMenuItem CreateProfileMenu(ProfileItem profile)
2017-02-26 19:23:31 +00:00
{
var profileMenu = new ToolStripMenuItem(profile.Name, new ProfileIcon(profile).ToBitmap(16, 16));
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run, null,
2017-02-26 19:23:31 +00:00
(sender, args) =>
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
2017-02-26 19:23:31 +00:00
SelectedItemPaths.FirstOrDefault())));
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run_as_administrator, Shield.SmallIcon,
2017-02-26 19:23:31 +00:00
(sender, args) =>
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
2017-02-26 19:23:31 +00:00
SelectedItemPaths.FirstOrDefault(), true)));
profileMenu.DropDownItems.Add(new ToolStripSeparator());
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Create_Shortcut, null,
2017-02-26 19:23:31 +00:00
(sender, args) =>
HeliosPlus.Open(HeliosStartupAction.CreateShortcut, profile,
2017-02-26 19:23:31 +00:00
SelectedItemPaths.FirstOrDefault())));
2018-10-20 00:27:25 +00:00
2017-02-26 19:23:31 +00:00
return profileMenu;
}
}
}