Code Cleanup, version 1.0.23.0

This commit is contained in:
Markus Hofknecht 2021-10-23 16:27:53 +02:00
parent 7c234efad6
commit d3e4c655ae
23 changed files with 150 additions and 34 deletions

View file

@ -18,6 +18,9 @@ namespace SystemTrayMenu
private readonly AppNotifyIcon menuNotifyIcon = new AppNotifyIcon(); private readonly AppNotifyIcon menuNotifyIcon = new AppNotifyIcon();
private readonly Menus menus = new Menus(); private readonly Menus menus = new Menus();
/// <summary>
/// Initializes a new instance of the <see cref="App"/> class.
/// </summary>
public App() public App()
{ {
AppRestart.BeforeRestarting += Dispose; AppRestart.BeforeRestarting += Dispose;
@ -36,6 +39,7 @@ namespace SystemTrayMenu
menus.MainPreload(); menus.MainPreload();
} }
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
SystemEvents.DisplaySettingsChanged -= AppRestart.ByDisplaySettings; SystemEvents.DisplaySettingsChanged -= AppRestart.ByDisplaySettings;

View file

@ -41,6 +41,7 @@ namespace SystemTrayMenu.Handler
internal bool InUse { get; set; } internal bool InUse { get; set; }
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
hook.Dispose(); hook.Dispose();

View file

@ -281,6 +281,7 @@ namespace SystemTrayMenu.Business
private List<Menu> AsList => AsEnumerable.ToList(); private List<Menu> AsList => AsEnumerable.ToList();
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
workerMainMenu.Dispose(); workerMainMenu.Dispose();

View file

@ -20,6 +20,7 @@ namespace SystemTrayMenu.Handler
public event EventHandlerEmpty LeaveTriggered; public event EventHandlerEmpty LeaveTriggered;
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
timerLeaveCheck.Dispose(); timerLeaveCheck.Dispose();

View file

@ -39,6 +39,7 @@ namespace SystemTrayMenu.Handler
internal bool MouseActive { get; set; } internal bool MouseActive { get; set; }
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
timerStartLoad.Stop(); timerStartLoad.Stop();

View file

@ -13,6 +13,9 @@ namespace SystemTrayMenu.DataClasses
using SystemTrayMenu.Utilities; using SystemTrayMenu.Utilities;
using Menu = SystemTrayMenu.UserInterface.Menu; using Menu = SystemTrayMenu.UserInterface.Menu;
/// <summary>
/// Contains data of row.
/// </summary>
internal class RowData internal class RowData
{ {
private static readonly Icon White50PercentageIcon = Properties.Resources.White50Percentage; private static readonly Icon White50PercentageIcon = Properties.Resources.White50Percentage;
@ -23,43 +26,97 @@ namespace SystemTrayMenu.DataClasses
private string text; private string text;
private Icon icon; private Icon icon;
/// <summary>
/// Initializes a new instance of the <see cref="RowData"/> class.
/// </summary>
internal RowData() internal RowData()
{ {
} }
/// <summary>
/// Gets or sets fileInfo.
/// </summary>
internal FileInfo FileInfo { get; set; } internal FileInfo FileInfo { get; set; }
/// <summary>
/// Gets or sets SubMenu.
/// </summary>
internal Menu SubMenu { get; set; } internal Menu SubMenu { get; set; }
/// <summary>
/// Gets or sets a value indicating whether IsMenuOpen.
/// </summary>
internal bool IsMenuOpen { get; set; } internal bool IsMenuOpen { get; set; }
/// <summary>
/// Gets or sets a value indicating whether IsSelected.
/// </summary>
internal bool IsSelected { get; set; } internal bool IsSelected { get; set; }
/// <summary>
/// Gets or sets a value indicating whether ContainsMenu.
/// </summary>
internal bool ContainsMenu { get; set; } internal bool ContainsMenu { get; set; }
/// <summary>
/// Gets or sets a value indicating whether IsContextMenuOpen.
/// </summary>
internal bool IsContextMenuOpen { get; set; } internal bool IsContextMenuOpen { get; set; }
/// <summary>
/// Gets or sets a value indicating whether IsResolvedLnk.
/// </summary>
internal bool IsResolvedLnk { get; set; } internal bool IsResolvedLnk { get; set; }
/// <summary>
/// Gets or sets a value indicating whether is a HiddenEntry.
/// </summary>
internal bool HiddenEntry { get; set; } internal bool HiddenEntry { get; set; }
/// <summary>
/// Gets or sets TargetFilePath.
/// </summary>
internal string TargetFilePath { get; set; } internal string TargetFilePath { get; set; }
/// <summary>
/// Gets or sets TargetFilePathOrig.
/// </summary>
internal string TargetFilePathOrig { get; set; } internal string TargetFilePathOrig { get; set; }
/// <summary>
/// Gets or sets RowIndex.
/// </summary>
internal int RowIndex { get; set; } internal int RowIndex { get; set; }
/// <summary>
/// Gets or sets MenuLevel.
/// </summary>
internal int MenuLevel { get; set; } internal int MenuLevel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether IconLoading.
/// </summary>
internal bool IconLoading { get; set; } internal bool IconLoading { get; set; }
/// <summary>
/// Gets or sets FilePathIcon.
/// </summary>
internal string FilePathIcon { get; set; } internal string FilePathIcon { get; set; }
/// <summary>
/// Set text of row.
/// </summary>
/// <param name="text">text of row.</param>
internal void SetText(string text) internal void SetText(string text)
{ {
this.text = text; this.text = text;
} }
/// <summary>
/// SetData.
/// </summary>
/// <param name="data">data.</param>
/// <param name="dataTable">dataTable.</param>
internal void SetData(RowData data, DataTable dataTable) internal void SetData(RowData data, DataTable dataTable)
{ {
DataRow row = dataTable.Rows.Add(); DataRow row = dataTable.Rows.Add();
@ -87,6 +144,12 @@ namespace SystemTrayMenu.DataClasses
row[2] = data; row[2] = data;
} }
/// <summary>
/// ReadIcon.
/// </summary>
/// <param name="isDirectory">isDirectory.</param>
/// <param name="resolvedLnkPath">resolvedLnkPath.</param>
/// <returns>isLnkDirectory.</returns>
internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
{ {
bool isLnkDirectory = false; bool isLnkDirectory = false;
@ -150,6 +213,12 @@ namespace SystemTrayMenu.DataClasses
return isLnkDirectory; return isLnkDirectory;
} }
/// <summary>
/// MouseDown.
/// </summary>
/// <param name="dgv">dgv.</param>
/// <param name="e">e.</param>
/// <param name="toCloseByDoubleClick">toCloseByDoubleClick.</param>
internal void MouseDown(DataGridView dgv, MouseEventArgs e, out bool toCloseByDoubleClick) internal void MouseDown(DataGridView dgv, MouseEventArgs e, out bool toCloseByDoubleClick)
{ {
toCloseByDoubleClick = false; toCloseByDoubleClick = false;
@ -191,6 +260,11 @@ namespace SystemTrayMenu.DataClasses
} }
} }
/// <summary>
/// DoubleClick.
/// </summary>
/// <param name="e">e.</param>
/// <param name="toCloseByDoubleClick">toCloseByDoubleClick.</param>
internal void DoubleClick(MouseEventArgs e, out bool toCloseByDoubleClick) internal void DoubleClick(MouseEventArgs e, out bool toCloseByDoubleClick)
{ {
toCloseByDoubleClick = false; toCloseByDoubleClick = false;
@ -209,6 +283,10 @@ namespace SystemTrayMenu.DataClasses
} }
} }
/// <summary>
/// ReadLoadedIcon.
/// </summary>
/// <returns>Icon.</returns>
internal Icon ReadLoadedIcon() internal Icon ReadLoadedIcon()
{ {
if (ContainsMenu) if (ContainsMenu)

View file

@ -5,9 +5,4 @@
using System.Diagnostics.CodeAnalysis; 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.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")] [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Standard codecleanup removes the this")]

View file

@ -28,6 +28,7 @@ namespace SystemTrayMenu.Helper
internal event Action<object, DataGridViewCellEventArgs> RowMouseLeave; internal event Action<object, DataGridViewCellEventArgs> RowMouseLeave;
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);

View file

@ -51,6 +51,7 @@ namespace SystemTrayMenu.UserInterface
internal bool IsHiding => state == FadingState.Hide; internal bool IsHiding => state == FadingState.Hide;
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);

View file

@ -12,16 +12,15 @@ namespace SystemTrayMenu.Helper
/// </summary> /// </summary>
internal class KeyPressedEventArgs : EventArgs internal class KeyPressedEventArgs : EventArgs
{ {
private readonly KeyboardHookModifierKeys modifier;
private readonly Keys key; private readonly Keys key;
internal KeyPressedEventArgs(KeyboardHookModifierKeys modifier, Keys key) internal KeyPressedEventArgs(KeyboardHookModifierKeys modifier, Keys key)
{ {
this.modifier = modifier; this.Modifier = modifier;
this.key = key; this.key = key;
} }
internal KeyboardHookModifierKeys Modifier => modifier; internal KeyboardHookModifierKeys Modifier { get; }
internal Keys Key => key; internal Keys Key => key;
} }

View file

@ -41,6 +41,7 @@ namespace SystemTrayMenu.Helper
/// </summary> /// </summary>
internal event EventHandler<KeyPressedEventArgs> KeyPressed; internal event EventHandler<KeyPressedEventArgs> KeyPressed;
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
// unregister all the registered hot keys. // unregister all the registered hot keys.

View file

@ -8,6 +8,7 @@ namespace SystemTrayMenu.Helper
internal class WindowsExplorerSort : IComparer<string> internal class WindowsExplorerSort : IComparer<string>
{ {
/// <inheritdoc/>
public int Compare(string x, string y) public int Compare(string x, string y)
{ {
return DllImports.NativeMethods.ShlwapiStrCmpLogicalW(x, y); return DllImports.NativeMethods.ShlwapiStrCmpLogicalW(x, y);

View file

@ -31,7 +31,6 @@ namespace SystemTrayMenu.UserInterface
private string entryAssemblyName; private string entryAssemblyName;
private string callingAssemblyName; private string callingAssemblyName;
private string executingAssemblyName; private string executingAssemblyName;
private Assembly entryAssembly;
private NameValueCollection entryAssemblyAttribCollection; private NameValueCollection entryAssemblyAttribCollection;
public AboutBox() public AboutBox()
@ -49,11 +48,7 @@ namespace SystemTrayMenu.UserInterface
// This is usually read-only, but in some weird cases (Smart Client apps) // 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. // you won't have an entry assembly, so you may want to set this manually.
// </remarks> // </remarks>
public Assembly AppEntryAssembly public Assembly AppEntryAssembly { get; set; }
{
get => entryAssembly;
set => entryAssembly = value;
}
// <summary> // <summary>
// single line of text to show in the application title section of the about box dialog // 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() private void PopulateLabels()
{ {
// get entry assembly attribs // get entry assembly attribs
entryAssemblyAttribCollection = AssemblyAttribs(entryAssembly); entryAssemblyAttribCollection = AssemblyAttribs(AppEntryAssembly);
// set icon from parent, if present // set icon from parent, if present
if (Owner != null) if (Owner != null)
@ -646,14 +641,14 @@ namespace SystemTrayMenu.UserInterface
private void AboutBox_Load(object sender, EventArgs e) 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 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; executingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;

View file

@ -80,6 +80,7 @@ namespace SystemTrayMenu.UserInterface
public event EventHandlerEmpty Exit; public event EventHandlerEmpty Exit;
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
notifyIcon.Icon = null; notifyIcon.Icon = null;

View file

@ -141,6 +141,7 @@ namespace SystemTrayMenu.UserInterface
public int Delta => Value - lastValue; public int Delta => Value - lastValue;
/// <inheritdoc/>
public override bool AutoSize public override bool AutoSize
{ {
get => base.AutoSize; get => base.AutoSize;
@ -207,12 +208,14 @@ namespace SystemTrayMenu.UserInterface
Invalidate(); Invalidate();
} }
/// <inheritdoc/>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
timerMouseStillClicked.Dispose(); timerMouseStillClicked.Dispose();
base.Dispose(disposing); base.Dispose(disposing);
} }
/// <inheritdoc/>
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)
{ {
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

View file

@ -9,6 +9,7 @@ namespace SystemTrayMenu.UserInterface
internal class ScrollbarControlDesigner : ControlDesigner internal class ScrollbarControlDesigner : ControlDesigner
{ {
/// <inheritdoc/>
public override SelectionRules SelectionRules public override SelectionRules SelectionRules
{ {
get get

View file

@ -30,11 +30,13 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
/// </summary> /// </summary>
public string Folder { get; set; } public string Folder { get; set; }
/// <inheritdoc/>
public DialogResult ShowDialog() public DialogResult ShowDialog()
{ {
return ShowDialog(owner: new WindowWrapper(IntPtr.Zero)); return ShowDialog(owner: new WindowWrapper(IntPtr.Zero));
} }
/// <inheritdoc/>
public DialogResult ShowDialog(IWin32Window owner) public DialogResult ShowDialog(IWin32Window owner)
{ {
if (Environment.OSVersion.Version.Major >= 6) if (Environment.OSVersion.Version.Major >= 6)
@ -47,6 +49,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
} }
} }
/// <inheritdoc/>
public DialogResult ShowVistaDialog(IWin32Window owner) public DialogResult ShowVistaDialog(IWin32Window owner)
{ {
NativeMethods.IFileDialog frm = (NativeMethods.IFileDialog)new NativeMethods.FileOpenDialogRCW(); NativeMethods.IFileDialog frm = (NativeMethods.IFileDialog)new NativeMethods.FileOpenDialogRCW();
@ -110,6 +113,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
return DialogResult.Cancel; return DialogResult.Cancel;
} }
/// <inheritdoc/>
public DialogResult ShowLegacyDialog(IWin32Window owner) public DialogResult ShowLegacyDialog(IWin32Window owner)
{ {
using SaveFileDialog frm = new SaveFileDialog using SaveFileDialog frm = new SaveFileDialog
@ -139,6 +143,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
} }
} }
/// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);

View file

@ -6,22 +6,23 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
{ {
using System; using System;
/// <summary>
/// WindowWrapper.
/// </summary>
public class WindowWrapper : System.Windows.Forms.IWin32Window public class WindowWrapper : System.Windows.Forms.IWin32Window
{ {
private readonly IntPtr hwnd;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WindowWrapper"/> class. /// Initializes a new instance of the <see cref="WindowWrapper"/> class.
/// </summary> /// </summary>
/// <param name="handle">Handle to wrap.</param> /// <param name="handle">Handle to wrap.</param>
public WindowWrapper(IntPtr handle) public WindowWrapper(IntPtr handle)
{ {
hwnd = handle; Handle = handle;
} }
/// <summary> /// <summary>
/// Gets original ptr. /// Gets original ptr.
/// </summary> /// </summary>
public IntPtr Handle => hwnd; public IntPtr Handle { get; }
} }
} }

View file

@ -485,6 +485,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
Redraw(true); Redraw(true);
} }
/// <inheritdoc/>
public override string ToString() public override string ToString()
{ {
return HotkeyToString(HotkeyModifiers, Hotkey); return HotkeyToString(HotkeyModifiers, Hotkey);

View file

@ -21,6 +21,7 @@ namespace SystemTrayMenu.UserInterface
{ {
private string text; private string text;
/// <inheritdoc/>
public override string Text public override string Text
{ {
get => text; get => text;

View file

@ -193,6 +193,7 @@ namespace SystemTrayMenu.UserInterface
internal bool IsUsable => Visible && !fading.IsHiding && internal bool IsUsable => Visible && !fading.IsHiding &&
!IsDisposed && !Disposing; !IsDisposed && !Disposing;
/// <inheritdoc/>
protected override CreateParams CreateParams protected override CreateParams CreateParams
{ {
get get
@ -482,6 +483,7 @@ namespace SystemTrayMenu.UserInterface
labelFilesCount.Text = filesCount.ToString(); labelFilesCount.Text = filesCount.ToString();
} }
/// <inheritdoc/>
protected override bool ProcessCmdKey(ref Message msg, Keys keys) protected override bool ProcessCmdKey(ref Message msg, Keys keys)
{ {
switch (keys) switch (keys)

View file

@ -18,16 +18,21 @@ namespace SystemTrayMenu.UserInterface
using Windows.ApplicationModel; using Windows.ApplicationModel;
using static SystemTrayMenu.UserInterface.HotkeyTextboxControl.HotkeyControl; using static SystemTrayMenu.UserInterface.HotkeyTextboxControl.HotkeyControl;
/// <summary>
/// SettingsForm.
/// </summary>
public partial class SettingsForm : Form public partial class SettingsForm : Form
{ {
private const string MenuName = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder"; private const string MenuName = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder";
private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command"; private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command";
private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu; private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu;
private readonly string newHotKey = string.Empty;
private readonly ColorConverter colorConverter = new ColorConverter(); private readonly ColorConverter colorConverter = new ColorConverter();
private bool inHotkey; private bool inHotkey;
/// <summary>
/// Initializes a new instance of the <see cref="SettingsForm"/> class.
/// </summary>
public SettingsForm() public SettingsForm()
{ {
InitializeComponent(); InitializeComponent();
@ -362,7 +367,10 @@ namespace SystemTrayMenu.UserInterface
textBoxColorArrowHoverBackgroundDarkMode.Text = Settings.Default.ColorArrowHoverBackgroundDarkMode; textBoxColorArrowHoverBackgroundDarkMode.Text = Settings.Default.ColorArrowHoverBackgroundDarkMode;
} }
public string NewHotKey => newHotKey; /// <summary>
/// Gets NewHotKey.
/// </summary>
public string NewHotKey { get; } = string.Empty;
/// <summary> /// <summary>
/// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools. /// 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); return RegisterHotkeys(false);
} }
/// <inheritdoc/>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ {
switch (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) private void SettingsForm_Load(object sender, EventArgs e)
{ {
AdjustControlMultilineIfNecessary(checkBoxStayOpenWhenFocusLost); AdjustControlMultilineIfNecessary(checkBoxStayOpenWhenFocusLost);
@ -931,14 +949,5 @@ namespace SystemTrayMenu.UserInterface
e.Handled = e.SuppressKeyPress = true; e.Handled = e.SuppressKeyPress = true;
} }
} }
private bool IsStartupTask()
{
bool useStartupTask = false;
#if RELEASEPACKAGE
useStartupTask = true;
#endif
return useStartupTask;
}
} }
} }

View file

@ -8,10 +8,17 @@ namespace SystemTrayMenu.Utilities
using System.IO; using System.IO;
using System.Linq; using System.Linq;
/// <summary>
/// Read *.ini files.
/// </summary>
public class FileIni public class FileIni
{ {
private readonly Dictionary<string, string> values; private readonly Dictionary<string, string> values;
/// <summary>
/// Initializes a new instance of the <see cref="FileIni"/> class.
/// </summary>
/// <param name="path">path of *.ini file.</param>
public FileIni(string path) public FileIni(string path)
{ {
values = File.ReadLines(path) values = File.ReadLines(path)
@ -22,6 +29,12 @@ namespace SystemTrayMenu.Utilities
parts.Length > 1 ? parts[1].Trim() : null); parts.Length > 1 ? parts[1].Trim() : null);
} }
/// <summary>
/// Get value of line in *.ini file.
/// </summary>
/// <param name="name">attribute name of line.</param>
/// <param name="value">default value.</param>
/// <returns>value of attribute name of line.</returns>
public string Value(string name, string value = null) public string Value(string name, string value = null)
{ {
if (values != null && values.ContainsKey(name)) if (values != null && values.ContainsKey(name))