From 3af4fee19ba5a05fa640296780ce8f5484b5bfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E7=82=B9lilac?= Date: Thu, 31 Dec 2020 03:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=84=9F=E7=9F=A5=E7=B1=BB=E5=9E=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContextMenuManager/AppString.cs | 1 + ContextMenuManager/Controls/ShellList.cs | 57 ++++++++++++++++--- .../Resources/Texts/AppLanguageDic.ini | 1 + languages/zh-CN.ini | 1 + 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ContextMenuManager/AppString.cs b/ContextMenuManager/AppString.cs index eaadfda..d93cd38 100644 --- a/ContextMenuManager/AppString.cs +++ b/ContextMenuManager/AppString.cs @@ -173,6 +173,7 @@ namespace ContextMenuManager public static string NewItem => GetValue("NewItem"); public static string AddGuidBlockedItem => GetValue("AddGuidBlockedItem"); public static string CurrentExtension => GetValue("CurrentExtension"); + public static string SetPerceivedType => GetValue("SetPerceivedType"); public static string EditSubItems => GetValue("EditSubItems"); public static string InvalidItem => GetValue("InvalidItem"); public static string Separator => GetValue("Separator"); diff --git a/ContextMenuManager/Controls/ShellList.cs b/ContextMenuManager/Controls/ShellList.cs index 9a3f034..0841f3d 100644 --- a/ContextMenuManager/Controls/ShellList.cs +++ b/ContextMenuManager/Controls/ShellList.cs @@ -3,6 +3,7 @@ using BulePointLilac.Methods; using Microsoft.Win32; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -158,6 +159,7 @@ namespace ContextMenuManager.Controls break; case Scenes.CustomType: this.InsertItem(new TypeItem(), 0); + this.InsertItem(new PerceptionItem(), 1); this.LoadItems(TypeItem.AssExtPath); break; } @@ -242,7 +244,6 @@ namespace ContextMenuManager.Controls sealed class TypeItem : MyListItem { - static string extension; public static string Extension { @@ -256,12 +257,16 @@ namespace ContextMenuManager.Controls public static string SysAssExtPath => Extension == null ? null : $@"{SYSFILEASSPATH}\{Extension}"; public static string AssExtPath => Extension == null ? null : $@"HKEY_CLASSES_ROOT\{FileExtension.GetOpenMode(Extension)}"; + public static string ExtensionPath => $@"HKEY_CLASSES_ROOT\{Extension}"; public static event EventHandler ExtensionChanged; + readonly PictureButton BtnType = new PictureButton(AppImage.Types); + public TypeItem() { - GetImageAndText(); + this.GetText(); + this.Image = AppImage.CustomType; this.AddCtr(BtnType); this.SetNoClickEvent(); BtnType.MouseDown += (sender, e) => @@ -269,24 +274,60 @@ namespace ContextMenuManager.Controls using(FileExtensionDialog dlg = new FileExtensionDialog()) if(dlg.ShowDialog() == DialogResult.OK) Extension = dlg.Extension; }; - ExtensionChanged += (sender, e) => GetImageAndText(); + ExtensionChanged += (sender, e) => this.GetText(); } - readonly PictureButton BtnType = new PictureButton(AppImage.Types); - - private void GetImageAndText() + private void GetText() { if(Extension == null) { - this.Image = AppImage.CustomType; this.Text = AppString.Dialog.SelectExtension; } else { - this.Image = ResourceIcon.GetExtensionIcon(Extension)?.ToBitmap() ?? AppImage.NotFound; this.Text = $"{AppString.Item.CurrentExtension}{Extension}"; } } } + + sealed class PerceptionItem : MyListItem + { + private static readonly string[] PerceptionTypes = { "Text", "Image", "Video", "Audio", "System", "Compressed" }; + + public PerceptionItem() + { + this.Image = ResourceIcon.GetExtensionIcon(TypeItem.Extension)?.ToBitmap() ?? AppImage.NotFound; + this.Text = AppString.Item.SetPerceivedType; + this.Visible = TypeItem.Extension != null; + this.AddCtr(cmbType); + cmbType.Text = PerceivedType; + cmbType.Items.AddRange(PerceptionTypes); + cmbType.TextChanged += (sneder, e) => PerceivedType = cmbType.Text; + TypeItem.ExtensionChanged += (sender, e) => this.Visible = TypeItem.Extension != null; + } + + private static string PerceivedType + { + get => Registry.GetValue(TypeItem.ExtensionPath, "PerceivedType", null)?.ToString(); + set + { + if(value.IsNullOrWhiteSpace()) + { + RegistryEx.DeleteValue(TypeItem.ExtensionPath, "PerceivedType"); + } + else + { + Registry.SetValue(TypeItem.ExtensionPath, "PerceivedType", value); + } + } + } + + readonly ComboBox cmbType = new ComboBox + { + Font = new Font(SystemFonts.MenuFont.FontFamily, 10F), + ImeMode = ImeMode.Disable, + Width = 100.DpiZoom() + }; + } } } \ No newline at end of file diff --git a/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini b/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini index 2d6ad8e..067f752 100644 --- a/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini +++ b/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini @@ -146,6 +146,7 @@ NewItem = 新建一个菜单项目 AddGuidBlockedItem = 添加GUID锁定项目 LockNewMenu = 锁定新建菜单 CurrentExtension = 你当前选择的文件格式为 +SetPerceivedType = 设置文件格式感知类型 EditSubItems = 编辑 "%s" 的子菜单项目 InvalidItem = 无效菜单项目: Separator = ●●●●●●●●●●●●●●●●●● diff --git a/languages/zh-CN.ini b/languages/zh-CN.ini index 2d6ad8e..067f752 100644 --- a/languages/zh-CN.ini +++ b/languages/zh-CN.ini @@ -146,6 +146,7 @@ NewItem = 新建一个菜单项目 AddGuidBlockedItem = 添加GUID锁定项目 LockNewMenu = 锁定新建菜单 CurrentExtension = 你当前选择的文件格式为 +SetPerceivedType = 设置文件格式感知类型 EditSubItems = 编辑 "%s" 的子菜单项目 InvalidItem = 无效菜单项目: Separator = ●●●●●●●●●●●●●●●●●●