diff --git a/Business/App.cs b/Business/App.cs index 2fe49242..411f8d59 100644 --- a/Business/App.cs +++ b/Business/App.cs @@ -17,11 +17,6 @@ internal class App : IDisposable public App() { - Screen screen = Screen.PrimaryScreen; - Statics.ScreenHeight = screen.Bounds.Height; - Statics.ScreenWidth = screen.Bounds.Width; - Statics.ScreenRight = screen.Bounds.Right; - Statics.TaskbarHeight = new WindowsTaskbar().Size.Height; AppRestart.BeforeRestarting += Dispose; SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings; menus.LoadStarted += menuNotifyIcon.LoadingStart; diff --git a/Business/KeyboardInput.cs b/Business/KeyboardInput.cs index 635f6524..6beaa001 100644 --- a/Business/KeyboardInput.cs +++ b/Business/KeyboardInput.cs @@ -12,40 +12,28 @@ namespace SystemTrayMenu.Handler { internal class KeyboardInput : IDisposable { - public event EventHandlerEmpty HotKeyPressed; - public event EventHandlerEmpty ClosePressed; - public event Action RowSelected; - public event Action RowDeselected; + internal event EventHandlerEmpty HotKeyPressed; + internal event EventHandlerEmpty ClosePressed; + internal event Action RowSelected; + internal event Action RowDeselected; internal Action EnterPressed; - public event EventHandlerEmpty Cleared; + internal event EventHandlerEmpty Cleared; + + internal bool InUse = false; + internal int iRowKey = -1; + internal int iMenuKey = 0; private readonly Menu[] menus; private readonly KeyboardHook hook = new KeyboardHook(); - private readonly Timer timerKeySearch = new Timer(); - public int iRowKey = -1; - public int iMenuKey = 0; - private string KeySearchString = string.Empty; - - public bool InUse = false; public KeyboardInput(Menu[] menus) { this.menus = menus; - - timerKeySearch.Interval = MenuDefines.KeySearchInterval; - timerKeySearch.Tick += TimerKeySearch_Tick; - void TimerKeySearch_Tick(object sender, EventArgs e) - { - // this search has expired, reset search - timerKeySearch.Stop(); - KeySearchString = string.Empty; - } } public void Dispose() { hook.Dispose(); - timerKeySearch.Dispose(); } private int GetMenuIndex(in Menu currentMenu) @@ -68,7 +56,7 @@ internal void RegisterHotKey() { try { - hook.RegisterHotKey(Properties.Settings.Default.HotKey); + hook.RegisterHotKey(); hook.KeyPressed += hook_KeyPressed; void hook_KeyPressed(object sender, KeyPressedEventArgs e) { @@ -178,29 +166,6 @@ internal void KeyPress(object sender, KeyPressEventArgs e) Menu menu = menus[iMenuKey]; menu.KeyPressedSearch(letter); -#warning remove if not more needed - // Old Search by letters - //timerKeySearch.Stop(); - //if (string.IsNullOrEmpty(KeySearchString)) - //{ - // // no search string set, start new search with initial letter - // KeySearchString += letter; - // SelectByKey(Keys.None, KeySearchString); - //} - //else if (KeySearchString.Length == 1 && KeySearchString.LastOrDefault().ToString(CultureInfo.InvariantCulture) == letter) - //{ - // // initial letter pressed again, jump to next element - // SelectByKey(Keys.None, letter); - //} - //else - //{ - // // new character for the search string, narrow down the search - // KeySearchString += letter; - // SelectByKey(Keys.None, KeySearchString, true); - //} - //// give user some time to continue with this search - //timerKeySearch.Start(); - e.Handled = true; } } @@ -295,7 +260,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f } else { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); EnterPressed.Invoke(dgv, iRowKey); } @@ -305,7 +270,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatchedReverse(dgv, iRowKey) || SelectMatchedReverse(dgv, dgv.Rows.Count - 1)) { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } @@ -314,7 +279,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } @@ -334,8 +299,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { - RowDeselected(iMenuBefore, - iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } @@ -352,7 +316,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, iRowKey) || SelectMatched(dgv, 0)) { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } @@ -371,7 +335,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, dgv.SelectedRows[0].Index) || SelectMatched(dgv, 0)) { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); SelectRow(dgv, iRowKey); toClear = true; } @@ -379,7 +343,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f } else { - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); iMenuKey = 0; iRowKey = -1; toClear = true; @@ -387,7 +351,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f } break; case Keys.Escape: - RowDeselected(iMenuBefore, iRowBefore, dgvBefore); + RowDeselected(iRowBefore, dgvBefore); iMenuKey = 0; iRowKey = -1; toClear = true; @@ -399,7 +363,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, iRowKey, keyInput) || SelectMatched(dgv, 0, keyInput)) { - RowDeselected(iMenuBefore, iRowBefore, null); + RowDeselected(iRowBefore, null); SelectRow(dgv, iRowKey); toClear = true; } @@ -409,7 +373,7 @@ private void SelectByKey(Keys keys, string keyInput = "", bool KeepSelection = f if (SelectMatched(dgv, iRowKey, keyInput) || SelectMatched(dgv, 0, keyInput)) { - RowDeselected(iMenuBefore, iRowBefore, null); + RowDeselected(iRowBefore, null); SelectRow(dgv, iRowKey); } else diff --git a/Business/Menus.cs b/Business/Menus.cs index 68fe5151..1d8b3c61 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -1,5 +1,4 @@ -using Clearcove.Logging; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -28,7 +27,7 @@ private enum OpenCloseState { Default, Opening, Closing }; private readonly List workersSubMenu = new List(); private readonly WaitToLoadMenu waitToOpenMenu = new WaitToLoadMenu(); - private readonly KeyboardInput keyboardInput; + private readonly KeyboardInput keyboardInput = null; private readonly Timer timerStillActiveCheck = new Timer(); private readonly WaitLeave waitLeave = new WaitLeave(MenuDefines.TimeUntilClose); private DateTime deactivatedTime = DateTime.MinValue; @@ -36,6 +35,11 @@ private enum OpenCloseState { Default, Opening, Closing }; private IEnumerable AsEnumerable => menus.Where(m => m != null && !m.IsDisposed); private List AsList => AsEnumerable.ToList(); + private readonly int screenHeight = Screen.PrimaryScreen.Bounds.Height; + private readonly int screenWidth = Screen.PrimaryScreen.Bounds.Width; + private readonly int screenRight = Screen.PrimaryScreen.Bounds.Right; + private readonly int taskbarHeight = new WindowsTaskbar().Size.Height; + public Menus() { workerMainMenu.WorkerSupportsCancellation = true; @@ -218,9 +222,10 @@ public void Dispose() { worker.Dispose(); } - waitLeave.Dispose(); + waitToOpenMenu.Dispose(); keyboardInput.Dispose(); timerStillActiveCheck.Dispose(); + waitLeave.Dispose(); IconReader.Dispose(); DisposeMenu(menus[0]); } @@ -374,7 +379,8 @@ internal void MainPreload() { menus[0] = Create(GetData(workerMainMenu, Config.Path, 0), Path.GetFileName(Config.Path)); - menus[0].AdjustSizeAndLocation(); + menus[0].AdjustSizeAndLocation(screenHeight, + screenRight, taskbarHeight); DisposeMenu(menus[0]); } @@ -737,7 +743,8 @@ private void AdjustMenusSizeAndLocation() int widthPredecessors = -1; // -1 padding bool directionToRight = false; - menus[0].AdjustSizeAndLocation(); + menus[0].AdjustSizeAndLocation(screenHeight, + screenRight, taskbarHeight); foreach (Menu menu in AsEnumerable.Where(m => m.Level > 0)) { @@ -754,14 +761,14 @@ private void AdjustMenusSizeAndLocation() widthPredecessors -= newWith; } } - else if (Statics.ScreenWidth < - widthPredecessors + menus[0].Width + menu.Width) + else if (screenWidth < widthPredecessors + menus[0].Width + menu.Width) { directionToRight = true; widthPredecessors -= newWith; } - menu.AdjustSizeAndLocation(menuPredecessor, directionToRight); + menu.AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight, + menuPredecessor, directionToRight); widthPredecessors += menu.Width - menu.Padding.Left; menuPredecessor = menu; } diff --git a/Business/WaitToLoadMenu.cs b/Business/WaitToLoadMenu.cs index db01b41f..1a29e405 100644 --- a/Business/WaitToLoadMenu.cs +++ b/Business/WaitToLoadMenu.cs @@ -70,7 +70,7 @@ internal void MouseLeave(object sender, DataGridViewCellEventArgs e) } } - internal void RowDeselected(int iMenuBefore, int rowIndex, DataGridView dgv) //iMenuBefore not needed + internal void RowDeselected(int rowIndex, DataGridView dgv) //iMenuBefore not needed { timerStartLoad.Stop(); StopLoadMenu?.Invoke(); @@ -115,7 +115,7 @@ internal void MouseMove(object sender, MouseEventArgs e) } mouseMoveEvents = 0; } - else if (DateTime.Now - dateTimeLastMouseMoveEvent < + else if (DateTime.Now - dateTimeLastMouseMoveEvent < new TimeSpan(0, 0, 0, 0, 200)) { mouseMoveEvents++; @@ -189,8 +189,8 @@ public void Dispose() { timerStartLoad.Stop(); timerStartLoad.Dispose(); - dgv.Dispose(); - dgvTmp.Dispose(); + dgv?.Dispose(); + dgvTmp?.Dispose(); } } } \ No newline at end of file diff --git a/Config/Config.cs b/Config/Config.cs index 1cb70e61..6d31f218 100644 --- a/Config/Config.cs +++ b/Config/Config.cs @@ -2,7 +2,7 @@ using System.IO; using System.Reflection; using System.Windows.Forms; -using SystemTrayMenu.UserInterface.FolderDialog; +using SystemTrayMenu.UserInterface.Dialogs; using SystemTrayMenu.Utilities; namespace SystemTrayMenu diff --git a/Config/MenuDefines.cs b/Config/MenuDefines.cs index 1deead77..3d965262 100644 --- a/Config/MenuDefines.cs +++ b/Config/MenuDefines.cs @@ -15,7 +15,6 @@ internal static class MenuDefines internal static readonly Color ColorTitleWarning = AppColors.Red; internal static readonly Color ColorTitleSelected = AppColors.Yellow; internal static readonly Color ColorTitleBackground = AppColors.Azure; - internal const int KeySearchInterval = 1000; internal const int Scrollspeed = 4; internal const int TimeUntilClose = 1000; internal const int MenusMax = 50; diff --git a/DataClasses/Statics.cs b/DataClasses/Statics.cs deleted file mode 100644 index c509eaef..00000000 --- a/DataClasses/Statics.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SystemTrayMenu.DataClasses -{ - - public static class Statics - { - public static int ScreenHeight = 0; - public static int ScreenWidth = 0; - public static int ScreenRight = 0; - public static int TaskbarHeight = 0; - } -} diff --git a/Helpers/Fading.cs b/Helpers/Fading.cs index 564b6010..ae0345ed 100644 --- a/Helpers/Fading.cs +++ b/Helpers/Fading.cs @@ -23,7 +23,6 @@ internal enum FadingState { Idle, Show, ShowTransparent, Hide }; private const double ShownMinus = 0.80; //Shown - StepIn private readonly Timer timer = new Timer(); - private static readonly object lockTimerEnable = new object(); private FadingState state = FadingState.Idle; private double opacity = 0.00; private bool visible = false; diff --git a/Helpers/KeyboardHook.cs b/Helpers/KeyboardHook.cs index 533a4495..ad0aeda8 100644 --- a/Helpers/KeyboardHook.cs +++ b/Helpers/KeyboardHook.cs @@ -77,25 +77,25 @@ internal void RegisterHotKey(Keys key) RegisterHotKey(keyModifiersNone, key); } - internal void RegisterHotKey(string hotKeyString) + internal void RegisterHotKey() { KeyboardHookModifierKeys modifiers = KeyboardHookModifierKeys.None; string modifiersString = Properties.Settings.Default.HotKey; if (!string.IsNullOrEmpty(modifiersString)) { - if (modifiersString.ToLower().Contains("alt")) + if (modifiersString.ToUpperInvariant().Contains("ALT", StringComparison.InvariantCulture)) { modifiers |= KeyboardHookModifierKeys.Alt; } - if (modifiersString.ToLower().Contains("ctrl")) + if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture)) { modifiers |= KeyboardHookModifierKeys.Control; } - if (modifiersString.ToLower().Contains("shift")) + if (modifiersString.ToUpperInvariant().Contains("SHIFT", StringComparison.InvariantCulture)) { modifiers |= KeyboardHookModifierKeys.Shift; } - if (modifiersString.ToLower().Contains("win")) + if (modifiersString.ToUpperInvariant().Contains("WIN", StringComparison.InvariantCulture)) { modifiers |= KeyboardHookModifierKeys.Win; } diff --git a/NativeDllImport/TrackPopupMenuEx.cs b/NativeDllImport/TrackPopupMenuEx.cs index 3a0416df..510f0372 100644 --- a/NativeDllImport/TrackPopupMenuEx.cs +++ b/NativeDllImport/TrackPopupMenuEx.cs @@ -20,13 +20,13 @@ internal enum TPM : uint { LEFTBUTTON = 0x0000, RIGHTBUTTON = 0x0002, - LEFTALIGN = 0x0000, + //LEFTALIGN = 0x0000, CENTERALIGN = 0x0004, RIGHTALIGN = 0x0008, - TOPALIGN = 0x0000, + //TOPALIGN = 0x0000, VCENTERALIGN = 0x0010, BOTTOMALIGN = 0x0020, - HORIZONTAL = 0x0000, + //HORIZONTAL = 0x0000, VERTICAL = 0x0040, NONOTIFY = 0x0080, RETURNCMD = 0x0100, diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 848fe88c..37016033 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.11.2.4")] -[assembly: AssemblyFileVersion("0.11.2.4")] +[assembly: AssemblyVersion("0.11.3.0")] +[assembly: AssemblyFileVersion("0.11.3.0")] diff --git a/Resources/lang.Designer.cs b/Resources/lang.Designer.cs index 44182764..2f563756 100644 --- a/Resources/lang.Designer.cs +++ b/Resources/lang.Designer.cs @@ -231,6 +231,15 @@ internal static string Restart { } } + /// + /// Looks up a localized string similar to Select Folder. + /// + internal static string Select_Folder { + get { + return ResourceManager.GetString("Select Folder", resourceCulture); + } + } + /// /// Looks up a localized string similar to Settings. /// @@ -257,5 +266,14 @@ internal static string TextFirstStart { return ResourceManager.GetString("TextFirstStart", resourceCulture); } } + + /// + /// Looks up a localized string similar to Warning. + /// + internal static string Warning { + get { + return ResourceManager.GetString("Warning", resourceCulture); + } + } } } diff --git a/Resources/lang.de-DE.resx b/Resources/lang.de-DE.resx index 6c719f5d..14915a14 100644 --- a/Resources/lang.de-DE.resx +++ b/Resources/lang.de-DE.resx @@ -183,4 +183,10 @@ Lese das FAQ und wähle anschließend ein root Verzeichniss für die SystemTrayMenu. + + Warning + + + Select Folder + \ No newline at end of file diff --git a/Resources/lang.resx b/Resources/lang.resx index c3510873..9908b0de 100644 --- a/Resources/lang.resx +++ b/Resources/lang.resx @@ -183,4 +183,10 @@ Read the FAQ and then choose a root directory for the SystemTrayMenu. + + Warning + + + Select Folder + \ No newline at end of file diff --git a/UserInterface/AboutBox.cs b/UserInterface/AboutBox.cs index 5c7009f1..933b09a3 100644 --- a/UserInterface/AboutBox.cs +++ b/UserInterface/AboutBox.cs @@ -332,7 +332,7 @@ private static NameValueCollection AssemblyAttribs(Assembly a) { if (!a.IsDynamic) { - nvc.Add("CodeBase", a.CodeBase.Replace("file:///", "")); + nvc.Add("CodeBase", a.CodeBase.Replace("file:///", "", StringComparison.InvariantCulture)); } } catch (NotSupportedException) @@ -584,22 +584,22 @@ private void PopulateLabels() // private string ReplaceTokens(string s) { - s = s.Replace("%title%", EntryAssemblyAttrib("title")); - s = s.Replace("%copyright%", EntryAssemblyAttrib("copyright")); - s = s.Replace("%description%", EntryAssemblyAttrib("description")); - s = s.Replace("%company%", EntryAssemblyAttrib("company")); - s = s.Replace("%product%", EntryAssemblyAttrib("product")); - s = s.Replace("%trademark%", EntryAssemblyAttrib("trademark")); - s = s.Replace("%year%", DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)); - s = s.Replace("%version%", EntryAssemblyAttrib("version")); - s = s.Replace("%builddate%", EntryAssemblyAttrib("builddate")); + s = s.Replace("%title%", EntryAssemblyAttrib("title"), StringComparison.InvariantCulture); + s = s.Replace("%copyright%", EntryAssemblyAttrib("copyright"), StringComparison.InvariantCulture); + s = s.Replace("%description%", EntryAssemblyAttrib("description"), StringComparison.InvariantCulture); + s = s.Replace("%company%", EntryAssemblyAttrib("company"), StringComparison.InvariantCulture); + s = s.Replace("%product%", EntryAssemblyAttrib("product"), StringComparison.InvariantCulture); + s = s.Replace("%trademark%", EntryAssemblyAttrib("trademark"), StringComparison.InvariantCulture); + s = s.Replace("%year%", DateTime.Now.Year.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCulture); + s = s.Replace("%version%", EntryAssemblyAttrib("version"), StringComparison.InvariantCulture); + s = s.Replace("%builddate%", EntryAssemblyAttrib("builddate"), StringComparison.InvariantCulture); return s; } // // populate details for a single assembly // - private void PopulateAssemblyDetails(Assembly a, ListView lvw) + private static void PopulateAssemblyDetails(Assembly a, ListView lvw) { lvw.Items.Clear(); @@ -617,7 +617,7 @@ private void PopulateAssemblyDetails(Assembly a, ListView lvw) // // matches assembly by Assembly.GetName.Name; returns nothing if no match // - private Assembly MatchAssemblyByName(string AssemblyName) + private static Assembly MatchAssemblyByName(string AssemblyName) { foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { diff --git a/UserInterface/Controls/HotkeyControl.cs b/UserInterface/Controls/HotkeyControl.cs index 8ad14c1e..a8fd86ea 100644 --- a/UserInterface/Controls/HotkeyControl.cs +++ b/UserInterface/Controls/HotkeyControl.cs @@ -421,19 +421,19 @@ public static Keys HotkeyModifiersFromString(string modifiersString) Keys modifiers = Keys.None; if (!string.IsNullOrEmpty(modifiersString)) { - if (modifiersString.ToLower().Contains("alt")) + if (modifiersString.ToUpperInvariant().Contains("ALT", StringComparison.InvariantCulture)) { modifiers |= Keys.Alt; } - if (modifiersString.ToLower().Contains("ctrl")) + if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture)) { modifiers |= Keys.Control; } - if (modifiersString.ToLower().Contains("shift")) + if (modifiersString.ToUpperInvariant().Contains("SHIFT", StringComparison.InvariantCulture)) { modifiers |= Keys.Shift; } - if (modifiersString.ToLower().Contains("win")) + if (modifiersString.ToUpperInvariant().Contains("WIN", StringComparison.InvariantCulture)) { modifiers |= Keys.LWin; } @@ -452,8 +452,9 @@ public static Keys HotkeyFromString(string hotkey) } try { - hotkey = hotkey.Replace("PgDn", "PageDown"). - Replace("PgUp", "PageUp"); + hotkey = hotkey. + Replace("PgDn", "PageDown", StringComparison.InvariantCulture). + Replace("PgUp", "PageUp", StringComparison.InvariantCulture); key = (Keys)Enum.Parse(typeof(Keys), hotkey); } catch (ArgumentException ex) diff --git a/UserInterface/FolderDialog/FolderDialog.cs b/UserInterface/Dialogs/FolderDialog.cs similarity index 98% rename from UserInterface/FolderDialog/FolderDialog.cs rename to UserInterface/Dialogs/FolderDialog.cs index 87e2e33f..29ca5dad 100644 --- a/UserInterface/FolderDialog/FolderDialog.cs +++ b/UserInterface/Dialogs/FolderDialog.cs @@ -3,8 +3,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows.Forms; +using SystemTrayMenu.Utilities; -namespace SystemTrayMenu.UserInterface.FolderDialog +namespace SystemTrayMenu.UserInterface.Dialogs { public class FolderDialog : IFolderDialog, IDisposable { @@ -71,7 +72,7 @@ public DialogResult ShowVistaDialog(IWin32Window owner) } } - if (frm.Show(owner.Handle) == NativeMethods.S_OK) + if (owner != null && frm.Show(owner.Handle) == NativeMethods.S_OK) { if (frm.GetResult(out NativeMethods.IShellItem shellItem) == NativeMethods.S_OK) { @@ -106,7 +107,7 @@ public DialogResult ShowLegacyDialog(IWin32Window owner) frm.FileName = "any"; if (InitialFolder != null) { frm.InitialDirectory = InitialFolder; } frm.OverwritePrompt = false; - frm.Title = "Select Folder"; + frm.Title = Translator.GetText("Select Folder"); frm.ValidateNames = false; if (frm.ShowDialog(owner) == DialogResult.OK) { diff --git a/UserInterface/FolderDialog/IFolderDialog.cs b/UserInterface/Dialogs/IFolderDialog.cs similarity index 89% rename from UserInterface/FolderDialog/IFolderDialog.cs rename to UserInterface/Dialogs/IFolderDialog.cs index fae48f28..fd8e6ca6 100644 --- a/UserInterface/FolderDialog/IFolderDialog.cs +++ b/UserInterface/Dialogs/IFolderDialog.cs @@ -1,6 +1,6 @@ using System.Windows.Forms; -namespace SystemTrayMenu.UserInterface.FolderDialog +namespace SystemTrayMenu.UserInterface.Dialogs { public interface IFolderDialog { diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 86d3cee4..3dae5db1 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -43,7 +43,7 @@ internal Menu() fading.ChangeOpacity += Fading_ChangeOpacity; void Fading_ChangeOpacity(object sender, double newOpacity) { - if(!IsDisposed && !Disposing) + if (!IsDisposed && !Disposing) { Opacity = newOpacity; } @@ -238,7 +238,9 @@ internal void HideWithFade() } } - internal void AdjustSizeAndLocation(Menu menuPredecessor = null, + internal void AdjustSizeAndLocation(int screenHeight, + int screenRight, int taskbarHeight, + Menu menuPredecessor = null, bool directionToRight = false) { CheckForAutoResizeRowDone(); @@ -272,14 +274,14 @@ void CheckForAutoResizeRowDone() row.Height = dgv.RowTemplate.Height; } dgv.Tag = true; - } + } } int dgvHeightNeeded = dgv.Rows.GetRowsHeight( DataGridViewElementStates.None); int menuRestNeeded = Height - dgv.Height; - int dgvHeightMax = Statics.ScreenHeight - Statics.TaskbarHeight - + int dgvHeightMax = screenHeight - taskbarHeight - menuRestNeeded; if (dgvHeightNeeded > dgvHeightMax) @@ -298,7 +300,7 @@ void CheckForAutoResizeRowDone() int x; if (menuPredecessor == null) { - x = Statics.ScreenRight - Width; + x = screenRight - Width; } else { @@ -327,7 +329,7 @@ void CheckForAutoResizeRowDone() int y; if (menuPredecessor == null) { - y = Statics.ScreenHeight - Statics.TaskbarHeight - Height; + y = screenHeight - taskbarHeight - Height; } else { diff --git a/UserInterface/SettingsForm.cs b/UserInterface/SettingsForm.cs index 830dc8f7..2d16b477 100644 --- a/UserInterface/SettingsForm.cs +++ b/UserInterface/SettingsForm.cs @@ -197,7 +197,6 @@ private static bool RegisterHotkey(StringBuilder failedKeys, string hotkeyString { if (HotkeyControl.RegisterHotKey(modifierKeyCode, virtualKeyCode, handler) < 0) { -#warning logging //LOG.DebugFormat("Failed to register {0} to hotkey: {1}", functionName, hotkeyString); if (failedKeys.Length > 0) { @@ -206,52 +205,45 @@ private static bool RegisterHotkey(StringBuilder failedKeys, string hotkeyString failedKeys.Append(hotkeyString); return false; } -#warning logging //LOG.DebugFormat("Registered {0} to hotkey: {1}", functionName, hotkeyString); } else { -#warning logging //LOG.InfoFormat("Skipping hotkey registration for {0}, no hotkey set!", functionName); } return true; } - private static bool RegisterWrapper(StringBuilder failedKeys, HotKeyHandler handler, bool ignoreFailedRegistration) + private static bool RegisterWrapper(StringBuilder failedKeys, HotKeyHandler handler) { -#warning todo with Properties.Settings.Default.HotKey //IniValue hotkeyValue = _conf.Values[configurationKey]; - try - { + //try + //{ bool success = RegisterHotkey(failedKeys, //hotkeyValue.Value.ToString(), Properties.Settings.Default.HotKey, handler); - if (!success && ignoreFailedRegistration) - { -#warning logging - //LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue); -#warning todo with Properties.Settings.Default.HotKey - //_conf.Values[configurationKey].Value = Keys.None.ToString(); - //_conf.IsDirty = true; - } + //if (!success && ignoreFailedRegistration) + //{ + // //LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue); + // //_conf.Values[configurationKey].Value = Keys.None.ToString(); + // //_conf.IsDirty = true; + //} return success; - } - catch (Exception) - { -#warning logging - //LOG.Warn(ex); - //LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.Attributes.DefaultValue); + //} + //catch (Exception) + //{ + // //LOG.Warn(ex); + // //LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.Attributes.DefaultValue); - // when getting an exception the key wasn't found: reset the hotkey value - //hotkeyValue.UseValueOrDefault(null); - //hotkeyValue.ContainingIniSection.IsDirty = true; -#warning todo set default Properties.Settings.Default.HotKey = - return RegisterHotkey(failedKeys, - //hotkeyValue.Value.ToString(), - Properties.Settings.Default.HotKey, - handler); - } + // // when getting an exception the key wasn't found: reset the hotkey value + // //hotkeyValue.UseValueOrDefault(null); + // //hotkeyValue.ContainingIniSection.IsDirty = true; + // return RegisterHotkey(failedKeys, + // //hotkeyValue.Value.ToString(), + // Properties.Settings.Default.HotKey, + // handler); + //} } /// @@ -276,7 +268,7 @@ private static bool RegisterHotkeys(bool ignoreFailedRegistration) //} bool success = true; StringBuilder failedKeys = new StringBuilder(); - if (!RegisterWrapper(failedKeys, TODO, ignoreFailedRegistration)) + if (!RegisterWrapper(failedKeys, handler)) { success = false; } @@ -289,8 +281,6 @@ private static bool RegisterHotkeys(bool ignoreFailedRegistration) } else { -#warning todo with Properties.Settings.Default.HotKey - // if failures have been ignored, the config has probably been updated //if (_conf.IsDirty) //{ @@ -301,9 +291,9 @@ private static bool RegisterHotkeys(bool ignoreFailedRegistration) return success || ignoreFailedRegistration; } - private static void TODO() + private static void handler() { -#warning TODO + //todo } ///// @@ -342,12 +332,8 @@ private static void TODO() private static bool HandleFailedHotkeyRegistration(string failedKeys) { bool success = false; -#warning todo - //var warningTitle = Language.GetString(LangKey.warning); - string warningTitle = "Warning"; - //var message = string.Format(Language.GetString(LangKey.warning_hotkeys), failedKeys, IsOneDriveBlockingHotkey() ? " (OneDrive)" : ""); - string message = Translator.GetText("Could not register the hot key."); - //DialogResult dr = MessageBox.Show(Instance, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); + string warningTitle = Translator.GetText("Warning"); + string message = Translator.GetText("Could not register the hot key.") + failedKeys; DialogResult dr = MessageBox.Show(message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Retry) { diff --git a/UserInterface/ShellContextMenu/ShellContextMenu.cs b/UserInterface/ShellContextMenu/ShellContextMenu.cs index ab97e322..187f49c0 100644 --- a/UserInterface/ShellContextMenu/ShellContextMenu.cs +++ b/UserInterface/ShellContextMenu/ShellContextMenu.cs @@ -758,8 +758,8 @@ private enum SFGAO : uint FOLDER = 0x20000000, GHOSTED = 0x8000, HASPROPSHEET = 0x40, - HASSTORAGE = 0x400000, - HASSUBFOLDER = 0x80000000, + //HASSTORAGE = 0x400000, + //HASSUBFOLDER = 0x80000000, HIDDEN = 0x80000, ISSLOW = 0x4000, LINK = 0x10000, @@ -771,7 +771,7 @@ private enum SFGAO : uint STORAGE = 8, STORAGEANCESTOR = 0x800000, STORAGECAPMASK = 0x70c50008, - STREAM = 0x400000, + //STREAM = 0x400000, VALIDATE = 0x1000000 } @@ -846,10 +846,10 @@ private enum SW { HIDE = 0, SHOWNORMAL = 1, - NORMAL = 1, + //NORMAL = 1, SHOWMINIMIZED = 2, SHOWMAXIMIZED = 3, - MAXIMIZE = 3, + //MAXIMIZE = 3, SHOWNOACTIVATE = 4, SHOW = 5, MINIMIZE = 6, @@ -934,7 +934,7 @@ private enum WM : uint IME_CONTROL = 0x283, IME_ENDCOMPOSITION = 0x10E, IME_KEYDOWN = 0x290, - IME_KEYLAST = 0x10F, + //IME_KEYLAST = 0x10F, IME_KEYUP = 0x291, IME_NOTIFY = 0x282, IME_REQUEST = 0x288, @@ -947,7 +947,7 @@ private enum WM : uint INPUTLANGCHANGE = 0x51, INPUTLANGCHANGEREQUEST = 0x50, KEYDOWN = 0x100, - KEYFIRST = 0x100, + //KEYFIRST = 0x100, KEYLAST = 0x108, KEYUP = 0x101, KILLFOCUS = 0x8, @@ -983,8 +983,8 @@ private enum WM : uint MOUSEHOVER = 0x2A1, MOUSELAST = 0x20A, MOUSELEAVE = 0x2A3, - MOUSEMOVE = 0x200, - MOUSEWHEEL = 0x20A, + //MOUSEMOVE = 0x200, + //MOUSEWHEEL = 0x20A, MOVE = 0x3, MOVING = 0x216, NCACTIVATE = 0x86, @@ -1070,7 +1070,7 @@ private enum WM : uint VSCROLLCLIPBOARD = 0x30A, WINDOWPOSCHANGED = 0x47, WINDOWPOSCHANGING = 0x46, - WININICHANGE = 0x1A, + //WININICHANGE = 0x1A, SH_NOTIFY = 0x0401 } @@ -1079,7 +1079,7 @@ private enum WM : uint private enum MFT : uint { GRAYED = 0x00000003, - DISABLED = 0x00000003, + //DISABLED = 0x00000003, CHECKED = 0x00000008, SEPARATOR = 0x00000800, RADIOCHECK = 0x00000200, @@ -1098,12 +1098,12 @@ private enum MFT : uint private enum MFS : uint { GRAYED = 0x00000003, - DISABLED = 0x00000003, + //DISABLED = 0x00000003, CHECKED = 0x00000008, HILITE = 0x00000080, ENABLED = 0x00000000, - UNCHECKED = 0x00000000, - UNHILITE = 0x00000000, + //UNCHECKED = 0x00000000, + //UNHILITE = 0x00000000, DEFAULT = 0x00001000 } diff --git a/Utilities/File/FileUrl.cs b/Utilities/File/FileUrl.cs index 276dc94e..67656541 100644 --- a/Utilities/File/FileUrl.cs +++ b/Utilities/File/FileUrl.cs @@ -42,7 +42,7 @@ public static string GetDefaultBrowserPath() userChoiceKey.Close(); // now look up the path of the executable - string concreteBrowserKey = browserPathKey.Replace("$BROWSER$", progId); + string concreteBrowserKey = browserPathKey.Replace("$BROWSER$", progId, System.StringComparison.InvariantCulture); RegistryKey kp = Registry.ClassesRoot.OpenSubKey(concreteBrowserKey, false); browserPath = CleanifyBrowserPath(kp.GetValue(null) as string); kp.Close(); diff --git a/Utilities/Shares.cs b/Utilities/Shares.cs index 690f1ed2..aac66241 100644 --- a/Utilities/Shares.cs +++ b/Utilities/Shares.cs @@ -1,8 +1,8 @@ using System; using System.Collections; +using System.Globalization; using System.IO; using System.Runtime.InteropServices; -#warning put each class in extra file namespace SystemTrayMenu.Utilities { @@ -421,12 +421,12 @@ protected static void EnumerateSharesNT(string server, ShareCollection shares) if (1 == level) { SHARE_INFO_1 si = (SHARE_INFO_1)Marshal.PtrToStructure(pItem, t); - shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark); + shares?.Add(si.NetName, string.Empty, si.ShareType, si.Remark); } else { SHARE_INFO_2 si = (SHARE_INFO_2)Marshal.PtrToStructure(pItem, t); - shares.Add(si.NetName, si.Path, si.ShareType, si.Remark); + shares?.Add(si.NetName, si.Path, si.ShareType, si.Remark); } } } @@ -482,12 +482,12 @@ protected static void EnumerateShares9x(string server, ShareCollection shares) if (1 == level) { SHARE_INFO_1_9x si = (SHARE_INFO_1_9x)Marshal.PtrToStructure(pItem, t); - shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark); + shares?.Add(si.NetName, string.Empty, si.ShareType, si.Remark); } else { SHARE_INFO_50 si = (SHARE_INFO_50)Marshal.PtrToStructure(pItem, t); - shares.Add(si.NetName, si.Path, si.ShareType, si.Remark); + shares?.Add(si.NetName, si.Path, si.ShareType, si.Remark); } } } @@ -512,7 +512,7 @@ protected static void EnumerateShares(string server, ShareCollection shares) { if (null != server && 0 != server.Length && !IsW2KUp) { - server = server.ToUpper(); + server = server.ToUpperInvariant(); // On NT4, 9x and Me, server has to start with "\\" if (!('\\' == server[0] && '\\' == server[1])) @@ -550,7 +550,7 @@ public static bool IsValidFilePath(string fileName) return false; } - char drive = char.ToUpper(fileName[0]); + char drive = char.ToUpper(fileName[0], CultureInfo.InvariantCulture); if ('A' > drive || drive > 'Z') { return false; @@ -655,7 +655,7 @@ public static string PathToUnc(string fileName) return fileName; default: - Console.WriteLine("Unknown return value: {0}", nRet); + //Console.WriteLine("Unknown return value: {0}", nRet); return string.Empty; } }