DisplayMagician/HeliosPlus.ShellExtension/HeliosDesktopMenuExtension.cs

78 lines
3.0 KiB
C#
Raw Normal View History

2017-02-26 19:23:31 +00:00
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.Class, @"DesktopBackground")]
[Guid("2EC0C798-715B-458E-8C86-5D846F67FBA1")]
2017-02-26 19:23:31 +00:00
internal class HeliosDesktopMenuExtension : SharpContextMenu
{
private static 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.Apply, null,
(sender, args) => HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile))
2017-02-26 19:23:31 +00:00
{
Enabled = profile.IsPossible && !profile.IsActive
});
profileMenu.DropDownItems.Add(new ToolStripSeparator());
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Edit, null,
(sender, args) => HeliosPlus.Open(HeliosStartupAction.EditProfile, profile)));
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Create_Shortcut, null,
(sender, args) => HeliosPlus.Open(HeliosStartupAction.CreateShortcut, profile)));
2018-10-20 00:27:25 +00:00
2017-02-26 19:23:31 +00:00
return profileMenu;
}
protected override bool CanShowMenu()
{
return Helios.IsInstalled;
2017-02-26 19:23:31 +00:00
}
protected override ContextMenuStrip CreateMenu()
{
var explorerMenu = new ContextMenuStrip();
2018-10-20 00:27:25 +00:00
if (ProfileItem.LoadAllProfiles().Any())
{
ProfileItem.UpdateCurrentProfile();
var extensionMenu = new ToolStripMenuItem(Language.Display_Profiles,
Properties.Resources.Icon_x16);
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());
extensionMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Manage_Profiles,
Properties.Resources.Icon_x16,
2018-10-20 00:27:25 +00:00
(sender, args) =>
{
HeliosPlus.Open();
2018-10-20 00:27:25 +00:00
}));
explorerMenu.Items.Add(extensionMenu);
explorerMenu.Items.Add(new ToolStripSeparator());
}
else
{
var extensionMenu = new ToolStripMenuItem(Language.Manage_Profiles,
Properties.Resources.Icon_x16,
2018-10-20 00:27:25 +00:00
(sender, args) =>
{
HeliosPlus.Open();
2018-10-20 00:27:25 +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;
}
}
}