mirror of
https://github.com/BluePointLilac/ContextMenuManager.git
synced 2025-09-02 02:34:08 +00:00
新增"添加本地GUID字典"功能
This commit is contained in:
@@ -132,7 +132,10 @@ namespace ContextMenuManager
|
||||
public static string RegistryLocation => GetValue("RegistryLocation");
|
||||
public static string Delete => GetValue("Delete");
|
||||
public static string DeleteReference => GetValue("DeleteReference");
|
||||
public static string HandleGuid => GetValue("HandleGuid");
|
||||
public static string CopyGuid => GetValue("CopyGuid");
|
||||
public static string BlockGuid => GetValue("BlockGuid");
|
||||
public static string AddGuidDic => GetValue("AddGuidDic");
|
||||
public static string InitialData => GetValue("InitialData");
|
||||
public static string Edit => GetValue("Edit");
|
||||
public static string Save => GetValue("Save");
|
||||
@@ -176,9 +179,12 @@ namespace ContextMenuManager
|
||||
public static string NewOpenWithItem => GetValue("NewOpenWithItem");
|
||||
public static string ItemText => GetValue("ItemText");
|
||||
public static string ItemCommand => GetValue("ItemCommand");
|
||||
public static string ItemName => GetValue("ItemName");
|
||||
public static string ItemIcon => GetValue("ItemIcon");
|
||||
public static string SingleMenu => GetValue("SingleMenu");
|
||||
public static string MultiMenu => GetValue("MultiMenu");
|
||||
public static string InputGuid => GetValue("InputGuid");
|
||||
public static string AddGuidDic => GetValue("AddGuidDic");
|
||||
public static string SelectExtension => GetValue("SelectExtension");
|
||||
public static string CheckReference => GetValue("CheckReference");
|
||||
public static string CheckCommon => GetValue("CheckCommon");
|
||||
|
@@ -126,6 +126,9 @@
|
||||
<Compile Include="Controls\AddCommonButton.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\AddGuidDicDialog.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\SelectItemsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
136
ContextMenuManager/Controls/AddGuidDicDialog.cs
Normal file
136
ContextMenuManager/Controls/AddGuidDicDialog.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using BulePointLilac.Controls;
|
||||
using BulePointLilac.Methods;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
sealed class AddGuidDicDialog : CommonDialog
|
||||
{
|
||||
public Image ItemIcon { get; set; }
|
||||
public string ItemName { get; set; }
|
||||
public string ItemIconPath { get; set; }
|
||||
public int ItemIconIndex { get; set; }
|
||||
public string ItemIconLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
if(ItemIconPath == null) return null;
|
||||
return $"{ItemIconPath},{ItemIconIndex}";
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset() { }
|
||||
|
||||
protected override bool RunDialog(IntPtr hwndOwner)
|
||||
{
|
||||
using(AddGuidDicForm frm = new AddGuidDicForm())
|
||||
{
|
||||
frm.ItemName = this.ItemName;
|
||||
frm.ItemIcon = this.ItemIcon;
|
||||
frm.ItemIconPath = this.ItemIconPath;
|
||||
frm.ItemIconIndex = this.ItemIconIndex;
|
||||
bool flag = frm.ShowDialog() == DialogResult.OK;
|
||||
if(flag)
|
||||
{
|
||||
this.ItemName = frm.ItemName;
|
||||
this.ItemIcon = frm.ItemIcon;
|
||||
this.ItemIconPath = frm.ItemIconPath;
|
||||
this.ItemIconIndex = frm.ItemIconIndex;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class AddGuidDicForm : Form
|
||||
{
|
||||
public AddGuidDicForm()
|
||||
{
|
||||
this.AcceptButton = btnOk;
|
||||
this.CancelButton = btnCancel;
|
||||
this.Font = SystemFonts.MenuFont;
|
||||
this.Text = AppString.Dialog.AddGuidDic;
|
||||
this.ShowIcon = this.ShowInTaskbar = false;
|
||||
this.MaximizeBox = this.MinimizeBox = false;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedSingle;
|
||||
this.StartPosition = FormStartPosition.CenterParent;
|
||||
InitializeComponents();
|
||||
}
|
||||
|
||||
public string ItemName
|
||||
{
|
||||
get=> txtName.Text;
|
||||
set => txtName.Text = value;
|
||||
}
|
||||
public string ItemIconPath { get; set; }
|
||||
public int ItemIconIndex { get; set; }
|
||||
public Image ItemIcon {
|
||||
get => picIcon.Image;
|
||||
set => picIcon.Image = value;
|
||||
}
|
||||
|
||||
readonly TextBox txtName = new TextBox();
|
||||
readonly Label lblName = new Label
|
||||
{
|
||||
Text = AppString.Dialog.ItemName,
|
||||
AutoSize = true
|
||||
};
|
||||
readonly Label lblIcon = new Label
|
||||
{
|
||||
Text = AppString.Dialog.ItemIcon,
|
||||
AutoSize = true
|
||||
};
|
||||
readonly PictureBox picIcon = new PictureBox
|
||||
{
|
||||
Size = SystemInformation.IconSize,
|
||||
BackColor = Color.White
|
||||
};
|
||||
readonly Button btnIcon = new Button
|
||||
{
|
||||
Text = AppString.Dialog.Browse,
|
||||
AutoSize = true
|
||||
};
|
||||
readonly Button btnOk = new Button
|
||||
{
|
||||
Text = AppString.Dialog.Ok,
|
||||
DialogResult = DialogResult.OK,
|
||||
AutoSize = true
|
||||
};
|
||||
readonly Button btnCancel = new Button
|
||||
{
|
||||
Text = AppString.Dialog.Cancel,
|
||||
DialogResult = DialogResult.Cancel,
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
private void InitializeComponents()
|
||||
{
|
||||
this.Controls.AddRange(new Control[] { lblName, txtName, lblIcon, picIcon, btnIcon, btnOk, btnCancel });
|
||||
int a = 20.DpiZoom();
|
||||
lblName.Left = lblName.Top = lblIcon.Left = txtName.Top = a;
|
||||
txtName.Left = lblName.Right + a;
|
||||
lblIcon.Top = picIcon.Top = btnIcon.Top = lblName.Bottom + a;
|
||||
btnOk.Left = picIcon.Left = lblIcon.Right + a;
|
||||
btnOk.Top = btnCancel.Top = picIcon.Bottom + a;
|
||||
btnIcon.Left = btnCancel.Left = btnOk.Right + a;
|
||||
txtName.Width = btnCancel.Right - txtName.Left;
|
||||
this.ClientSize = new Size(btnCancel.Right + a, btnCancel.Bottom + a);
|
||||
|
||||
btnIcon.Click += (sender, e) => SelectIcon();
|
||||
}
|
||||
|
||||
private void SelectIcon()
|
||||
{
|
||||
using(IconDialog dlg = new IconDialog())
|
||||
{
|
||||
dlg.IconPath = this.ItemIconPath;
|
||||
if(dlg.ShowDialog() != DialogResult.OK) return;
|
||||
ItemIconPath = dlg.IconPath;
|
||||
ItemIconIndex = dlg.IconIndex;
|
||||
picIcon.Image = ResourceIcon.GetIcon(ItemIconPath, ItemIconIndex).ToBitmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ using ContextMenuManager.Controls.Interfaces;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
@@ -66,6 +67,7 @@ namespace ContextMenuManager.Controls
|
||||
private string DefaultValue => Registry.GetValue(RegPath, "", null)?.ToString();
|
||||
private string ItemText => GuidInfo.GetText(Guid) ?? ((Guid.ToString("B") == KeyName) ? DefaultValue : KeyName);
|
||||
private string BuckupPath => $@"{ShellExPath}\{(ItemVisible ? CmhParts[1] : CmhParts[0])}\{KeyName}";
|
||||
private GuidInfo.IconLocation IconLocation => GuidInfo.GetIconLocation(this.Guid);
|
||||
private bool IsOpenLnkItem => Guid.ToString() == LnkOpenGuid;
|
||||
private bool TryProtectOpenItem => IsOpenLnkItem && MessageBoxEx.Show
|
||||
(AppString.MessageBox.PromptIsOpenItem, MessageBoxButtons.YesNo) != DialogResult.Yes;
|
||||
@@ -92,7 +94,10 @@ namespace ContextMenuManager.Controls
|
||||
public RegLocationMenuItem TsiRegLocation { get; set; }
|
||||
public DeleteMeMenuItem TsiDeleteMe { get; set; }
|
||||
readonly ToolStripMenuItem TsiDetails = new ToolStripMenuItem(AppString.Menu.Details);
|
||||
readonly ToolStripMenuItem TsiHandleGuid = new ToolStripMenuItem(AppString.Menu.HandleGuid);
|
||||
readonly ToolStripMenuItem TsiCopyGuid = new ToolStripMenuItem(AppString.Menu.CopyGuid);
|
||||
readonly ToolStripMenuItem TsiBlockGuid = new ToolStripMenuItem(AppString.Menu.BlockGuid);
|
||||
readonly ToolStripMenuItem TsiAddGuidDic = new ToolStripMenuItem(AppString.Menu.AddGuidDic);
|
||||
|
||||
private void InitializeComponents()
|
||||
{
|
||||
@@ -104,14 +109,19 @@ namespace ContextMenuManager.Controls
|
||||
TsiRegLocation = new RegLocationMenuItem(this);
|
||||
TsiDeleteMe = new DeleteMeMenuItem(this);
|
||||
|
||||
ContextMenuStrip.Items.AddRange(new ToolStripItem[] { TsiCopyGuid, new ToolStripSeparator(),
|
||||
ContextMenuStrip.Items.AddRange(new ToolStripItem[] { TsiHandleGuid, new ToolStripSeparator(),
|
||||
TsiDetails, new ToolStripSeparator(), TsiDeleteMe });
|
||||
|
||||
TsiHandleGuid.DropDownItems.AddRange(new ToolStripItem[] { TsiCopyGuid, new ToolStripSeparator(),
|
||||
TsiBlockGuid, new ToolStripSeparator(), TsiAddGuidDic });
|
||||
|
||||
TsiDetails.DropDownItems.AddRange(new ToolStripItem[] { TsiSearch, new ToolStripSeparator(),
|
||||
TsiFileProperties, TsiFileLocation, TsiRegLocation});
|
||||
|
||||
ContextMenuStrip.Opening += (sender, e) => TsiDeleteMe.Enabled = !IsOpenLnkItem;
|
||||
ContextMenuStrip.Opening += (sender, e) => RefreshMenuItem();
|
||||
TsiCopyGuid.Click += (sender, e) => CopyGuid();
|
||||
TsiBlockGuid.Click += (sender, e) => BlockGuid();
|
||||
TsiAddGuidDic.Click += (sender, e) => AddGuidDic();
|
||||
}
|
||||
|
||||
private void CopyGuid()
|
||||
@@ -121,6 +131,78 @@ namespace ContextMenuManager.Controls
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void BlockGuid()
|
||||
{
|
||||
foreach(string path in GuidBlockedItem.BlockedPaths)
|
||||
{
|
||||
if(TsiBlockGuid.Checked)
|
||||
{
|
||||
RegistryEx.DeleteValue(path, this.Guid.ToString("B"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Registry.SetValue(path, this.Guid.ToString("B"), string.Empty);
|
||||
}
|
||||
}
|
||||
ExplorerRestarter.NeedRestart = true;
|
||||
}
|
||||
|
||||
private void AddGuidDic()
|
||||
{
|
||||
using(AddGuidDicDialog dlg = new AddGuidDicDialog())
|
||||
{
|
||||
dlg.ItemName = this.Text;
|
||||
dlg.ItemIcon = this.Image;
|
||||
dlg.ItemIconPath = this.IconLocation.IconPath;
|
||||
dlg.ItemIconIndex = this.IconLocation.IconIndex;
|
||||
if(dlg.ShowDialog() != DialogResult.OK) return;
|
||||
Directory.CreateDirectory(Program.ConfigDir);
|
||||
IniFileHelper helper = new IniFileHelper(Program.GuidInfosDicPath);
|
||||
string section = this.Guid.ToString();
|
||||
if(!string.IsNullOrWhiteSpace(dlg.ItemName))
|
||||
{
|
||||
helper.SetValue(section, "Text", dlg.ItemName);
|
||||
this.Text = dlg.ItemName;
|
||||
if(GuidInfo.ItemTextDic.ContainsKey(this.Guid))
|
||||
{
|
||||
GuidInfo.ItemTextDic[this.Guid] = this.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
GuidInfo.ItemTextDic.Add(this.Guid, this.Text);
|
||||
}
|
||||
}
|
||||
if(dlg.ItemIconLocation != null)
|
||||
{
|
||||
helper.SetValue(section, "Icon", dlg.ItemIconLocation);
|
||||
var location = new GuidInfo.IconLocation { IconPath = dlg.ItemIconPath, IconIndex = dlg.ItemIconIndex };
|
||||
if(GuidInfo.IconLocationDic.ContainsKey(this.Guid))
|
||||
{
|
||||
GuidInfo.IconLocationDic[this.Guid] = location;
|
||||
}
|
||||
else
|
||||
{
|
||||
GuidInfo.IconLocationDic.Add(this.Guid, location);
|
||||
}
|
||||
this.Image = dlg.ItemIcon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshMenuItem()
|
||||
{
|
||||
TsiDeleteMe.Enabled = !IsOpenLnkItem;
|
||||
TsiBlockGuid.Checked = false;
|
||||
foreach(string path in GuidBlockedItem.BlockedPaths)
|
||||
{
|
||||
if(Registry.GetValue(path, this.Guid.ToString("B"), null) != null)
|
||||
{
|
||||
TsiBlockGuid.Checked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteMe()
|
||||
{
|
||||
RegistryEx.DeleteKeyTree(this.RegPath);
|
||||
|
@@ -24,10 +24,9 @@ namespace ContextMenuManager
|
||||
|
||||
private static IniReader AppDic;
|
||||
private static readonly IniReader UserDic = new IniReader(Program.GuidInfosDicPath);
|
||||
private static readonly Dictionary<Guid, IconLocation> IconLocationDic = new Dictionary<Guid, IconLocation>();
|
||||
public static readonly Dictionary<Guid, IconLocation> IconLocationDic = new Dictionary<Guid, IconLocation>();
|
||||
private static readonly Dictionary<Guid, string> FilePathDic = new Dictionary<Guid, string>();
|
||||
private static readonly Dictionary<Guid, string> ItemTextDic = new Dictionary<Guid, string>();
|
||||
|
||||
public static readonly Dictionary<Guid, string> ItemTextDic = new Dictionary<Guid, string>();
|
||||
private static readonly Dictionary<Guid, Image> ItemImageDic = new Dictionary<Guid, Image>();
|
||||
|
||||
public static bool TryGetGuid(string value, out Guid guid) => TryGetGuid(value, out guid, out _);
|
||||
@@ -52,12 +51,13 @@ namespace ContextMenuManager
|
||||
|
||||
private static bool TryGetValue(string section, string key, out string value)
|
||||
{
|
||||
//用户自定义字典优先
|
||||
if(UserDic != null && UserDic.TryGetValue(section, key, out value)) return true;
|
||||
if(!File.Exists(Program.AppDataGuidInfosDicPath))
|
||||
File.WriteAllText(Program.AppDataGuidInfosDicPath, Properties.Resources.GuidInfosDic, Encoding.UTF8);
|
||||
if(AppDic == null)
|
||||
AppDic = new IniReader(Program.AppDataGuidInfosDicPath);
|
||||
if(AppDic.TryGetValue(section, key, out value)) return true;
|
||||
if(UserDic != null && UserDic.TryGetValue(section, key, out value)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -106,7 +106,10 @@ FileLocation = 文件位置
|
||||
RegistryLocation = 注册表位置
|
||||
Delete = 删除此项
|
||||
DeleteReference = 删除引用
|
||||
HandleGuid = 处理guid
|
||||
CopyGuid = 复制guid
|
||||
BlockGuid = 锁定Guid
|
||||
AddGuidDic = 添加字典
|
||||
InitialData = 初始数据
|
||||
Edit = 编辑
|
||||
Save = 保存
|
||||
@@ -143,9 +146,12 @@ NewSendToItem = 新建发送到子菜单项目
|
||||
NewOpenWithItem = 新建打开方式菜单项目
|
||||
ItemText = 菜单文本
|
||||
ItemCommand = 菜单命令
|
||||
ItemName = 项目名称
|
||||
ItemIcon = 项目图标
|
||||
SingleMenu = 一级
|
||||
MultiMenu = 多级
|
||||
InputGuid = 输入Guid
|
||||
AddGuidDic = 添加Guid本地字典
|
||||
SelectExtension = 请选择一个文件扩展名
|
||||
CheckReference = 请勾选你想要添加引用的菜单项目
|
||||
CheckCommon = 请勾选你想要添加的常用菜单项目
|
||||
|
@@ -106,7 +106,10 @@ FileLocation = 文件位置
|
||||
RegistryLocation = 注册表位置
|
||||
Delete = 删除此项
|
||||
DeleteReference = 删除引用
|
||||
HandleGuid = 处理guid
|
||||
CopyGuid = 复制guid
|
||||
BlockGuid = 锁定Guid
|
||||
AddGuidDic = 添加字典
|
||||
InitialData = 初始数据
|
||||
Edit = 编辑
|
||||
Save = 保存
|
||||
@@ -143,9 +146,12 @@ NewSendToItem = 新建发送到子菜单项目
|
||||
NewOpenWithItem = 新建打开方式菜单项目
|
||||
ItemText = 菜单文本
|
||||
ItemCommand = 菜单命令
|
||||
ItemName = 项目名称
|
||||
ItemIcon = 项目图标
|
||||
SingleMenu = 一级
|
||||
MultiMenu = 多级
|
||||
InputGuid = 输入Guid
|
||||
AddGuidDic = 添加Guid本地字典
|
||||
SelectExtension = 请选择一个文件扩展名
|
||||
CheckReference = 请勾选你想要添加引用的菜单项目
|
||||
CheckCommon = 请勾选你想要添加的常用菜单项目
|
||||
|
Reference in New Issue
Block a user