Code Analyze and Refactor 0.12 (#109), version 0.11.4.1

This commit is contained in:
Markus Hofknecht 2020-07-06 16:46:47 +02:00
parent 0ecb70c878
commit 48805cc0f2
18 changed files with 155 additions and 233 deletions

View file

@ -2,8 +2,6 @@
using System;
using System.Windows.Forms;
using SystemTrayMenu.Business;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.Helper;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
@ -13,7 +11,7 @@ namespace SystemTrayMenu
{
private readonly MenuNotifyIcon menuNotifyIcon = new MenuNotifyIcon();
private readonly Menus menus = new Menus();
private TaskbarForm taskbarForm = new TaskbarForm();
private readonly TaskbarForm taskbarForm = new TaskbarForm();
public App()
{

View file

@ -45,7 +45,7 @@ namespace SystemTrayMenu.Business
{
workerMainMenu.WorkerSupportsCancellation = true;
workerMainMenu.DoWork += LoadMenu;
void LoadMenu(object senderDoWork, DoWorkEventArgs eDoWork)
static void LoadMenu(object senderDoWork, DoWorkEventArgs eDoWork)
{
string path = Config.Path;
int level = 0;
@ -305,7 +305,8 @@ namespace SystemTrayMenu.Business
return
output
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => System.IO.Path.Combine(networkLocationRootPath, x.Substring(0, x.IndexOf(' '))))
.Select(x => Path.Combine(networkLocationRootPath,
x.Substring(0, x.IndexOf(' ', StringComparison.InvariantCulture))))
.ToArray();
}
}
@ -506,7 +507,7 @@ namespace SystemTrayMenu.Business
menu.SetTitle(title);
menu.UserClickedOpenFolder += OpenFolder;
void OpenFolder()
static void OpenFolder()
{
Log.ProcessStart("explorer.exe", Config.Path);
}
@ -544,7 +545,7 @@ namespace SystemTrayMenu.Business
menu.VisibleChanged += MenuVisibleChanged;
AddItemsToMenu(menuData.RowDatas, menu);
void AddItemsToMenu(List<RowData> data, Menu menu)
static void AddItemsToMenu(List<RowData> data, Menu menu)
{
DataGridView dgv = menu.GetDataGridView();
DataTable dataTable = new DataTable();
@ -739,15 +740,6 @@ namespace SystemTrayMenu.Business
}
}
private void FadeInIfNeeded()
{
if (menus[0].IsUsable)
{
bool active = IsActive();
AsList.ForEach(menu => menu.ShowWithFadeOrTransparent(active));
}
}
internal void FadeHalfOrOutIfNeeded()
{
if (menus[0].IsUsable)

View file

@ -23,7 +23,7 @@ namespace SystemTrayMenu
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += ThreadException;
void ThreadException(object s, ThreadExceptionEventArgs t)
static void ThreadException(object s, ThreadExceptionEventArgs t)
{
AskUserSendError(t.Exception);
}
@ -49,11 +49,10 @@ namespace SystemTrayMenu
Log.Close();
}
void AskUserSendError(Exception ex)
static void AskUserSendError(Exception ex)
{
Log.Error("Application Crashed", ex);
#warning [Feature] When Error ask user to send us #47, todo own dialog, lines here too long
if (MessageBox.Show("A problem has been encountered and the application needs to restart. " +
"Reporting this error will help us make our product better. Press yes to open your standard email app.",
"SystemTrayMenu BugSplat", MessageBoxButtons.YesNo) == DialogResult.Yes)

View file

@ -45,8 +45,8 @@ namespace SystemTrayMenu.Handler
}
else
{
this.dgvTmp = (DataGridView)sender;
this.rowIndexTmp = e.RowIndex;
dgvTmp = (DataGridView)sender;
rowIndexTmp = e.RowIndex;
}
}

View file

@ -172,8 +172,7 @@ namespace SystemTrayMenu.DataClasses
string iconLocation = lnk.IconLocation;
if (iconLocation.Length > 2)
{
iconLocation = iconLocation.Substring(0,
iconLocation.Length - 2);
iconLocation = iconLocation[0..^2];
if (System.IO.File.Exists(iconLocation))
{
try
@ -246,7 +245,7 @@ namespace SystemTrayMenu.DataClasses
}
}
SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}");
SetText($"{FileInfo.Name[0..^4]}");
return handled;
}

View file

@ -36,10 +36,7 @@ namespace SystemTrayMenu.Helper
KeyboardHookModifierKeys modifier = (KeyboardHookModifierKeys)((int)m.LParam & 0xFFFF);
// invoke the event to notify the parent.
if (KeyPressed != null)
{
KeyPressed(this, new KeyPressedEventArgs(modifier, key));
}
KeyPressed?.Invoke(this, new KeyPressedEventArgs(modifier, key));
}
}
@ -87,7 +84,8 @@ namespace SystemTrayMenu.Helper
{
modifiers |= KeyboardHookModifierKeys.Alt;
}
if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture))
if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture) ||
modifiersString.ToUpperInvariant().Contains("STRG", StringComparison.InvariantCulture))
{
modifiers |= KeyboardHookModifierKeys.Control;
}
@ -119,7 +117,7 @@ namespace SystemTrayMenu.Helper
private void RegisterHotKey(uint modifier, Keys key)
{
_currentId = _currentId + 1;
_currentId += 1;
if (!DllImports.NativeMethods.User32RegisterHotKey(
_window.Handle, _currentId, modifier, (uint)key))

View file

@ -1,16 +1,25 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace SystemTrayMenu.DllImports
{
public static partial class NativeMethods
{
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKeyCode);
[DllImport("user32.dll")]
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll", SetLastError = true)]
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize);
public static bool User32RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk)
{
return RegisterHotKey(hWnd, id, fsModifiers, vk);
@ -20,5 +29,15 @@ namespace SystemTrayMenu.DllImports
{
return UnregisterHotKey(hWnd, id);
}
public static uint User32MapVirtualKey(uint uCode, uint uMapType)
{
return MapVirtualKey(uCode, uMapType);
}
public static int User32GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize)
{
return GetKeyNameText(lParam, lpString, nSize);
}
}
}

View file

@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// 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.4.0")]
[assembly: AssemblyFileVersion("0.11.4.0")]
[assembly: AssemblyVersion("0.11.4.1")]
[assembly: AssemblyFileVersion("0.11.4.1")]

View file

@ -197,33 +197,14 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer">
<Version>3.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeQuality.Analyzers">
<Version>3.0.0</Version>
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NetCore.Analyzers">
<Version>3.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NetFramework.Analyzers">
<Version>3.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>taskkill /fi "pid gt 0" /im SystemTrayMenu.exe

View file

@ -37,7 +37,6 @@ namespace SystemTrayMenu.UserInterface
private string _ExecutingAssemblyName;
private Assembly _EntryAssembly;
private NameValueCollection _EntryAssemblyAttribCollection;
private int _MinWindowHeight;
// <summary>
// returns the entry assembly for the current application domain
@ -222,7 +221,9 @@ namespace SystemTrayMenu.UserInterface
else
{
dt = DateTime.Parse("01/01/2000", CultureInfo.InvariantCulture).AddDays(AssemblyVersion.Build).AddSeconds(AssemblyVersion.Revision * 2);
#pragma warning disable CS0618
if (TimeZone.IsDaylightSavingTime(dt, TimeZone.CurrentTimeZone.GetDaylightChanges(dt.Year)))
#pragma warning restore CS0618
{
dt = dt.AddHours(1);
}
@ -335,7 +336,9 @@ namespace SystemTrayMenu.UserInterface
nvc.Add("CodeBase", a.CodeBase.Replace("file:///", "", StringComparison.InvariantCulture));
}
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (NotSupportedException)
#pragma warning restore CA1031 // Do not catch general exception types
{
nvc.Add("CodeBase", "(not supported)");
}
@ -357,7 +360,9 @@ namespace SystemTrayMenu.UserInterface
nvc.Add("Location", a.Location);
}
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (NotSupportedException)
#pragma warning restore CA1031 // Do not catch general exception types
{
nvc.Add("Location", "(not supported)");
}
@ -650,12 +655,12 @@ namespace SystemTrayMenu.UserInterface
// for web hosted apps, GetEntryAssembly = nothing
_EntryAssemblyName = Assembly.GetEntryAssembly().GetName().Name;
_MinWindowHeight = AppCopyrightLabel.Top + AppCopyrightLabel.Height + buttonOk.Height + 30;
//_MinWindowHeight = AppCopyrightLabel.Top + AppCopyrightLabel.Height + buttonOk.Height + 30;
TabPanelDetails.Visible = false;
if (!MoreRichTextBox.Visible)
{
Height = Height - MoreRichTextBox.Height;
Height -= MoreRichTextBox.Height;
}
}

View file

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Utilities;
namespace SystemTrayMenu.UserInterface.Controls
@ -28,14 +28,14 @@ namespace SystemTrayMenu.UserInterface.Controls
private static IntPtr _hotkeyHwnd;
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum Modifiers : uint
private enum Modifiers
{
NONE = 0,
ALT = 1,
CTRL = 2,
SHIFT = 4,
WIN = 8,
NO_REPEAT = 0x4000
NOREPEAT = 0x4000
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
@ -48,19 +48,6 @@ namespace SystemTrayMenu.UserInterface.Controls
MAPVK_VK_TO_VSC_EX = 4 //The uCode parameter is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If the scan code is an extended scan code, the high byte of the uCode value can contain either 0xe0 or 0xe1 to specify the extended scan code. If there is no translation, the function returns 0.
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKeyCode);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll", SetLastError = true)]
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize);
// These variables store the current hotkey and modifier(s)
private Keys _hotkey = Keys.None;
private Keys _modifiers = Keys.None;
@ -425,7 +412,8 @@ namespace SystemTrayMenu.UserInterface.Controls
{
modifiers |= Keys.Alt;
}
if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture))
if (modifiersString.ToUpperInvariant().Contains("CTRL", StringComparison.InvariantCulture) ||
modifiersString.ToUpperInvariant().Contains("STRG", StringComparison.InvariantCulture))
{
modifiers |= Keys.Control;
}
@ -486,7 +474,6 @@ namespace SystemTrayMenu.UserInterface.Controls
{
if (virtualKeyCode == Keys.None)
{
Log.Info("Trying to register a Keys.none hotkey, ignoring");
return 0;
}
// Convert Modifiers to fit HKM_SETHOTKEY
@ -510,9 +497,9 @@ namespace SystemTrayMenu.UserInterface.Controls
// Disable repeating hotkey for Windows 7 and beyond, as described in #1559
if (IsWindows7OrOlder)
{
modifiers |= (uint)Modifiers.NO_REPEAT;
modifiers |= (uint)Modifiers.NOREPEAT;
}
if (RegisterHotKey(_hotkeyHwnd, _hotKeyCounter, modifiers, (uint)virtualKeyCode))
if (NativeMethods.User32RegisterHotKey(_hotkeyHwnd, _hotKeyCounter, modifiers, (uint)virtualKeyCode))
{
KeyHandlers.Add(_hotKeyCounter, handler);
return _hotKeyCounter++;
@ -528,7 +515,7 @@ namespace SystemTrayMenu.UserInterface.Controls
{
foreach (int hotkey in KeyHandlers.Keys)
{
UnregisterHotKey(_hotkeyHwnd, hotkey);
NativeMethods.User32UnregisterHotKey(_hotkeyHwnd, hotkey);
}
// Remove all key handlers
KeyHandlers.Clear();
@ -541,7 +528,7 @@ namespace SystemTrayMenu.UserInterface.Controls
{
if (availableHotkey == hotkey)
{
UnregisterHotKey(_hotkeyHwnd, hotkey);
NativeMethods.User32UnregisterHotKey(_hotkeyHwnd, hotkey);
removeHotkey = true;
}
}
@ -575,13 +562,14 @@ namespace SystemTrayMenu.UserInterface.Controls
return true;
}
#pragma warning disable CA1308
public static string GetKeyName(Keys givenKey)
{
StringBuilder keyName = new StringBuilder();
const uint numpad = 55;
Keys virtualKey = givenKey;
string keyString;
string keyString = string.Empty;
// Make VC's to real keys
switch (virtualKey)
{
@ -595,25 +583,29 @@ namespace SystemTrayMenu.UserInterface.Controls
virtualKey = Keys.LShiftKey;
break;
case Keys.Multiply:
GetKeyNameText(numpad << 16, keyName, 100);
keyString = keyName.ToString().Replace("*", "").Trim().ToLower();
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0)
if (NativeMethods.User32GetKeyNameText(numpad << 16, keyName, 100) > 0)
{
return "* " + keyString;
keyString = keyName.ToString().Replace("*", "", StringComparison.InvariantCulture).Trim().ToLowerInvariant();
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0)
{
return "* " + keyString;
}
keyString = keyString.Substring(0, 1).ToUpperInvariant() + keyString.Substring(1).ToLowerInvariant();
}
keyString = keyString.Substring(0, 1).ToUpper() + keyString.Substring(1).ToLower();
return keyString + " *";
case Keys.Divide:
GetKeyNameText(numpad << 16, keyName, 100);
keyString = keyName.ToString().Replace("*", "").Trim().ToLower();
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0)
if (NativeMethods.User32GetKeyNameText(numpad << 16, keyName, 100) > 0)
{
return "/ " + keyString;
keyString = keyName.ToString().Replace("*", "", StringComparison.InvariantCulture).Trim().ToLowerInvariant();
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0)
{
return "/ " + keyString;
}
keyString = keyString.Substring(0, 1).ToUpperInvariant() + keyString.Substring(1).ToLowerInvariant();
}
keyString = keyString.Substring(0, 1).ToUpper() + keyString.Substring(1).ToLower();
return keyString + " /";
}
uint scanCode = MapVirtualKey((uint)virtualKey, (uint)MapType.MAPVK_VK_TO_VSC);
uint scanCode = NativeMethods.User32MapVirtualKey((uint)virtualKey, (uint)MapType.MAPVK_VK_TO_VSC);
// because MapVirtualKey strips the extended bit for some keys
switch (virtualKey)
@ -640,12 +632,12 @@ namespace SystemTrayMenu.UserInterface.Controls
break;
}
scanCode |= 0x200;
if (GetKeyNameText(scanCode << 16, keyName, 100) != 0)
if (NativeMethods.User32GetKeyNameText(scanCode << 16, keyName, 100) != 0)
{
string visibleName = keyName.ToString();
if (visibleName.Length > 1)
{
visibleName = visibleName.Substring(0, 1) + visibleName.Substring(1).ToLower();
visibleName = visibleName.Substring(0, 1) + visibleName.Substring(1).ToLowerInvariant();
}
return visibleName;
}
@ -655,6 +647,7 @@ namespace SystemTrayMenu.UserInterface.Controls
}
}
}
#pragma warning restore CA1308
public class EventDelay
{
@ -667,7 +660,9 @@ namespace SystemTrayMenu.UserInterface.Controls
public bool Check()
{
#pragma warning disable CA2002
lock (this)
#pragma warning restore CA2002
{
long now = DateTime.Now.Ticks;
bool isPassed = now - lastCheck > waitTime;

View file

@ -98,26 +98,26 @@ namespace SystemTrayMenu.UserInterface.Dialogs
}
public DialogResult ShowLegacyDialog(IWin32Window owner)
{
using (SaveFileDialog frm = new SaveFileDialog())
using SaveFileDialog frm = new SaveFileDialog
{
frm.CheckFileExists = false;
frm.CheckPathExists = true;
frm.CreatePrompt = false;
frm.Filter = "|" + Guid.Empty.ToString();
frm.FileName = "any";
if (InitialFolder != null) { frm.InitialDirectory = InitialFolder; }
frm.OverwritePrompt = false;
frm.Title = Translator.GetText("Select Folder");
frm.ValidateNames = false;
if (frm.ShowDialog(owner) == DialogResult.OK)
{
Folder = Path.GetDirectoryName(frm.FileName);
return DialogResult.OK;
}
else
{
return DialogResult.Cancel;
}
CheckFileExists = false,
CheckPathExists = true,
CreatePrompt = false,
Filter = "|" + Guid.Empty.ToString(),
FileName = "any"
};
if (InitialFolder != null) { frm.InitialDirectory = InitialFolder; }
frm.OverwritePrompt = false;
frm.Title = Translator.GetText("Select Folder");
frm.ValidateNames = false;
if (frm.ShowDialog(owner) == DialogResult.OK)
{
Folder = Path.GetDirectoryName(frm.FileName);
return DialogResult.OK;
}
else
{
return DialogResult.Cancel;
}
}

View file

@ -65,7 +65,7 @@
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel.Size = new System.Drawing.Size(83, 182);
this.tableLayoutPanel.TabIndex = 3;
this.tableLayoutPanel.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.dgv_MouseWheel);
this.tableLayoutPanel.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel);
//
// labelTitle
//
@ -86,7 +86,7 @@
this.labelTitle.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.LabelTitle_MouseDoubleClick);
this.labelTitle.MouseEnter += new System.EventHandler(this.LabelTitle_MouseEnter);
this.labelTitle.MouseLeave += new System.EventHandler(this.LabelTitle_MouseLeave);
this.labelTitle.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.dgv_MouseWheel);
this.labelTitle.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel);
//
// ColumnText
//
@ -154,7 +154,7 @@
this.dgv.ShowRowErrors = false;
this.dgv.Size = new System.Drawing.Size(83, 145);
this.dgv.TabIndex = 4;
this.dgv.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.dgv_MouseWheel);
this.dgv.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel);
//
// pictureBoxSearch
//
@ -179,7 +179,7 @@
this.textBoxSearch.ShortcutsEnabled = false;
this.textBoxSearch.Size = new System.Drawing.Size(55, 15);
this.textBoxSearch.TabIndex = 0;
this.textBoxSearch.TextChanged += new System.EventHandler(this.textBoxSearch_TextChanged);
this.textBoxSearch.TextChanged += new System.EventHandler(this.TextBoxSearch_TextChanged);
//
// tableLayoutPanelSearch
//

View file

@ -59,7 +59,9 @@ namespace SystemTrayMenu.UserInterface
Visible = true;
isShowing = false;
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (ObjectDisposedException)
#pragma warning restore CA1031 // Do not catch general exception types
{
Visible = false;
isShowing = false;
@ -101,7 +103,7 @@ namespace SystemTrayMenu.UserInterface
dgv.DefaultCellStyle = dgvCellStyle;
VScrollBar scrollBar = dgv.Controls.OfType<VScrollBar>().First();
scrollBar.MouseWheel += dgv_MouseWheel;
scrollBar.MouseWheel += DgvMouseWheel;
scrollBar.MouseEnter += ControlsMouseEnter;
dgv.MouseEnter += ControlsMouseEnter;
labelTitle.MouseEnter += ControlsMouseEnter;
@ -398,7 +400,7 @@ namespace SystemTrayMenu.UserInterface
return isScrollbarShown;
}
private void dgv_MouseWheel(object sender, MouseEventArgs e)
private void DgvMouseWheel(object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = true;
int scrollspeed = MenuDefines.Scrollspeed;
@ -488,7 +490,7 @@ namespace SystemTrayMenu.UserInterface
return base.ProcessCmdKey(ref msg, keys);
}
private void textBoxSearch_TextChanged(object sender, EventArgs e)
private void TextBoxSearch_TextChanged(object sender, EventArgs e)
{
DataTable data = (DataTable)dgv.DataSource;
string filterField = dgv.Columns[1].Name;

View file

@ -158,8 +158,8 @@ namespace SystemTrayMenu.UserInterface
this.textBoxHotkey.TabIndex = 99;
this.textBoxHotkey.TabStop = false;
this.textBoxHotkey.Text = "None";
this.textBoxHotkey.Enter += new System.EventHandler(this.textBoxHotkey_Enter);
this.textBoxHotkey.Leave += new System.EventHandler(this.textBoxHotkey_Leave);
this.textBoxHotkey.Enter += new System.EventHandler(this.TextBoxHotkeyEnter);
this.textBoxHotkey.Leave += new System.EventHandler(this.TextBoxHotkey_Leave);
//
// checkBoxAutostart
//
@ -225,7 +225,7 @@ namespace SystemTrayMenu.UserInterface
this.buttonChange.TabIndex = 5;
this.buttonChange.Text = "...";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
this.buttonChange.Click += new System.EventHandler(this.ButtonChange_Click);
//
// textBoxFolder
//
@ -363,7 +363,7 @@ namespace SystemTrayMenu.UserInterface
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// SettingsForm
//

View file

@ -130,26 +130,26 @@ namespace SystemTrayMenu.UserInterface
comboBoxLanguage.SelectedValue.ToString();
}
private void buttonCancel_Click(object sender, EventArgs e)
private void ButtonCancel_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Reload();
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonChange_Click(object sender, EventArgs e)
private void ButtonChange_Click(object sender, EventArgs e)
{
Config.SetFolderByUser(false);
textBoxFolder.Text = Config.Path;
}
private void textBoxHotkey_Enter(object sender, EventArgs e)
private void TextBoxHotkeyEnter(object sender, EventArgs e)
{
HotkeyControl.UnregisterHotkeys();
_inHotkey = true;
}
private void textBoxHotkey_Leave(object sender, EventArgs e)
private void TextBoxHotkey_Leave(object sender, EventArgs e)
{
Properties.Settings.Default.HotKey =
new KeysConverter().ConvertToInvariantString(
@ -219,17 +219,17 @@ namespace SystemTrayMenu.UserInterface
//IniValue hotkeyValue = _conf.Values[configurationKey];
//try
//{
bool success = RegisterHotkey(failedKeys,
//hotkeyValue.Value.ToString(),
Properties.Settings.Default.HotKey,
handler);
//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;
bool success = RegisterHotkey(failedKeys,
//hotkeyValue.Value.ToString(),
Properties.Settings.Default.HotKey,
handler);
//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)
//{
@ -268,7 +268,7 @@ namespace SystemTrayMenu.UserInterface
//}
bool success = true;
StringBuilder failedKeys = new StringBuilder();
if (!RegisterWrapper(failedKeys, handler))
if (!RegisterWrapper(failedKeys, Handler))
{
success = false;
}
@ -291,9 +291,8 @@ namespace SystemTrayMenu.UserInterface
return success || ignoreFailedRegistration;
}
private static void handler()
private static void Handler()
{
//todo
}
///// <summary>

View file

@ -109,19 +109,19 @@ namespace SystemTrayMenu.Utilities
((int)ShellHelper.HiWord(m.WParam) & (int)MFT.SEPARATOR) == 0 &&
((int)ShellHelper.HiWord(m.WParam) & (int)MFT.POPUP) == 0)
{
string info = string.Empty;
//string info = string.Empty;
if (ShellHelper.LoWord(m.WParam) == (int)CMD_CUSTOM.ExpandCollapse)
{
info = "Expands or collapses the current selected item";
}
else
{
info = "";/* ContextMenuHelper.GetCommandString(
_oContextMenu,
ShellHelper.LoWord(m.WParam) - CMD_FIRST,
false);*/
}
//if (ShellHelper.LoWord(m.WParam) == (int)CMD_CUSTOM.ExpandCollapse)
//{
// info = "Expands or collapses the current selected item";
//}
//else
//{
// info = "";/* ContextMenuHelper.GetCommandString(
// _oContextMenu,
// ShellHelper.LoWord(m.WParam) - CMD_FIRST,
// false);*/
//}
//br.OnContextMenuMouseHover(new ContextMenuMouseHoverEventArgs(info.ToString()));
}
@ -230,12 +230,10 @@ namespace SystemTrayMenu.Utilities
/// <returns>IShellFolder for desktop folder</returns>
private IShellFolder GetDesktopFolder()
{
IntPtr pUnkownDesktopFolder = IntPtr.Zero;
if (null == _oDesktopFolder)
{
// Get desktop IShellFolder
int nResult = DllImports.NativeMethods.Shell32SHGetDesktopFolder(out pUnkownDesktopFolder);
int nResult = DllImports.NativeMethods.Shell32SHGetDesktopFolder(out IntPtr pUnkownDesktopFolder);
if (S_OK != nResult)
{
#pragma warning disable CA1303 // Do not pass literals as localized parameters
@ -266,10 +264,9 @@ namespace SystemTrayMenu.Utilities
}
// Get the PIDL for the folder file is in
IntPtr pPIDL = IntPtr.Zero;
uint pchEaten = 0;
SFGAO pdwAttributes = 0;
int nResult = oDesktopFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, folderName, ref pchEaten, out pPIDL, ref pdwAttributes);
int nResult = oDesktopFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, folderName, ref pchEaten, out IntPtr pPIDL, ref pdwAttributes);
if (S_OK != nResult)
{
return null;
@ -277,16 +274,14 @@ namespace SystemTrayMenu.Utilities
IntPtr pStrRet = Marshal.AllocCoTaskMem(MAX_PATH * 2 + 4);
Marshal.WriteInt32(pStrRet, 0, 0);
nResult = _oDesktopFolder.GetDisplayNameOf(pPIDL, SHGNO.FORPARSING, pStrRet);
_ = _oDesktopFolder.GetDisplayNameOf(pPIDL, SHGNO.FORPARSING, pStrRet);
StringBuilder strFolder = new StringBuilder(MAX_PATH);
_ = DllImports.NativeMethods.ShlwapiStrRetToBuf(pStrRet, pPIDL, strFolder, MAX_PATH);
Marshal.FreeCoTaskMem(pStrRet);
pStrRet = IntPtr.Zero;
_strParentFolder = strFolder.ToString();
// Get the IShellFolder for folder
IntPtr pUnknownParentFolder = IntPtr.Zero;
nResult = oDesktopFolder.BindToObject(pPIDL, IntPtr.Zero, ref IID_IShellFolder, out pUnknownParentFolder);
nResult = oDesktopFolder.BindToObject(pPIDL, IntPtr.Zero, ref IID_IShellFolder, out IntPtr pUnknownParentFolder);
// Free the PIDL first
Marshal.FreeCoTaskMem(pPIDL);
if (S_OK != nResult)
@ -401,64 +396,6 @@ namespace SystemTrayMenu.Utilities
}
#endregion
#region InvokeContextMenuDefault
private void InvokeContextMenuDefault(FileInfo[] arrFI)
{
// Release all resources first.
ReleaseAll();
IntPtr pMenu = IntPtr.Zero,
iContextMenuPtr = IntPtr.Zero;
try
{
_arrPIDLs = GetPIDLs(arrFI);
if (null == _arrPIDLs)
{
ReleaseAll();
return;
}
if (false == GetContextMenuInterfaces(_oParentFolder, _arrPIDLs, out iContextMenuPtr))
{
ReleaseAll();
return;
}
pMenu = DllImports.NativeMethods.User32CreatePopupMenu();
int nResult = _oContextMenu.QueryContextMenu(
pMenu,
0,
CMD_FIRST,
CMD_LAST,
CMF.DEFAULTONLY |
((Control.ModifierKeys & Keys.Shift) != 0 ? CMF.EXTENDEDVERBS : 0));
uint nDefaultCmd = (uint)DllImports.NativeMethods.User32GetMenuDefaultItem(pMenu, false, 0);
if (nDefaultCmd >= CMD_FIRST)
{
InvokeCommand(_oContextMenu, nDefaultCmd, arrFI[0].DirectoryName, Control.MousePosition);
}
DllImports.NativeMethods.User32DestroyMenu(pMenu);
pMenu = IntPtr.Zero;
}
catch
{
throw;
}
finally
{
if (pMenu != IntPtr.Zero)
{
DllImports.NativeMethods.User32DestroyMenu(pMenu);
}
ReleaseAll();
}
}
#endregion
#region ShowContextMenu()
/// <summary>

View file

@ -20,7 +20,7 @@ namespace SystemTrayMenu.Utilities
public static class IconReader
{
private static readonly ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>();
private static readonly Object readIcon = new Object();
private static readonly object readIcon = new object();
public enum IconSize
{
Large = 0, //32x32 pixels
@ -206,16 +206,14 @@ namespace SystemTrayMenu.Utilities
Icon icon = null;
if (originalIcon != null)
{
using (Bitmap target = new Bitmap(
using Bitmap target = new Bitmap(
originalIcon.Width, originalIcon.Height,
PixelFormat.Format32bppArgb))
{
Graphics graphics = Graphics.FromImage(target);
graphics.DrawIcon(originalIcon, 0, 0);
graphics.DrawIcon(overlay, 0, 0);
target.MakeTransparent(target.GetPixel(1, 1));
icon = Icon.FromHandle(target.GetHicon());
}
PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(target);
graphics.DrawIcon(originalIcon, 0, 0);
graphics.DrawIcon(overlay, 0, 0);
target.MakeTransparent(target.GetPixel(1, 1));
icon = Icon.FromHandle(target.GetHicon());
}
return icon;