[Feature] CodeBuity&Refactor #49, [Feature] Code review tool #10

This commit is contained in:
Markus Hofknecht 2020-03-23 12:35:10 +01:00
parent 039fd92e26
commit 3ead0424d2
15 changed files with 61 additions and 60 deletions

View file

@ -801,8 +801,8 @@ namespace SystemTrayMenu.Controls
// </summary> // </summary>
private class ListViewItemComparer : System.Collections.IComparer private class ListViewItemComparer : System.Collections.IComparer
{ {
private int _intCol; private readonly int _intCol;
private bool _IsAscending = true; private readonly bool _IsAscending = true;
public ListViewItemComparer() public ListViewItemComparer()
{ {

View file

@ -17,12 +17,13 @@ namespace SystemTrayMenu
public event EventHandler Restart; public event EventHandler Restart;
public event EventHandler Exit; public event EventHandler Exit;
private NotifyIcon notifyIcon = new NotifyIcon(); private readonly NotifyIcon notifyIcon = new NotifyIcon();
private DateTime timeLoadingStart; private DateTime timeLoadingStart;
private int threadsLoading = 0; private int threadsLoading = 0;
private Timer load = new Timer(); private readonly Timer load = new Timer();
private int loadCount = 0, indexLoad = 0; private int loadCount = 0;
private List<Icon> bitmapsLoading = new List<Icon>() { R.L010, R.L020, R.L030, private readonly int indexLoad = 0;
private readonly List<Icon> bitmapsLoading = new List<Icon>() { R.L010, R.L020, R.L030,
R.L040, R.L050, R.L060, R.L070, R.L080, R.L090, R.L100, R.L110, R.L120, R.L040, R.L050, R.L060, R.L070, R.L080, R.L090, R.L100, R.L110, R.L120,
R.L130, R.L140, R.L150, R.L160, R.L170, R.L180}; R.L130, R.L140, R.L150, R.L160, R.L170, R.L180};

View file

@ -42,7 +42,7 @@ namespace SystemTrayMenu
} }
public int Level = 0; public int Level = 0;
private FadeForm FadeForm = null; private readonly FadeForm FadeForm = null;
private bool autoResizeRowsDone = false; private bool autoResizeRowsDone = false;
public enum MenuType { Default, DisposedFake }; public enum MenuType { Default, DisposedFake };

View file

@ -37,8 +37,8 @@ namespace SystemTrayMenu.Controls
public string TargetFilePathOrig; public string TargetFilePathOrig;
public string Text; public string Text;
public int RowIndex; public int RowIndex;
private WaitMenuOpen waitMenuOpen = new WaitMenuOpen(); private readonly WaitMenuOpen waitMenuOpen = new WaitMenuOpen();
private Icon icon = null; private readonly Icon icon = null;
private bool isDisposed = false; private bool isDisposed = false;
public RowData() public RowData()

View file

@ -14,9 +14,9 @@ namespace SystemTrayMenu.Handler
public Action<int, int, DataGridView> RowDeselected; public Action<int, int, DataGridView> RowDeselected;
public event EventHandler Cleared; public event EventHandler Cleared;
private Menu[] menus; private readonly Menu[] menus;
private KeyboardHook hook = new KeyboardHook(); private readonly KeyboardHook hook = new KeyboardHook();
private Timer timerKeySearch = new Timer(); private readonly Timer timerKeySearch = new Timer();
public int iRowKey = -1; public int iRowKey = -1;
public int iMenuKey = 0; public int iMenuKey = 0;
private string KeySearchString = string.Empty; private string KeySearchString = string.Empty;

View file

@ -7,7 +7,7 @@ namespace SystemTrayMenu.Handler
{ {
public event EventHandler Leave; public event EventHandler Leave;
private Timer timerSecondLeaveCheck = new Timer(); private readonly Timer timerSecondLeaveCheck = new Timer();
public WaitFastLeave() public WaitFastLeave()
{ {

View file

@ -7,7 +7,7 @@ namespace SystemTrayMenu.Handler
{ {
public event EventHandler DoOpen; public event EventHandler DoOpen;
private Timer waitOpen = new Timer(); private readonly Timer waitOpen = new Timer();
private bool waitedDone = false; private bool waitedDone = false;
private bool clicked = false; private bool clicked = false;
private bool menuLoaded = false; private bool menuLoaded = false;

View file

@ -22,10 +22,10 @@ namespace SystemTrayMenu
} }
} }
private Timer timerFadeIn = new Timer(); private readonly Timer timerFadeIn = new Timer();
private Timer timerFadeOut = new Timer(); private readonly Timer timerFadeOut = new Timer();
private Timer timerFadeHalf = new Timer(); private readonly Timer timerFadeHalf = new Timer();
private Form form = null; private readonly Form form = null;
private bool stopFadeInByHalf = false; private bool stopFadeInByHalf = false;
public FadeForm(Form form) public FadeForm(Form form)

View file

@ -7,11 +7,11 @@ namespace SystemTrayMenu.Helper
{ {
public class FileIni public class FileIni
{ {
private Dictionary<string, string> values; private readonly Dictionary<string, string> values;
public FileIni(string path) public FileIni(string path)
{ {
values = File.ReadLines(path) values = File.ReadLines(path)
.Where(line => (!String.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))) .Where(line => (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")))
.Select(line => line.Split(new char[] { '=' }, 2, 0)) .Select(line => line.Split(new char[] { '=' }, 2, 0))
.ToDictionary(parts => parts[0].Trim(), parts => parts.Length > 1 ? parts[1].Trim() : null); .ToDictionary(parts => parts[0].Trim(), parts => parts.Length > 1 ? parts[1].Trim() : null);
} }

View file

@ -19,7 +19,7 @@ namespace SystemTrayMenu.Helper
/// </example> /// </example>
public class IconReader public class IconReader
{ {
private static ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>(); private static readonly ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>();
/// <summary> /// <summary>
/// Options to specify the size of icons to return. /// Options to specify the size of icons to return.

View file

@ -18,7 +18,7 @@ namespace SystemTrayMenu.Helper
/// </summary> /// </summary>
private class Window : NativeWindow, IDisposable private class Window : NativeWindow, IDisposable
{ {
private static int WM_HOTKEY = 0x0312; private static readonly int WM_HOTKEY = 0x0312;
public Window() public Window()
{ {
@ -61,7 +61,7 @@ namespace SystemTrayMenu.Helper
#endregion #endregion
} }
private Window _window = new Window(); private readonly Window _window = new Window();
private int _currentId; private int _currentId;
public KeyboardHook() public KeyboardHook()
@ -120,8 +120,8 @@ namespace SystemTrayMenu.Helper
/// </summary> /// </summary>
public class KeyPressedEventArgs : EventArgs public class KeyPressedEventArgs : EventArgs
{ {
private KeyboardHookModifierKeys _modifier; private readonly KeyboardHookModifierKeys _modifier;
private Keys _key; private readonly Keys _key;
internal KeyPressedEventArgs(KeyboardHookModifierKeys modifier, Keys key) internal KeyPressedEventArgs(KeyboardHookModifierKeys modifier, Keys key)
{ {

View file

@ -8,7 +8,7 @@ namespace SystemTrayMenu.Helper
{ {
internal static class Log internal static class Log
{ {
private static Logger log = new Logger(""); private static readonly Logger log = new Logger("");
internal static void Initialize() internal static void Initialize()
{ {
Logger.Start(new FileInfo(GetLogFilePath())); Logger.Start(new FileInfo(GetLogFilePath()));

View file

@ -630,8 +630,8 @@ namespace SystemTrayMenu.Helper
private const int S_OK = 0; private const int S_OK = 0;
private const int S_FALSE = 1; private const int S_FALSE = 1;
private static int cbMenuItemInfo = Marshal.SizeOf(typeof(MENUITEMINFO)); private static readonly int cbMenuItemInfo = Marshal.SizeOf(typeof(MENUITEMINFO));
private static int cbInvokeCommand = Marshal.SizeOf(typeof(CMINVOKECOMMANDINFOEX)); private static readonly int cbInvokeCommand = Marshal.SizeOf(typeof(CMINVOKECOMMANDINFOEX));
#endregion #endregion
@ -639,11 +639,11 @@ namespace SystemTrayMenu.Helper
// Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace. // Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace.
[DllImport("shell32.dll")] [DllImport("shell32.dll")]
private static extern Int32 SHGetDesktopFolder(out IntPtr ppshf); private static extern int SHGetDesktopFolder(out IntPtr ppshf);
// Takes a STRRET structure returned by IShellFolder::GetDisplayNameOf, converts it to a string, and places the result in a buffer. // Takes a STRRET structure returned by IShellFolder::GetDisplayNameOf, converts it to a string, and places the result in a buffer.
[DllImport("shlwapi.dll", EntryPoint = "StrRetToBuf", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] [DllImport("shlwapi.dll", EntryPoint = "StrRetToBuf", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern Int32 StrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf); private static extern int StrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf);
// The TrackPopupMenuEx function displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. The shortcut menu can appear anywhere on the screen. // The TrackPopupMenuEx function displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. The shortcut menu can appear anywhere on the screen.
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
@ -1227,7 +1227,7 @@ namespace SystemTrayMenu.Helper
// Translates a file object's or folder's display name into an item identifier list. // Translates a file object's or folder's display name into an item identifier list.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 ParseDisplayName( int ParseDisplayName(
IntPtr hwnd, IntPtr hwnd,
IntPtr pbc, IntPtr pbc,
[MarshalAs(UnmanagedType.LPWStr)] [MarshalAs(UnmanagedType.LPWStr)]
@ -1240,7 +1240,7 @@ namespace SystemTrayMenu.Helper
// identifier enumeration object and returning its IEnumIDList interface. // identifier enumeration object and returning its IEnumIDList interface.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 EnumObjects( int EnumObjects(
IntPtr hwnd, IntPtr hwnd,
SHCONTF grfFlags, SHCONTF grfFlags,
out IntPtr enumIDList); out IntPtr enumIDList);
@ -1248,7 +1248,7 @@ namespace SystemTrayMenu.Helper
// Retrieves an IShellFolder object for a subfolder. // Retrieves an IShellFolder object for a subfolder.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 BindToObject( int BindToObject(
IntPtr pidl, IntPtr pidl,
IntPtr pbc, IntPtr pbc,
ref Guid riid, ref Guid riid,
@ -1257,7 +1257,7 @@ namespace SystemTrayMenu.Helper
// Requests a pointer to an object's storage interface. // Requests a pointer to an object's storage interface.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 BindToStorage( int BindToStorage(
IntPtr pidl, IntPtr pidl,
IntPtr pbc, IntPtr pbc,
ref Guid riid, ref Guid riid,
@ -1274,7 +1274,7 @@ namespace SystemTrayMenu.Helper
// follow the second (pidl1 > pidl2). Zero A return value of zero // follow the second (pidl1 > pidl2). Zero A return value of zero
// indicates that the two items are the same (pidl1 = pidl2). // indicates that the two items are the same (pidl1 = pidl2).
[PreserveSig] [PreserveSig]
Int32 CompareIDs( int CompareIDs(
IntPtr lParam, IntPtr lParam,
IntPtr pidl1, IntPtr pidl1,
IntPtr pidl2); IntPtr pidl2);
@ -1283,7 +1283,7 @@ namespace SystemTrayMenu.Helper
// with a folder object. // with a folder object.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 CreateViewObject( int CreateViewObject(
IntPtr hwndOwner, IntPtr hwndOwner,
Guid riid, Guid riid,
out IntPtr ppv); out IntPtr ppv);
@ -1291,7 +1291,7 @@ namespace SystemTrayMenu.Helper
// Retrieves the attributes of one or more file objects or subfolders. // Retrieves the attributes of one or more file objects or subfolders.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 GetAttributesOf( int GetAttributesOf(
uint cidl, uint cidl,
[MarshalAs(UnmanagedType.LPArray)] [MarshalAs(UnmanagedType.LPArray)]
IntPtr[] apidl, IntPtr[] apidl,
@ -1301,7 +1301,7 @@ namespace SystemTrayMenu.Helper
// specified file objects or folders. // specified file objects or folders.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 GetUIObjectOf( int GetUIObjectOf(
IntPtr hwndOwner, IntPtr hwndOwner,
uint cidl, uint cidl,
[MarshalAs(UnmanagedType.LPArray)] [MarshalAs(UnmanagedType.LPArray)]
@ -1313,7 +1313,7 @@ namespace SystemTrayMenu.Helper
// Retrieves the display name for the specified file object or subfolder. // Retrieves the display name for the specified file object or subfolder.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig()] [PreserveSig()]
Int32 GetDisplayNameOf( int GetDisplayNameOf(
IntPtr pidl, IntPtr pidl,
SHGNO uFlags, SHGNO uFlags,
IntPtr lpName); IntPtr lpName);
@ -1322,7 +1322,7 @@ namespace SystemTrayMenu.Helper
// identifier in the process. // identifier in the process.
// Return value: error code, if any // Return value: error code, if any
[PreserveSig] [PreserveSig]
Int32 SetNameOf( int SetNameOf(
IntPtr hwnd, IntPtr hwnd,
IntPtr pidl, IntPtr pidl,
[MarshalAs(UnmanagedType.LPWStr)] [MarshalAs(UnmanagedType.LPWStr)]
@ -1340,7 +1340,7 @@ namespace SystemTrayMenu.Helper
{ {
// Adds commands to a shortcut menu // Adds commands to a shortcut menu
[PreserveSig()] [PreserveSig()]
Int32 QueryContextMenu( int QueryContextMenu(
IntPtr hmenu, IntPtr hmenu,
uint iMenu, uint iMenu,
uint idCmdFirst, uint idCmdFirst,
@ -1349,14 +1349,14 @@ namespace SystemTrayMenu.Helper
// Carries out the command associated with a shortcut menu item // Carries out the command associated with a shortcut menu item
[PreserveSig()] [PreserveSig()]
Int32 InvokeCommand( int InvokeCommand(
ref CMINVOKECOMMANDINFOEX info); ref CMINVOKECOMMANDINFOEX info);
// Retrieves information about a shortcut menu command, // Retrieves information about a shortcut menu command,
// including the help string and the language-independent, // including the help string and the language-independent,
// or canonical, name for the command // or canonical, name for the command
[PreserveSig()] [PreserveSig()]
Int32 GetCommandString( int GetCommandString(
uint idcmd, uint idcmd,
GCS uflags, GCS uflags,
uint reserved, uint reserved,
@ -1371,7 +1371,7 @@ namespace SystemTrayMenu.Helper
{ {
// Adds commands to a shortcut menu // Adds commands to a shortcut menu
[PreserveSig()] [PreserveSig()]
Int32 QueryContextMenu( int QueryContextMenu(
IntPtr hmenu, IntPtr hmenu,
uint iMenu, uint iMenu,
uint idCmdFirst, uint idCmdFirst,
@ -1380,14 +1380,14 @@ namespace SystemTrayMenu.Helper
// Carries out the command associated with a shortcut menu item // Carries out the command associated with a shortcut menu item
[PreserveSig()] [PreserveSig()]
Int32 InvokeCommand( int InvokeCommand(
ref CMINVOKECOMMANDINFOEX info); ref CMINVOKECOMMANDINFOEX info);
// Retrieves information about a shortcut menu command, // Retrieves information about a shortcut menu command,
// including the help string and the language-independent, // including the help string and the language-independent,
// or canonical, name for the command // or canonical, name for the command
[PreserveSig()] [PreserveSig()]
Int32 GetCommandString( int GetCommandString(
uint idcmd, uint idcmd,
GCS uflags, GCS uflags,
uint reserved, uint reserved,
@ -1398,7 +1398,7 @@ namespace SystemTrayMenu.Helper
// Allows client objects of the IContextMenu interface to // Allows client objects of the IContextMenu interface to
// handle messages associated with owner-drawn menu items // handle messages associated with owner-drawn menu items
[PreserveSig] [PreserveSig]
Int32 HandleMenuMsg( int HandleMenuMsg(
uint uMsg, uint uMsg,
IntPtr wParam, IntPtr wParam,
IntPtr lParam); IntPtr lParam);
@ -1410,7 +1410,7 @@ namespace SystemTrayMenu.Helper
{ {
// Adds commands to a shortcut menu // Adds commands to a shortcut menu
[PreserveSig()] [PreserveSig()]
Int32 QueryContextMenu( int QueryContextMenu(
IntPtr hmenu, IntPtr hmenu,
uint iMenu, uint iMenu,
uint idCmdFirst, uint idCmdFirst,
@ -1419,14 +1419,14 @@ namespace SystemTrayMenu.Helper
// Carries out the command associated with a shortcut menu item // Carries out the command associated with a shortcut menu item
[PreserveSig()] [PreserveSig()]
Int32 InvokeCommand( int InvokeCommand(
ref CMINVOKECOMMANDINFOEX info); ref CMINVOKECOMMANDINFOEX info);
// Retrieves information about a shortcut menu command, // Retrieves information about a shortcut menu command,
// including the help string and the language-independent, // including the help string and the language-independent,
// or canonical, name for the command // or canonical, name for the command
[PreserveSig()] [PreserveSig()]
Int32 GetCommandString( int GetCommandString(
uint idcmd, uint idcmd,
GCS uflags, GCS uflags,
uint reserved, uint reserved,
@ -1437,7 +1437,7 @@ namespace SystemTrayMenu.Helper
// Allows client objects of the IContextMenu interface to // Allows client objects of the IContextMenu interface to
// handle messages associated with owner-drawn menu items // handle messages associated with owner-drawn menu items
[PreserveSig] [PreserveSig]
Int32 HandleMenuMsg( int HandleMenuMsg(
uint uMsg, uint uMsg,
IntPtr wParam, IntPtr wParam,
IntPtr lParam); IntPtr lParam);
@ -1445,7 +1445,7 @@ namespace SystemTrayMenu.Helper
// Allows client objects of the IContextMenu3 interface to // Allows client objects of the IContextMenu3 interface to
// handle messages associated with owner-drawn menu items // handle messages associated with owner-drawn menu items
[PreserveSig] [PreserveSig]
Int32 HandleMenuMsg2( int HandleMenuMsg2(
uint uMsg, uint uMsg,
IntPtr wParam, IntPtr wParam,
IntPtr lParam, IntPtr lParam,

View file

@ -7,7 +7,7 @@ namespace SystemTrayMenu.Helper
internal class WindowsExplorerSort : IComparer<string> internal class WindowsExplorerSort : IComparer<string>
{ {
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int StrCmpLogicalW(String x, String y); private static extern int StrCmpLogicalW(string x, string y);
public int Compare(string x, string y) public int Compare(string x, string y)
{ {

View file

@ -18,13 +18,13 @@ namespace SystemTrayMenu
private enum OpenCloseState { Default, Opening, Closing }; private enum OpenCloseState { Default, Opening, Closing };
private OpenCloseState openCloseState = OpenCloseState.Default; private OpenCloseState openCloseState = OpenCloseState.Default;
private MessageFilter messageFilter = new MessageFilter(); private readonly MessageFilter messageFilter = new MessageFilter();
private MenuNotifyIcon menuNotifyIcon = null; private readonly MenuNotifyIcon menuNotifyIcon = null;
private Menu[] menus = new Menu[MenuDefines.MenusMax]; private readonly Menu[] menus = new Menu[MenuDefines.MenusMax];
private BackgroundWorker worker = new BackgroundWorker(); private readonly BackgroundWorker worker = new BackgroundWorker();
private Screen screen = Screen.PrimaryScreen; private readonly Screen screen = Screen.PrimaryScreen;
private WaitFastLeave fastLeave = new WaitFastLeave(); private readonly WaitFastLeave fastLeave = new WaitFastLeave();
private KeyboardInput keyboardInput; private readonly KeyboardInput keyboardInput;
private DataGridView dgvFromLastMouseEvent = null; private DataGridView dgvFromLastMouseEvent = null;
private DataGridViewCellEventArgs cellEventArgsFromLastMouseEvent = null; private DataGridViewCellEventArgs cellEventArgsFromLastMouseEvent = null;
private int clicksInQueue = 0; private int clicksInQueue = 0;