添加使用Shell-NeverDefault规则

This commit is contained in:
蓝点lilac
2020-12-31 00:33:23 +08:00
parent 81ec352df7
commit aa32ddda0f
6 changed files with 55 additions and 36 deletions

View File

@@ -129,6 +129,7 @@ namespace ContextMenuManager
public static string OnlyWithShift => GetValue("OnlyWithShift");
public static string OnlyInExplorer => GetValue("OnlyInExplorer");
public static string NoWorkingDirectory => GetValue("NoWorkingDirectory");
public static string NeverDefault => GetValue("NeverDefault");
public static string Details => GetValue("Details");
public static string WebSearch => GetValue("WebSearch");
public static string ChangeCommand => GetValue("ChangeCommand");

View File

@@ -132,6 +132,7 @@ namespace ContextMenuManager.Controls
using(var key = shellKey.CreateSubKey(keyName, true))
{
key.SetValue("MUIVerb", ItemText);
key.SetValue("NeverDefault", "");
if(rdoMulti.Checked)
key.SetValue("SubCommands", "");
else

View File

@@ -169,6 +169,16 @@ namespace ContextMenuManager.Controls
}
}
private bool NeverDefault
{
get => Registry.GetValue(RegPath, "NeverDefault", null) != null;
set
{
if(value) Registry.SetValue(RegPath, "NeverDefault", "");
else RegistryEx.DeleteValue(RegPath, "NeverDefault");
}
}
private Positions ItemPosition
{
get
@@ -375,14 +385,15 @@ namespace ContextMenuManager.Controls
protected readonly ToolStripMenuItem TsiOtherAttributes = new ToolStripMenuItem(AppString.Menu.OtherAttributes);
readonly ToolStripMenuItem TsiItemIcon = new ToolStripMenuItem(AppString.Menu.ItemIcon);
readonly ToolStripMenuItem TsiDeleteIcon = new ToolStripMenuItem(AppString.Menu.DeleteIcon);
readonly ToolStripMenuItem TsiShieldIcon = new ToolStripMenuItem(AppString.Menu.ShieldIcon);
readonly ToolStripMenuItem TsiPosition = new ToolStripMenuItem(AppString.Menu.ItemPosition);
readonly ToolStripMenuItem TsiDefault = new ToolStripMenuItem(AppString.Menu.SetDefault);
readonly ToolStripMenuItem TsiTop = new ToolStripMenuItem(AppString.Menu.SetTop);
readonly ToolStripMenuItem TsiBottom = new ToolStripMenuItem(AppString.Menu.SetBottom);
readonly ToolStripMenuItem TsiShift = new ToolStripMenuItem(AppString.Menu.OnlyWithShift);
readonly ToolStripMenuItem TsiExplorer = new ToolStripMenuItem(AppString.Menu.OnlyInExplorer);
readonly ToolStripMenuItem TsiSetTop = new ToolStripMenuItem(AppString.Menu.SetTop);
readonly ToolStripMenuItem TsiSetBottom = new ToolStripMenuItem(AppString.Menu.SetBottom);
readonly ToolStripMenuItem TsiOnlyWithShift = new ToolStripMenuItem(AppString.Menu.OnlyWithShift);
readonly ToolStripMenuItem TsiOnlyInExplorer = new ToolStripMenuItem(AppString.Menu.OnlyInExplorer);
readonly ToolStripMenuItem TsiNoWorkDir = new ToolStripMenuItem(AppString.Menu.NoWorkingDirectory);
readonly ToolStripMenuItem TsiShieldIcon = new ToolStripMenuItem(AppString.Menu.ShieldIcon);
readonly ToolStripMenuItem TsiNeverDefault = new ToolStripMenuItem(AppString.Menu.NeverDefault);
readonly ToolStripMenuItem TsiDetails = new ToolStripMenuItem(AppString.Menu.Details);
protected readonly PictureButton BtnSubItems = new PictureButton(AppImage.SubItems);
@@ -405,20 +416,21 @@ namespace ContextMenuManager.Controls
TsiItemIcon.DropDownItems.AddRange(new ToolStripItem[] { TsiChangeIcon, TsiDeleteIcon, TsiShieldIcon });
TsiPosition.DropDownItems.AddRange(new ToolStripItem[] { TsiDefault, TsiTop, TsiBottom });
TsiPosition.DropDownItems.AddRange(new ToolStripItem[] { TsiDefault, TsiSetTop, TsiSetBottom });
TsiOtherAttributes.DropDownItems.AddRange(new ToolStripItem[] { TsiShift, TsiExplorer, TsiNoWorkDir });
TsiOtherAttributes.DropDownItems.AddRange(new ToolStripItem[] { TsiOnlyWithShift, TsiOnlyInExplorer, TsiNoWorkDir, TsiNeverDefault });
TsiDetails.DropDownItems.AddRange(new ToolStripItem[] { TsiSearch, new ToolStripSeparator(),
TsiChangeCommand, TsiFileProperties, TsiFileLocation, TsiRegLocation, TsiRegExport});
TsiDeleteIcon.Click += (sender, e) => DeleteIcon();
TsiTop.Click += (sender, e) => this.ItemPosition = Positions.Top;
TsiBottom.Click += (sender, e) => this.ItemPosition = Positions.Bottom;
TsiSetTop.Click += (sender, e) => this.ItemPosition = Positions.Top;
TsiSetBottom.Click += (sender, e) => this.ItemPosition = Positions.Bottom;
TsiDefault.Click += (sender, e) => this.ItemPosition = Positions.Default;
TsiExplorer.Click += (sender, e) => this.OnlyInExplorer = !TsiExplorer.Checked;
TsiShift.Click += (sender, e) => this.OnlyWithShift = !TsiShift.Checked;
TsiOnlyInExplorer.Click += (sender, e) => this.OnlyInExplorer = !TsiOnlyInExplorer.Checked;
TsiOnlyWithShift.Click += (sender, e) => this.OnlyWithShift = !TsiOnlyWithShift.Checked;
TsiNoWorkDir.Click += (sender, e) => this.NoWorkingDirectory = !TsiNoWorkDir.Checked;
TsiNeverDefault.Click += (sender, e) => this.NeverDefault = !TsiNeverDefault.Checked;
ContextMenuStrip.Opening += (sender, e) => RefreshMenuItem();
BtnSubItems.MouseDown += (sender, e) => ShowSubItems();
TsiShieldIcon.Click += (sender, e) => UseShieldIcon();
@@ -446,17 +458,18 @@ namespace ContextMenuManager.Controls
private void RefreshMenuItem()
{
TsiShift.Visible = !IsSubItem;
TsiOnlyWithShift.Visible = !IsSubItem;
TsiDeleteMe.Enabled = !(IsOpenItem && AppConfig.ProtectOpenItem);
TsiNoWorkDir.Checked = this.NoWorkingDirectory;
TsiChangeCommand.Visible = !IsMultiItem && Guid.Equals(Guid.Empty);
if(!this.IsSubItem) TsiShift.Checked = this.OnlyWithShift;
if(!this.IsSubItem) TsiOnlyWithShift.Checked = this.OnlyWithShift;
if(WindowsOsVersion.IsAfterVista)
{
TsiItemIcon.Visible = true;
TsiPosition.Visible = !IsSubItem;
TsiExplorer.Visible = !IsSubItem;
TsiOnlyInExplorer.Visible = !IsSubItem;
TsiNeverDefault.Visible = !IsSubItem;
if(this.HasIcon)
{
TsiChangeIcon.Text = AppString.Menu.ChangeIcon;
@@ -469,20 +482,21 @@ namespace ContextMenuManager.Controls
}
TsiShieldIcon.Checked = HasLUAShield;
if(!this.IsSubItem)
if(!IsSubItem)
{
TsiExplorer.Checked = this.OnlyInExplorer;
TsiDefault.Checked = TsiTop.Checked = TsiBottom.Checked = false;
TsiOnlyInExplorer.Checked = this.OnlyInExplorer;
TsiNeverDefault.Checked = this.NeverDefault;
TsiDefault.Checked = TsiSetTop.Checked = TsiSetBottom.Checked = false;
switch(this.ItemPosition)
{
case Positions.Default:
TsiDefault.Checked = true;
break;
case Positions.Top:
TsiTop.Checked = true;
TsiSetTop.Checked = true;
break;
case Positions.Bottom:
TsiBottom.Checked = true;
TsiSetBottom.Checked = true;
break;
}
}
@@ -491,7 +505,8 @@ namespace ContextMenuManager.Controls
{
TsiItemIcon.Visible = false;
TsiPosition.Visible = false;
TsiExplorer.Visible = false;
TsiOnlyInExplorer.Visible = false;
TsiNeverDefault.Visible = false;
}
}

View File

@@ -102,9 +102,10 @@ SetDefault = 默认
SetTop = 置顶
SetBottom = 置底
OtherAttributes = 其他属性
OnlyWithShift = 仅在按住Shift键后显示
OnlyInExplorer = 仅在Explorer窗口显示
OnlyWithShift = 仅在按住 Shift 键后显示
OnlyInExplorer = 仅在 Explorer 窗口显示
NoWorkingDirectory = 不使用右键所处目录信息
NeverDefault = 从不作为左键默认执行命令
Details = 详细信息
WebSearch = 网页搜索
ChangeCommand = 更改命令

View File

@@ -7,7 +7,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Shell>
<Item KeyName='CopyAsPath' Tip='系统原生菜单项需按住Shift显示,&#x000A;此项可以直接显示'>
<Value>
<REG_SZ MUIVerb='复制文件路径' Icon='imageres.dll,-5302'/>
<REG_SZ MUIVerb='复制文件路径' Icon='imageres.dll,-5302' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='mshta vbscript:clipboarddata.setdata("text","%1")(close)'/>
@@ -15,7 +15,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
</Item>
<Item KeyName='CopyContent' Tip='不需打开文件直接复制文件文本内容&#x000A;非UTF-16 LE(或带BOM)编码会乱码'>
<Value>
<REG_SZ MUIVerb='复制内容到剪切板' Icon='DxpTaskSync.dll,-52'/>
<REG_SZ MUIVerb='复制内容到剪切板' Icon='DxpTaskSync.dll,-52' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='cmd /c clip &lt; "%1"'/>
@@ -24,7 +24,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Item KeyName='TakeOwnerShip'>
<OSVersion Compare=">=">6.2</OSVersion>
<Value>
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory=''/>
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory='' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList &apos;/c takeown /f \"%1\" &amp; icacls \"%1\" /grant *S-1-3-4:F /c /l&apos; -Verb runAs"'/>
@@ -36,7 +36,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Item KeyName='GetHash'>
<OSVersion Compare=">=">6.3</OSVersion>
<Value>
<REG_SZ MUIVerb='获取哈希值'/>
<REG_SZ MUIVerb='获取哈希值' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='powershell -noexit get-filehash -literalpath "%1" -algorithm SHA1 | format-list;get-filehash -literalpath "%1" -algorithm SHA256 | format-list;get-filehash -literalpath "%1" -algorithm SHA384 | format-list;get-filehash -literalpath "%1" -algorithm SHA512 | format-list;get-filehash -literalpath "%1" -algorithm MACTripleDES | format-list;get-filehash -literalpath "%1" -algorithm MD5 | format-list;get-filehash -literalpath "%1" -algorithm RIPEMD160 | format-list'/>
@@ -49,7 +49,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Shell>
<Item KeyName='CopyAsPath' Tip='系统原生菜单项需按住Shift显示,&#x000A;此项可以直接显示'>
<Value>
<REG_SZ MUIVerb='复制文件夹路径' Icon='imageres.dll,-5302'/>
<REG_SZ MUIVerb='复制文件夹路径' Icon='imageres.dll,-5302' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='mshta vbscript:clipboarddata.setdata("text","%1")(close)'/>
@@ -63,7 +63,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Item KeyName="TakeOwnerShip">
<OSVersion Compare=">=">6.2</OSVersion>
<Value>
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory=''/>
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory='' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList &apos;/c takeown /f \"%1\" /r /d y &amp; icacls \"%1\" /grant *S-1-3-4:F /t /c /l /q&apos; -Verb runAs"'>
@@ -195,7 +195,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<!--优化驱动器-->
<Item KeyName='OptimizeDrives'>
<Value>
<REG_SZ MUIVerb='@dfrgui.exe,-106' Icon='dfrgui.exe,0'/>
<REG_SZ MUIVerb='@dfrgui.exe,-106' Icon='dfrgui.exe,0' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='dfrgui.exe'/>
@@ -204,7 +204,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<!--磁盘清理-->
<Item KeyName='Windows.CleanUp'>
<Value>
<REG_SZ MUIVerb='@shell32.dll,-22026' Icon='cleanmgr.exe,-104' CommandStateSync='' ExplorerCommandHandler='{9cca66bb-9c78-4e59-a76f-a5e9990b8aa0}'/>
<REG_SZ MUIVerb='@shell32.dll,-22026' Icon='cleanmgr.exe,-104' NeverDefault='' CommandStateSync='' ExplorerCommandHandler='{9cca66bb-9c78-4e59-a76f-a5e9990b8aa0}'/>
<REG_DWORD ImpliedSelectionModel='0x1'/>
</Value>
</Item>
@@ -217,14 +217,14 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Item KeyName='Windows.PermanentDelete' Tip='不能用于删除lnk快捷方式文件,&#x000A;或通过快捷方式删除其目标对象'>
<OSVersion Compare=">=">6.2</OSVersion>
<Value>
<REG_SZ MUIVerb='@shell32.dll,-37394' Icon='shell32.dll,-240' Position='bottom' CommandStateSync='' ExplorerCommandHandler='{E9571AB2-AD92-4ec6-8924-4E5AD33790F5}'/>
<REG_SZ MUIVerb='@shell32.dll,-37394' Icon='shell32.dll,-240' NeverDefault='' Position='bottom' CommandStateSync='' ExplorerCommandHandler='{E9571AB2-AD92-4ec6-8924-4E5AD33790F5}'/>
</Value>
</Item>
<!--复制路径-->
<Item KeyName='Windows.CopyAsPath' Tip='系统原生菜单项需按住Shift显示,&#x000A;此项可以直接显示'>
<OSVersion Compare=">=">6.2</OSVersion>
<Value>
<REG_SZ MUIVerb='@shell32.dll,-30329' Icon='imageres.dll,-5302' CommandStateHandler='{3B1599F9-E00A-4BBF-AD3E-B3F99FA87779}' CanonicalName='{707C7BC6-685A-4A4D-A275-3966A5A3EFAA}' CommandStateSync='' VerbHandler='{f3d06e7c-1e45-4a26-847e-f9fcdee59be0}' VerbName='copyaspath' Description='@shell32.dll,-30336'/>
<REG_SZ MUIVerb='@shell32.dll,-30329' Icon='imageres.dll,-5302' NeverDefault='' CommandStateHandler='{3B1599F9-E00A-4BBF-AD3E-B3F99FA87779}' CanonicalName='{707C7BC6-685A-4A4D-A275-3966A5A3EFAA}' CommandStateSync='' VerbHandler='{f3d06e7c-1e45-4a26-847e-f9fcdee59be0}' VerbName='copyaspath' Description='@shell32.dll,-30336'/>
<REG_DWORD InvokeCommandOnSelection='1'/>
</Value>
</Item>
@@ -241,7 +241,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Shell>
<Item KeyName='OpenWithNotepad'>
<Value>
<REG_SZ MUIVerb='用记事本打开' Icon='%windir%\system32\notepad.exe,0'/>
<REG_SZ MUIVerb='用记事本打开' Icon='%windir%\system32\notepad.exe,0' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='notepad.exe %1'/>
@@ -254,7 +254,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息从每个Item节点开
<Shell>
<Item KeyName='OpenWithMsPaint'>
<Value>
<REG_SZ MUIVerb='用画图打开' Icon='mspaint.exe,0'/>
<REG_SZ MUIVerb='用画图打开' Icon='mspaint.exe,0' NeverDefault=''/>
</Value>
<SubKey>
<Command Default='mspaint.exe %1'/>

View File

@@ -102,9 +102,10 @@ SetDefault = 默认
SetTop = 置顶
SetBottom = 置底
OtherAttributes = 其他属性
OnlyWithShift = 仅在按住Shift键后显示
OnlyInExplorer = 仅在Explorer窗口显示
OnlyWithShift = 仅在按住 Shift 键后显示
OnlyInExplorer = 仅在 Explorer 窗口显示
NoWorkingDirectory = 不使用右键所处目录信息
NeverDefault = 从不作为左键默认执行命令
Details = 详细信息
WebSearch = 网页搜索
ChangeCommand = 更改命令