Browse Source

优化代码

蓝点lilac 4 years ago
parent
commit
5b89cd81ac

+ 11 - 7
ContextMenuManager/BluePointLilac.Controls/MyListBox.cs

@@ -113,8 +113,12 @@ namespace BluePointLilac.Controls
         {
             if(this.Controls.Count == 0) return;
             this.SuspendLayout();
-            foreach(Control control in this.Controls) BeginInvoke(new Action(control.Dispose));
-            this.Controls.Clear();
+            for(int i = this.Controls.Count - 1; i >= 0; i--)
+            {
+                Control ctr = this.Controls[i];
+                this.Controls.Remove(ctr);
+                ctr.Dispose();
+            }
             this.ResumeLayout();
         }
 
@@ -154,9 +158,9 @@ namespace BluePointLilac.Controls
             this.BackColor = Color.FromArgb(250, 250, 250);
             this.Controls.AddRange(new Control[] { lblSeparator, flpControls, lblText, picImage });
             this.Resize += (Sender, e) => pnlScrollbar.Height = this.ClientSize.Height;
-            flpControls.MouseClick += (sender, e) => this.OnMouseClick(null);
-            flpControls.MouseEnter += (sender, e) => this.OnMouseEnter(null);
-            flpControls.MouseDown += (sender, e) => this.OnMouseDown(null);
+            flpControls.MouseClick += (sender, e) => this.OnMouseClick(e);
+            flpControls.MouseEnter += (sender, e) => this.OnMouseEnter(e);
+            flpControls.MouseDown += (sender, e) => this.OnMouseDown(e);
             lblSeparator.SetEnabled(false);
             lblText.SetEnabled(false);
             CenterControl(lblText);
@@ -263,8 +267,8 @@ namespace BluePointLilac.Controls
             this.SuspendLayout();
             ctr.Parent = flpControls;
             ctr.Margin = new Padding(0, 0, space, 0);
-            ctr.MouseEnter += (sender, e) => this.OnMouseEnter(null);
-            ctr.MouseDown += (sender, e) => this.OnMouseEnter(null);
+            ctr.MouseEnter += (sender, e) => this.OnMouseEnter(e);
+            ctr.MouseDown += (sender, e) => this.OnMouseEnter(e);
             CenterControl(ctr);
             this.ResumeLayout();
         }

+ 4 - 2
ContextMenuManager/BluePointLilac.Controls/ReadOnlyTextBox.cs

@@ -14,7 +14,8 @@ namespace BluePointLilac.Controls
             this.ShortcutsEnabled = false;
             this.BackColor = Color.White;
             this.ForeColor = Color.FromArgb(80, 80, 80);
-            this.Font = new Font(SystemFonts.MenuFont.FontFamily, 10F);
+            this.Font = SystemFonts.MenuFont;
+            this.Font = new Font(this.Font.FontFamily, this.Font.Size + 1F);
         }
 
         const int WM_SETFOCUS = 0x0007;
@@ -48,7 +49,8 @@ namespace BluePointLilac.Controls
             this.BackColor = Color.White;
             this.BorderStyle = BorderStyle.None;
             this.ForeColor = Color.FromArgb(80, 80, 80);
-            this.Font = new Font(SystemFonts.MenuFont.FontFamily, 10F);
+            this.Font = SystemFonts.MenuFont;
+            this.Font = new Font(this.Font.FontFamily, this.Font.Size + 1F);
         }
 
         const int WM_SETFOCUS = 0x0007;

+ 4 - 0
ContextMenuManager/BluePointLilac.Methods/FormExtension.cs

@@ -6,6 +6,8 @@ namespace BluePointLilac.Methods
     public static class FormExtension
     {
         /// <summary>移动窗体时同时移动另一个窗体</summary>
+        /// <param name="frm1">主动移动的窗体</param>
+        /// <param name="frm2">同时被移动的窗体</param>
         public static void MoveAsMove(this Form frm1, Form frm2)
         {
             if(frm2 == null) return;
@@ -21,6 +23,8 @@ namespace BluePointLilac.Methods
         }
 
         /// <summary>给窗体添加ESC键关闭功能</summary>
+        /// <param name="frm">指定窗口</param>
+        /// <param name="dr">关闭窗口时的对话框返回值</param>
         /// <remarks>也可以重写Form的ProcessDialogKey事件,
         /// 这个方法更简单,但遍历窗体控件时切记多了一个不可见的关闭按钮</remarks>
         public static void AddEscapeButton(this Form frm, DialogResult dr = DialogResult.Cancel)

+ 2 - 2
ContextMenuManager/Controls/EnhanceMenusItem.cs

@@ -170,6 +170,7 @@ namespace ContextMenuManager.Controls
 
     sealed class EnhanceShellExItem : FoldSubItem, IChkVisibleItem
     {
+        public string RegPath => $@"{ShellExPath}\ContextMenuHandlers\{DefaultKeyName}";
         public string ShellExPath { get; set; }
         public string DefaultKeyName { get; set; }
         public Guid Guid { get; set; }
@@ -182,8 +183,7 @@ namespace ContextMenuManager.Controls
             {
                 if(value)
                 {
-                    string regPath = ObjectPath.GetNewPathWithIndex
-                    ($@"{ShellExPath}\ContextMenuHandlers\{DefaultKeyName}", ObjectPath.PathType.Registry);
+                    string regPath = ObjectPath.GetNewPathWithIndex(this.RegPath, ObjectPath.PathType.Registry);
                     Registry.SetValue(regPath, "", this.Guid.ToString("B"));
                 }
                 else

+ 4 - 1
ContextMenuManager/Controls/FoldSubItem.cs

@@ -81,7 +81,10 @@ namespace ContextMenuManager.Controls
             this.Font = new Font(this.Font, FontStyle.Bold);
             this.AddCtrs(new[] { btnFold, btnOpenPath });
             this.ContextMenuStrip.Items.AddRange(new[] { tsiFoldAll, tsiUnfoldAll });
-            this.MouseDown += (sender, e) => Fold();
+            this.MouseDown += (sender, e) =>
+            {
+                if(e.Button == MouseButtons.Left) Fold();
+            };
             btnFold.MouseDown += (sender, e) =>
             {
                 Fold();

+ 1 - 0
ContextMenuManager/Controls/NewShellDialog.cs

@@ -51,6 +51,7 @@ namespace ContextMenuManager.Controls
 
             static readonly string[] DirScenePaths = {
                 ShellList.MENUPATH_DIRECTORY,
+                ShellList.MENUPATH_BACKGROUND,
                 $@"{ShellList.SYSFILEASSPATH}\Directory."
             };
             static readonly string[] FileObjectsScenePaths = {

+ 2 - 1
ContextMenuManager/Methods/AppConfig.cs

@@ -168,8 +168,9 @@ namespace ContextMenuManager.Methods
                 }
                 catch
                 {
+                    return DateTime.MinValue;
                     //返回文件上次修改时间
-                    return new FileInfo(Application.ExecutablePath).LastWriteTime;
+                    //return new FileInfo(Application.ExecutablePath).LastWriteTime;
                 }
             }
             set => SetGeneralValue("LastCheckUpdateTime", value.ToBinary());

+ 2 - 1
ContextMenuManager/Methods/Updater.cs

@@ -65,7 +65,8 @@ namespace ContextMenuManager.Methods
                     XmlNode bodyXN = root.SelectSingleNode("body");
                     string info = AppString.Message.UpdateInfo.Replace("%v1", appVer.ToString()).Replace("%v2", webVer.ToString());
                     info += "\r\n\r\n" + MachinedInfo(bodyXN.InnerText);
-                    if(AppMessageBox.Show(info, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+                    if(MessageBox.Show(info, AppString.General.AppName, 
+                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                     {
                         string netVer = Environment.Version > new Version(4, 0) ? "4.0" : "3.5";
                         XmlNode assetsXN = root.SelectSingleNode("assets");

+ 3 - 4
ContextMenuManager/Properties/Resources.Designer.cs

@@ -107,12 +107,11 @@ namespace ContextMenuManager.Properties {
         ///;General - TranslatorUrl 为翻译贡献者的URL地址(能用Win+R命令打开的URL链接即可)
         ///;翻译说明:暂时不翻译的值保留为空即可,字典内赋值换行使用\r\n或\n进行转义。
         ///;翻译贡献者和为多人时请使用\r\n或\n对 Translator 的值和对应的 TranslatorUrl 值换行,
-        ///;没有URL地址赋值为null,使贡献者与链接一一对应,如 Translator = Bob \r\n Jion \r\n Andi, 
-        ///;TranslatorUrl = https://example.io \r\n null \r\n https://one.blog
+        ///;没有URL地址赋值为null,使贡献者与链接一一对应,如 Translator = Bob \r\n Join \r\n Andi, 
+        ///;TranslatorUrl = https://github.com/BluePointLilac \r\n null \r\n https://gitee.com/BluePointLilac
         ///
         ///[General]
-        ///AppName = Windows右键管理
-        ///Language = [字符串的其余部分被截断]&quot;; 的本地化字符串。
+        ///Ap [字符串的其余部分被截断]&quot;; 的本地化字符串。
         /// </summary>
         internal static string AppLanguageDic {
             get {