From d3e4c655ae409fb74545b44dc965328b48a32a0b Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Sat, 23 Oct 2021 16:27:53 +0200 Subject: [PATCH] Code Cleanup, version 1.0.23.0 --- Business/App.cs | 4 + Business/KeyboardInput.cs | 1 + Business/Menus.cs | 1 + Business/WaitLeave.cs | 1 + Business/WaitToLoadMenu.cs | 1 + DataClasses/RowData.cs | 78 +++++++++++++++++++ GlobalSuppressions.cs | 5 -- Helpers/DgvMouseRow.cs | 1 + Helpers/Fading.cs | 1 + Helpers/KeyPressedEventArgs.cs | 5 +- Helpers/KeyboardHook.cs | 1 + Helpers/WindowsExplorerSort.cs | 1 + UserInterface/AboutBox.cs | 17 ++-- UserInterface/AppNotifyIcon.cs | 1 + .../CustomScrollbar/CustomScrollbar.cs | 3 + .../ScrollbarControlDesigner.cs | 1 + .../FolderBrowseDialog/FolderDialog.cs | 5 ++ .../FolderBrowseDialog/WindowWrapper.cs | 9 ++- .../HotkeyTextboxControl/HotkeyControl.cs | 1 + UserInterface/LabelNoCopy.cs | 1 + UserInterface/Menu.cs | 2 + UserInterface/SettingsForm.cs | 31 +++++--- Utilities/File/FileIni.cs | 13 ++++ 23 files changed, 150 insertions(+), 34 deletions(-) diff --git a/Business/App.cs b/Business/App.cs index f941a1d..4b2438e 100644 --- a/Business/App.cs +++ b/Business/App.cs @@ -18,6 +18,9 @@ namespace SystemTrayMenu private readonly AppNotifyIcon menuNotifyIcon = new AppNotifyIcon(); private readonly Menus menus = new Menus(); + /// + /// Initializes a new instance of the class. + /// public App() { AppRestart.BeforeRestarting += Dispose; @@ -36,6 +39,7 @@ namespace SystemTrayMenu menus.MainPreload(); } + /// public void Dispose() { SystemEvents.DisplaySettingsChanged -= AppRestart.ByDisplaySettings; diff --git a/Business/KeyboardInput.cs b/Business/KeyboardInput.cs index 2b8dbb8..214015d 100644 --- a/Business/KeyboardInput.cs +++ b/Business/KeyboardInput.cs @@ -41,6 +41,7 @@ namespace SystemTrayMenu.Handler internal bool InUse { get; set; } + /// public void Dispose() { hook.Dispose(); diff --git a/Business/Menus.cs b/Business/Menus.cs index bb69dbd..8249593 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -281,6 +281,7 @@ namespace SystemTrayMenu.Business private List AsList => AsEnumerable.ToList(); + /// public void Dispose() { workerMainMenu.Dispose(); diff --git a/Business/WaitLeave.cs b/Business/WaitLeave.cs index 1adda8c..c4b28d8 100644 --- a/Business/WaitLeave.cs +++ b/Business/WaitLeave.cs @@ -20,6 +20,7 @@ namespace SystemTrayMenu.Handler public event EventHandlerEmpty LeaveTriggered; + /// public void Dispose() { timerLeaveCheck.Dispose(); diff --git a/Business/WaitToLoadMenu.cs b/Business/WaitToLoadMenu.cs index c57af9d..dd7855d 100644 --- a/Business/WaitToLoadMenu.cs +++ b/Business/WaitToLoadMenu.cs @@ -39,6 +39,7 @@ namespace SystemTrayMenu.Handler internal bool MouseActive { get; set; } + /// public void Dispose() { timerStartLoad.Stop(); diff --git a/DataClasses/RowData.cs b/DataClasses/RowData.cs index 5d0baa9..da2c7d2 100644 --- a/DataClasses/RowData.cs +++ b/DataClasses/RowData.cs @@ -13,6 +13,9 @@ namespace SystemTrayMenu.DataClasses using SystemTrayMenu.Utilities; using Menu = SystemTrayMenu.UserInterface.Menu; + /// + /// Contains data of row. + /// internal class RowData { private static readonly Icon White50PercentageIcon = Properties.Resources.White50Percentage; @@ -23,43 +26,97 @@ namespace SystemTrayMenu.DataClasses private string text; private Icon icon; + /// + /// Initializes a new instance of the class. + /// internal RowData() { } + /// + /// Gets or sets fileInfo. + /// internal FileInfo FileInfo { get; set; } + /// + /// Gets or sets SubMenu. + /// internal Menu SubMenu { get; set; } + /// + /// Gets or sets a value indicating whether IsMenuOpen. + /// internal bool IsMenuOpen { get; set; } + /// + /// Gets or sets a value indicating whether IsSelected. + /// internal bool IsSelected { get; set; } + /// + /// Gets or sets a value indicating whether ContainsMenu. + /// internal bool ContainsMenu { get; set; } + /// + /// Gets or sets a value indicating whether IsContextMenuOpen. + /// internal bool IsContextMenuOpen { get; set; } + /// + /// Gets or sets a value indicating whether IsResolvedLnk. + /// internal bool IsResolvedLnk { get; set; } + /// + /// Gets or sets a value indicating whether is a HiddenEntry. + /// internal bool HiddenEntry { get; set; } + /// + /// Gets or sets TargetFilePath. + /// internal string TargetFilePath { get; set; } + /// + /// Gets or sets TargetFilePathOrig. + /// internal string TargetFilePathOrig { get; set; } + /// + /// Gets or sets RowIndex. + /// internal int RowIndex { get; set; } + /// + /// Gets or sets MenuLevel. + /// internal int MenuLevel { get; set; } + /// + /// Gets or sets a value indicating whether IconLoading. + /// internal bool IconLoading { get; set; } + /// + /// Gets or sets FilePathIcon. + /// internal string FilePathIcon { get; set; } + /// + /// Set text of row. + /// + /// text of row. internal void SetText(string text) { this.text = text; } + /// + /// SetData. + /// + /// data. + /// dataTable. internal void SetData(RowData data, DataTable dataTable) { DataRow row = dataTable.Rows.Add(); @@ -87,6 +144,12 @@ namespace SystemTrayMenu.DataClasses row[2] = data; } + /// + /// ReadIcon. + /// + /// isDirectory. + /// resolvedLnkPath. + /// isLnkDirectory. internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) { bool isLnkDirectory = false; @@ -150,6 +213,12 @@ namespace SystemTrayMenu.DataClasses return isLnkDirectory; } + /// + /// MouseDown. + /// + /// dgv. + /// e. + /// toCloseByDoubleClick. internal void MouseDown(DataGridView dgv, MouseEventArgs e, out bool toCloseByDoubleClick) { toCloseByDoubleClick = false; @@ -191,6 +260,11 @@ namespace SystemTrayMenu.DataClasses } } + /// + /// DoubleClick. + /// + /// e. + /// toCloseByDoubleClick. internal void DoubleClick(MouseEventArgs e, out bool toCloseByDoubleClick) { toCloseByDoubleClick = false; @@ -209,6 +283,10 @@ namespace SystemTrayMenu.DataClasses } } + /// + /// ReadLoadedIcon. + /// + /// Icon. internal Icon ReadLoadedIcon() { if (ContainsMenu) diff --git a/GlobalSuppressions.cs b/GlobalSuppressions.cs index 835ffc9..0eec1b3 100644 --- a/GlobalSuppressions.cs +++ b/GlobalSuppressions.cs @@ -5,9 +5,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA0001:XML comment analysis is disabled due to project configuration", Justification = "no idea what this is")] - -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "we need to document")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:Partial elements should be documented", Justification = "we need to document")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "we need to document")] - [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Standard codecleanup removes the this")] diff --git a/Helpers/DgvMouseRow.cs b/Helpers/DgvMouseRow.cs index f7f3041..eaeee29 100644 --- a/Helpers/DgvMouseRow.cs +++ b/Helpers/DgvMouseRow.cs @@ -28,6 +28,7 @@ namespace SystemTrayMenu.Helper internal event Action RowMouseLeave; + /// public void Dispose() { Dispose(true); diff --git a/Helpers/Fading.cs b/Helpers/Fading.cs index 6a81580..94e4101 100644 --- a/Helpers/Fading.cs +++ b/Helpers/Fading.cs @@ -51,6 +51,7 @@ namespace SystemTrayMenu.UserInterface internal bool IsHiding => state == FadingState.Hide; + /// public void Dispose() { Dispose(true); diff --git a/Helpers/KeyPressedEventArgs.cs b/Helpers/KeyPressedEventArgs.cs index 1ee5cf6..26fc5e2 100644 --- a/Helpers/KeyPressedEventArgs.cs +++ b/Helpers/KeyPressedEventArgs.cs @@ -12,16 +12,15 @@ namespace SystemTrayMenu.Helper /// internal class KeyPressedEventArgs : EventArgs { - private readonly KeyboardHookModifierKeys modifier; private readonly Keys key; internal KeyPressedEventArgs(KeyboardHookModifierKeys modifier, Keys key) { - this.modifier = modifier; + this.Modifier = modifier; this.key = key; } - internal KeyboardHookModifierKeys Modifier => modifier; + internal KeyboardHookModifierKeys Modifier { get; } internal Keys Key => key; } diff --git a/Helpers/KeyboardHook.cs b/Helpers/KeyboardHook.cs index 2325a98..1495d8f 100644 --- a/Helpers/KeyboardHook.cs +++ b/Helpers/KeyboardHook.cs @@ -41,6 +41,7 @@ namespace SystemTrayMenu.Helper /// internal event EventHandler KeyPressed; + /// public void Dispose() { // unregister all the registered hot keys. diff --git a/Helpers/WindowsExplorerSort.cs b/Helpers/WindowsExplorerSort.cs index d340eca..6efc66f 100644 --- a/Helpers/WindowsExplorerSort.cs +++ b/Helpers/WindowsExplorerSort.cs @@ -8,6 +8,7 @@ namespace SystemTrayMenu.Helper internal class WindowsExplorerSort : IComparer { + /// public int Compare(string x, string y) { return DllImports.NativeMethods.ShlwapiStrCmpLogicalW(x, y); diff --git a/UserInterface/AboutBox.cs b/UserInterface/AboutBox.cs index 2532870..e509b9a 100644 --- a/UserInterface/AboutBox.cs +++ b/UserInterface/AboutBox.cs @@ -31,7 +31,6 @@ namespace SystemTrayMenu.UserInterface private string entryAssemblyName; private string callingAssemblyName; private string executingAssemblyName; - private Assembly entryAssembly; private NameValueCollection entryAssemblyAttribCollection; public AboutBox() @@ -49,11 +48,7 @@ namespace SystemTrayMenu.UserInterface // This is usually read-only, but in some weird cases (Smart Client apps) // you won't have an entry assembly, so you may want to set this manually. // - public Assembly AppEntryAssembly - { - get => entryAssembly; - set => entryAssembly = value; - } + public Assembly AppEntryAssembly { get; set; } // // single line of text to show in the application title section of the about box dialog @@ -585,7 +580,7 @@ namespace SystemTrayMenu.UserInterface private void PopulateLabels() { // get entry assembly attribs - entryAssemblyAttribCollection = AssemblyAttribs(entryAssembly); + entryAssemblyAttribCollection = AssemblyAttribs(AppEntryAssembly); // set icon from parent, if present if (Owner != null) @@ -646,14 +641,14 @@ namespace SystemTrayMenu.UserInterface private void AboutBox_Load(object sender, EventArgs e) { // if the user didn't provide an assembly, try to guess which one is the entry assembly - if (entryAssembly == null) + if (AppEntryAssembly == null) { - entryAssembly = Assembly.GetEntryAssembly(); + AppEntryAssembly = Assembly.GetEntryAssembly(); } - if (entryAssembly == null) + if (AppEntryAssembly == null) { - entryAssembly = Assembly.GetExecutingAssembly(); + AppEntryAssembly = Assembly.GetExecutingAssembly(); } executingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name; diff --git a/UserInterface/AppNotifyIcon.cs b/UserInterface/AppNotifyIcon.cs index d2e19c8..3b5ebee 100644 --- a/UserInterface/AppNotifyIcon.cs +++ b/UserInterface/AppNotifyIcon.cs @@ -80,6 +80,7 @@ namespace SystemTrayMenu.UserInterface public event EventHandlerEmpty Exit; + /// public void Dispose() { notifyIcon.Icon = null; diff --git a/UserInterface/CustomScrollbar/CustomScrollbar.cs b/UserInterface/CustomScrollbar/CustomScrollbar.cs index ac315f8..919e25e 100644 --- a/UserInterface/CustomScrollbar/CustomScrollbar.cs +++ b/UserInterface/CustomScrollbar/CustomScrollbar.cs @@ -141,6 +141,7 @@ namespace SystemTrayMenu.UserInterface public int Delta => Value - lastValue; + /// public override bool AutoSize { get => base.AutoSize; @@ -207,12 +208,14 @@ namespace SystemTrayMenu.UserInterface Invalidate(); } + /// protected override void Dispose(bool disposing) { timerMouseStillClicked.Dispose(); base.Dispose(disposing); } + /// protected override void OnPaint(PaintEventArgs e) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; diff --git a/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs index 92c996b..695a559 100644 --- a/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs +++ b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs @@ -9,6 +9,7 @@ namespace SystemTrayMenu.UserInterface internal class ScrollbarControlDesigner : ControlDesigner { + /// public override SelectionRules SelectionRules { get diff --git a/UserInterface/FolderBrowseDialog/FolderDialog.cs b/UserInterface/FolderBrowseDialog/FolderDialog.cs index 1c71c1a..0c83f6c 100644 --- a/UserInterface/FolderBrowseDialog/FolderDialog.cs +++ b/UserInterface/FolderBrowseDialog/FolderDialog.cs @@ -30,11 +30,13 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog /// public string Folder { get; set; } + /// public DialogResult ShowDialog() { return ShowDialog(owner: new WindowWrapper(IntPtr.Zero)); } + /// public DialogResult ShowDialog(IWin32Window owner) { if (Environment.OSVersion.Version.Major >= 6) @@ -47,6 +49,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog } } + /// public DialogResult ShowVistaDialog(IWin32Window owner) { NativeMethods.IFileDialog frm = (NativeMethods.IFileDialog)new NativeMethods.FileOpenDialogRCW(); @@ -110,6 +113,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog return DialogResult.Cancel; } + /// public DialogResult ShowLegacyDialog(IWin32Window owner) { using SaveFileDialog frm = new SaveFileDialog @@ -139,6 +143,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog } } + /// public void Dispose() { Dispose(true); diff --git a/UserInterface/FolderBrowseDialog/WindowWrapper.cs b/UserInterface/FolderBrowseDialog/WindowWrapper.cs index 9311a3b..1995d7e 100644 --- a/UserInterface/FolderBrowseDialog/WindowWrapper.cs +++ b/UserInterface/FolderBrowseDialog/WindowWrapper.cs @@ -6,22 +6,23 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog { using System; + /// + /// WindowWrapper. + /// public class WindowWrapper : System.Windows.Forms.IWin32Window { - private readonly IntPtr hwnd; - /// /// Initializes a new instance of the class. /// /// Handle to wrap. public WindowWrapper(IntPtr handle) { - hwnd = handle; + Handle = handle; } /// /// Gets original ptr. /// - public IntPtr Handle => hwnd; + public IntPtr Handle { get; } } } diff --git a/UserInterface/HotkeyTextboxControl/HotkeyControl.cs b/UserInterface/HotkeyTextboxControl/HotkeyControl.cs index 6caeb2a..c8f6e7e 100644 --- a/UserInterface/HotkeyTextboxControl/HotkeyControl.cs +++ b/UserInterface/HotkeyTextboxControl/HotkeyControl.cs @@ -485,6 +485,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl Redraw(true); } + /// public override string ToString() { return HotkeyToString(HotkeyModifiers, Hotkey); diff --git a/UserInterface/LabelNoCopy.cs b/UserInterface/LabelNoCopy.cs index 526dbaf..c80e347 100644 --- a/UserInterface/LabelNoCopy.cs +++ b/UserInterface/LabelNoCopy.cs @@ -21,6 +21,7 @@ namespace SystemTrayMenu.UserInterface { private string text; + /// public override string Text { get => text; diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 12a1af8..050df6a 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -193,6 +193,7 @@ namespace SystemTrayMenu.UserInterface internal bool IsUsable => Visible && !fading.IsHiding && !IsDisposed && !Disposing; + /// protected override CreateParams CreateParams { get @@ -482,6 +483,7 @@ namespace SystemTrayMenu.UserInterface labelFilesCount.Text = filesCount.ToString(); } + /// protected override bool ProcessCmdKey(ref Message msg, Keys keys) { switch (keys) diff --git a/UserInterface/SettingsForm.cs b/UserInterface/SettingsForm.cs index c84a435..877241e 100644 --- a/UserInterface/SettingsForm.cs +++ b/UserInterface/SettingsForm.cs @@ -18,16 +18,21 @@ namespace SystemTrayMenu.UserInterface using Windows.ApplicationModel; using static SystemTrayMenu.UserInterface.HotkeyTextboxControl.HotkeyControl; + /// + /// SettingsForm. + /// public partial class SettingsForm : Form { private const string MenuName = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder"; private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command"; private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu; - private readonly string newHotKey = string.Empty; private readonly ColorConverter colorConverter = new ColorConverter(); private bool inHotkey; + /// + /// Initializes a new instance of the class. + /// public SettingsForm() { InitializeComponent(); @@ -362,7 +367,10 @@ namespace SystemTrayMenu.UserInterface textBoxColorArrowHoverBackgroundDarkMode.Text = Settings.Default.ColorArrowHoverBackgroundDarkMode; } - public string NewHotKey => newHotKey; + /// + /// Gets NewHotKey. + /// + public string NewHotKey { get; } = string.Empty; /// /// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools. @@ -373,6 +381,7 @@ namespace SystemTrayMenu.UserInterface return RegisterHotkeys(false); } + /// protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) @@ -566,6 +575,15 @@ namespace SystemTrayMenu.UserInterface } } + private static bool IsStartupTask() + { + bool useStartupTask = false; +#if RELEASEPACKAGE + useStartupTask = true; +#endif + return useStartupTask; + } + private void SettingsForm_Load(object sender, EventArgs e) { AdjustControlMultilineIfNecessary(checkBoxStayOpenWhenFocusLost); @@ -931,14 +949,5 @@ namespace SystemTrayMenu.UserInterface e.Handled = e.SuppressKeyPress = true; } } - - private bool IsStartupTask() - { - bool useStartupTask = false; -#if RELEASEPACKAGE - useStartupTask = true; -#endif - return useStartupTask; - } } } diff --git a/Utilities/File/FileIni.cs b/Utilities/File/FileIni.cs index a8167de..0c7d4f5 100644 --- a/Utilities/File/FileIni.cs +++ b/Utilities/File/FileIni.cs @@ -8,10 +8,17 @@ namespace SystemTrayMenu.Utilities using System.IO; using System.Linq; + /// + /// Read *.ini files. + /// public class FileIni { private readonly Dictionary values; + /// + /// Initializes a new instance of the class. + /// + /// path of *.ini file. public FileIni(string path) { values = File.ReadLines(path) @@ -22,6 +29,12 @@ namespace SystemTrayMenu.Utilities parts.Length > 1 ? parts[1].Trim() : null); } + /// + /// Get value of line in *.ini file. + /// + /// attribute name of line. + /// default value. + /// value of attribute name of line. public string Value(string name, string value = null) { if (values != null && values.ContainsKey(name))