From 4a294c7d76d4e11a422fcd15256009b5db89e6a9 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Mon, 18 Nov 2019 20:11:55 +0100 Subject: [PATCH] run visual studio code Cleanup --- Config.cs | 2 +- Controls/AppContextMenu.cs | 2 +- Controls/DragDropHintForm.cs | 9 +-------- Controls/Menu.cs | 10 +++++----- Controls/MenuData.cs | 37 ++++++++++++------------------------ Controls/RowData.cs | 10 +++++----- Helper/File/FileUrl.cs | 1 - Helper/File/IconReader.cs | 2 +- Helper/ScreenMouse.cs | 3 +-- Helper/Taskbar.cs | 2 +- MenuDefines.cs | 2 +- Program.cs | 3 +-- SystemTrayMenuHandler.cs | 32 +++++++++++++++---------------- 13 files changed, 46 insertions(+), 69 deletions(-) diff --git a/Config.cs b/Config.cs index 7a69b27..d17a875 100644 --- a/Config.cs +++ b/Config.cs @@ -61,7 +61,7 @@ namespace SystemTrayMenu if (Directory.Exists(dialog.FileName)) { pathOK = true; - Properties.Settings.Default.PathDirectory = + Properties.Settings.Default.PathDirectory = dialog.FileName; Properties.Settings.Default.Save(); } diff --git a/Controls/AppContextMenu.cs b/Controls/AppContextMenu.cs index 566ba4a..bd8cd0c 100644 --- a/Controls/AppContextMenu.cs +++ b/Controls/AppContextMenu.cs @@ -36,7 +36,7 @@ namespace SystemTrayMenu.Controls Name = "changeLanguage", Text = Program.Translate("Language") }; - foreach (CultureInfo cultureInfo in + foreach (CultureInfo cultureInfo in GetCultureList(CultureTypes.AllCultures)) { if (Program.Languages.Contains(cultureInfo.Name)) diff --git a/Controls/DragDropHintForm.cs b/Controls/DragDropHintForm.cs index 75ffd14..e06fdd3 100644 --- a/Controls/DragDropHintForm.cs +++ b/Controls/DragDropHintForm.cs @@ -1,18 +1,11 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace SystemTrayMenu.Controls { public partial class DragDropHintForm : Form { - public DragDropHintForm(string hintTitle, string hintText, + public DragDropHintForm(string hintTitle, string hintText, string buttonOk) { InitializeComponent(); diff --git a/Controls/Menu.cs b/Controls/Menu.cs index e5d960e..9eec362 100644 --- a/Controls/Menu.cs +++ b/Controls/Menu.cs @@ -156,9 +156,9 @@ namespace SystemTrayMenu { DataGridViewElementStates states = DataGridViewElementStates.None; dgv.AutoResizeRows(); - int height = (int)(dgv.Rows.GetRowsHeight(states)); - int heightMax = screen.Bounds.Height - - new Taskbar().Size.Height - + int height = (int)(dgv.Rows.GetRowsHeight(states)); + int heightMax = screen.Bounds.Height - + new Taskbar().Size.Height - labelTitle.Height; if (height > heightMax) { @@ -185,8 +185,8 @@ namespace SystemTrayMenu this.dgv.Height = height; AdjustDataGridViewSize(); - int x = menuPredecessor.Location.X - Width + - (int)Math.Round(Program.ScalingFactor, 0, + int x = menuPredecessor.Location.X - Width + + (int)Math.Round(Program.ScalingFactor, 0, MidpointRounding.AwayFromZero); RowData trigger = (RowData)Tag; diff --git a/Controls/MenuData.cs b/Controls/MenuData.cs index 0e18477..aa6b81f 100644 --- a/Controls/MenuData.cs +++ b/Controls/MenuData.cs @@ -1,31 +1,18 @@ -using Clearcove.Logging; -using IWshRuntimeLibrary; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Windows.Forms; -using SystemTrayMenu.Helper; -using TAFactory.IconPack; - -namespace SystemTrayMenu.Controls -{ +using System.Collections.Generic; + +namespace SystemTrayMenu.Controls +{ public enum MenuDataValidity { Valid, Invalid, NoAccess - } - - public struct MenuData - { - public List RowDatas; - public MenuDataValidity Validity; - public int Level; - }; + } + + public struct MenuData + { + public List RowDatas; + public MenuDataValidity Validity; + public int Level; + }; } \ No newline at end of file diff --git a/Controls/RowData.cs b/Controls/RowData.cs index b40cac5..644cb69 100644 --- a/Controls/RowData.cs +++ b/Controls/RowData.cs @@ -306,7 +306,7 @@ namespace SystemTrayMenu.Controls // FlatAppearance.BorderColor = BackColor; //} - + } } @@ -343,7 +343,7 @@ namespace SystemTrayMenu.Controls waitMenuOpen.Click(); } - if (e == null || + if (e == null || e.Button == MouseButtons.Left && !ContainsMenu) { @@ -386,7 +386,7 @@ namespace SystemTrayMenu.Controls ShellContextMenu ctxMnu = new ShellContextMenu(); Point location = dgv.FindForm().Location; Point point = new Point( - e.X + location.X + dgv.Location.X, + e.X + location.X + dgv.Location.X, e.Y + location.Y + dgv.Location.Y); if (ContainsMenu) { @@ -474,7 +474,7 @@ namespace SystemTrayMenu.Controls cellIcon.Value = data.Icon; } - DataGridViewTextBoxCell cellName = + DataGridViewTextBoxCell cellName = (DataGridViewTextBoxCell)row.Cells[1]; cellName.Value = data.Text; @@ -488,7 +488,7 @@ namespace SystemTrayMenu.Controls var graphics = Graphics.FromImage(target); graphics.DrawIcon(originalIcon, 0, 0); graphics.DrawIcon(overlay, 0, 0); - target.MakeTransparent(target.GetPixel(1,1)); + target.MakeTransparent(target.GetPixel(1, 1)); return Icon.FromHandle(target.GetHicon()); } diff --git a/Helper/File/FileUrl.cs b/Helper/File/FileUrl.cs index 7dfdaef..b9e84b8 100644 --- a/Helper/File/FileUrl.cs +++ b/Helper/File/FileUrl.cs @@ -1,5 +1,4 @@ using Microsoft.Win32; -using System; namespace SystemTrayMenu.Helper { diff --git a/Helper/File/IconReader.cs b/Helper/File/IconReader.cs index 19c78ad..3757c59 100644 --- a/Helper/File/IconReader.cs +++ b/Helper/File/IconReader.cs @@ -155,7 +155,7 @@ namespace SystemTrayMenu.Helper log.Info($"directoryPath:'{directoryPath}'"); log.Error($"{ex.ToString()}"); } - + // Cleanup User32.DestroyIcon(shfi.hIcon); } diff --git a/Helper/ScreenMouse.cs b/Helper/ScreenMouse.cs index 76a6253..c933c31 100644 --- a/Helper/ScreenMouse.cs +++ b/Helper/ScreenMouse.cs @@ -1,5 +1,4 @@ -using System.Drawing; -using System.Windows.Forms; +using System.Windows.Forms; namespace SystemTrayMenu.Helper { diff --git a/Helper/Taskbar.cs b/Helper/Taskbar.cs index 4147f2f..04b7111 100644 --- a/Helper/Taskbar.cs +++ b/Helper/Taskbar.cs @@ -52,7 +52,7 @@ namespace SystemTrayMenu get; private set; } - + [DllImport("shell32.dll", SetLastError = true)] public static extern IntPtr SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData); diff --git a/MenuDefines.cs b/MenuDefines.cs index 44fc732..3f04bbf 100644 --- a/MenuDefines.cs +++ b/MenuDefines.cs @@ -19,7 +19,7 @@ namespace SystemTrayMenu public const int MenuRowsHeight = 18; public const int LengthMax = 37; public const int ButtonTextPaddingLeft = 18; - public const int ButtonTextPaddingRight= 12; + public const int ButtonTextPaddingRight = 12; public const int Scrollspeed = 4; diff --git a/Program.cs b/Program.cs index 874a6d9..8d33a05 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,4 @@ using Clearcove.Logging; -using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; @@ -55,7 +54,7 @@ namespace SystemTrayMenu try { bool cancelAppRun = false; - using (SystemTrayMenuHandler stm = + using (SystemTrayMenuHandler stm = new SystemTrayMenuHandler(ref cancelAppRun)) { if (!cancelAppRun) diff --git a/SystemTrayMenuHandler.cs b/SystemTrayMenuHandler.cs index 6fb92f0..d46f695 100644 --- a/SystemTrayMenuHandler.cs +++ b/SystemTrayMenuHandler.cs @@ -425,7 +425,7 @@ namespace SystemTrayMenu // Using SHGetSetSettings would be much better in performance but the results are not accurate. // We have to go for the shell interface in order to receive the correct settings: // https://docs.microsoft.com/en-us/windows/win32/shell/ishelldispatch4-getsetting - const int SSF_SHOWALLOBJECTS = 0x00000001; + const int SSF_SHOWALLOBJECTS = 0x00000001; const int SSF_SHOWSUPERHIDDEN = 0x00040000; HideHiddenEntries = !iShellDispatch4.GetSetting(SSF_SHOWALLOBJECTS); @@ -487,9 +487,9 @@ namespace SystemTrayMenu try { - files = Directory.GetFiles(path). Where(p => - !Path.GetFileName(p).Equals("desktop.ini", StringComparison.OrdinalIgnoreCase) && // Windows folder settings, e.g. Win10 "desktop.ini", Win2003 "Desktop.ini" - !Path.GetFileName(p).Equals("thumbs.db", StringComparison.OrdinalIgnoreCase) // Windows thumbnail cache + files = Directory.GetFiles(path).Where(p => + !Path.GetFileName(p).Equals("desktop.ini", StringComparison.OrdinalIgnoreCase) && // Windows folder settings, e.g. Win10 "desktop.ini", Win2003 "Desktop.ini" + !Path.GetFileName(p).Equals("thumbs.db", StringComparison.OrdinalIgnoreCase) // Windows thumbnail cache ).ToArray(); Array.Sort(files, new WindowsExplorerSort()); } @@ -649,7 +649,7 @@ namespace SystemTrayMenu private void CheckMenuOpenerStop(int menuIndex, int rowIndex, DataGridView dgv = null) { Menu menu = menus[menuIndex]; - if (menu != null && + if (menu != null && rowIndex > -1) { if (dgv == null) @@ -698,13 +698,13 @@ namespace SystemTrayMenu RowData rowData = (RowData)row.Tag; if (rowData.IsSelectedByKeyboard) { - row.DefaultCellStyle.SelectionBackColor = + row.DefaultCellStyle.SelectionBackColor = MenuDefines.KeyBoardSelection; row.Selected = true; } else if (rowData.IsSelected) { - row.DefaultCellStyle.SelectionBackColor = + row.DefaultCellStyle.SelectionBackColor = MenuDefines.FolderOpen; row.Selected = true; } @@ -829,7 +829,7 @@ namespace SystemTrayMenu private bool IsAnyMenuSelectedByKey( ref DataGridView dgv, - ref Menu menuFromSelected, + ref Menu menuFromSelected, ref string textselected) { Menu menu = menus[iMenuKey]; @@ -933,7 +933,7 @@ namespace SystemTrayMenu if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { - CheckMenuOpenerStop(iMenuBefore, + CheckMenuOpenerStop(iMenuBefore, iRowBefore, dgvBefore); CheckMenuOpenerStart(dgv, iRowKey); toClear = true; @@ -1031,10 +1031,10 @@ namespace SystemTrayMenu { ClearIsSelectedByKey(iMenuBefore, iRowBefore); } - + } - private bool SelectMatched(DataGridView dgv, + private bool SelectMatched(DataGridView dgv, int indexStart, string keyInput = "") { bool found = false; @@ -1049,7 +1049,7 @@ namespace SystemTrayMenu return found; } - private bool SelectMatchedReverse(DataGridView dgv, + private bool SelectMatchedReverse(DataGridView dgv, int indexStart, string keyInput = "") { bool found = false; @@ -1064,7 +1064,7 @@ namespace SystemTrayMenu return found; } - private bool Select(DataGridView dgv, int i, + private bool Select(DataGridView dgv, int i, string keyInput = "") { bool found = false; @@ -1085,14 +1085,14 @@ namespace SystemTrayMenu { dgv.FirstDisplayedScrollingRowIndex = row.Index; } - else if(row.Index >= - dgv.FirstDisplayedScrollingRowIndex + + else if (row.Index >= + dgv.FirstDisplayedScrollingRowIndex + dgv.DisplayedRowCount(false)) { dgv.FirstDisplayedScrollingRowIndex = row.Index - dgv.DisplayedRowCount(false) + 1; } - + found = true; } }