Code quality changes

This commit is contained in:
Robin 2016-09-22 20:40:13 +02:00
commit 610f45d082
189 changed files with 4609 additions and 5203 deletions

View file

@ -29,7 +29,7 @@ namespace GreenshotPlugin.Controls {
/// Extend this Form to have the possibility for animations on your form
/// </summary>
public class AnimatingForm : GreenshotForm {
private static readonly ILog LOG = LogManager.GetLogger(typeof(AnimatingForm));
private static readonly ILog Log = LogManager.GetLogger(typeof(AnimatingForm));
private const int DEFAULT_VREFRESH = 60;
private int _vRefresh;
private Timer _timer;
@ -49,7 +49,7 @@ namespace GreenshotPlugin.Controls {
get {
if (_vRefresh == 0) {
// get te hDC of the desktop to get the VREFRESH
using (SafeWindowDCHandle desktopHandle = SafeWindowDCHandle.FromDesktop()) {
using (SafeWindowDcHandle desktopHandle = SafeWindowDcHandle.FromDesktop()) {
_vRefresh = GDI32.GetDeviceCaps(desktopHandle, DeviceCaps.VREFRESH);
}
}
@ -65,11 +65,7 @@ namespace GreenshotPlugin.Controls {
/// <summary>
/// Check if we are in a Terminal Server session OR need to optimize for RDP / remote desktop connections
/// </summary>
protected bool IsTerminalServerSession {
get {
return !coreConfiguration.DisableRDPOptimizing && (coreConfiguration.OptimizeForRDP || SystemInformation.TerminalServerSession);
}
}
protected bool IsTerminalServerSession => !coreConfiguration.DisableRDPOptimizing && (coreConfiguration.OptimizeForRDP || SystemInformation.TerminalServerSession);
/// <summary>
/// Calculate the amount of frames that an animation takes
@ -89,19 +85,22 @@ namespace GreenshotPlugin.Controls {
/// </summary>
protected AnimatingForm() {
Load += delegate {
if (EnableAnimation) {
_timer = new Timer();
_timer.Interval = 1000 / VRefresh;
_timer.Tick += timer_Tick;
_timer.Start();
if (!EnableAnimation)
{
return;
}
_timer = new Timer
{
Interval = 1000/VRefresh
};
_timer.Tick += timer_Tick;
_timer.Start();
};
// Unregister at close
FormClosing += delegate {
if (_timer != null) {
_timer.Stop();
}
FormClosing += delegate
{
_timer?.Stop();
};
}
@ -114,7 +113,7 @@ namespace GreenshotPlugin.Controls {
try {
Animate();
} catch (Exception ex) {
LOG.Warn("An exception occured while animating:", ex);
Log.Warn("An exception occured while animating:", ex);
}
}

View file

@ -59,8 +59,5 @@ namespace GreenshotPlugin.Controls {
protected override WebBrowserSiteBase CreateWebBrowserSiteBase() {
return new ExtendedWebBrowserSite(this);
}
public ExtendedWebBrowser() {
}
}
}

View file

@ -83,7 +83,7 @@ namespace GreenshotPlugin.Controls {
foreach (Enum enumValue in availableValues) {
string enumKey = enumTypeName + "." + enumValue;
if (Language.hasKey(enumKey)) {
if (Language.HasKey(enumKey)) {
string translation = Language.GetString(enumTypeName + "." + enumValue);
if (translation.Equals(selectedValue)) {
returnValue = enumValue;

View file

@ -107,13 +107,16 @@ namespace GreenshotPlugin.Controls {
// this "type"
Assembly currentAssembly = GetType().Assembly;
string assemblyPath = typeResService.GetPathOfAssembly(currentAssembly.GetName());
string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Greenshot\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Greenshot\Languages\"));
}
if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Languages\"));
if (typeResService != null)
{
string assemblyPath = typeResService.GetPathOfAssembly(currentAssembly.GetName());
string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
if (assemblyDirectory != null && !Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Greenshot\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Greenshot\Languages\"));
}
if (assemblyDirectory != null && !Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Languages\"));
}
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
@ -131,7 +134,10 @@ namespace GreenshotPlugin.Controls {
_isDesignModeLanguageSet = true;
try {
ApplyLanguage();
} catch (Exception) {
}
catch (Exception)
{
// ignored
}
}
}
@ -229,7 +235,7 @@ namespace GreenshotPlugin.Controls {
/// <param name="sender"></param>
/// <param name="ce"></param>
private void OnComponentChanged(object sender, ComponentChangedEventArgs ce) {
if (ce.Component != null && ((IComponent)ce.Component).Site != null && ce.Member != null) {
if (((IComponent) ce.Component)?.Site != null && ce.Member != null) {
if ("LanguageKey".Equals(ce.Member.Name)) {
Control control = ce.Component as Control;
if (control != null) {
@ -249,7 +255,7 @@ namespace GreenshotPlugin.Controls {
}
private void OnComponentAdded(object sender, ComponentEventArgs ce) {
if (ce.Component != null && ((IComponent)ce.Component).Site != null) {
if (ce.Component?.Site != null) {
Control control = ce.Component as Control;
if (control != null) {
if (!_designTimeControls.ContainsKey(control.Name)) {
@ -257,12 +263,17 @@ namespace GreenshotPlugin.Controls {
} else {
_designTimeControls[control.Name] = control;
}
} else if (ce.Component is ToolStripItem) {
ToolStripItem item = ce.Component as ToolStripItem;
if (!_designTimeControls.ContainsKey(item.Name)) {
_designTimeToolStripItems.Add(item.Name, item);
} else {
_designTimeToolStripItems[item.Name] = item;
}
else
{
var stripItem = ce.Component as ToolStripItem;
if (stripItem != null) {
ToolStripItem item = stripItem;
if (!_designTimeControls.ContainsKey(item.Name)) {
_designTimeToolStripItems.Add(item.Name, item);
} else {
_designTimeToolStripItems[item.Name] = item;
}
}
}
}
@ -308,10 +319,12 @@ namespace GreenshotPlugin.Controls {
if (languageBindable == null) {
// check if it's a menu!
ToolStrip toolStrip = applyTo as ToolStrip;
if (toolStrip != null) {
foreach (ToolStripItem item in toolStrip.Items) {
ApplyLanguage(item);
}
if (toolStrip == null)
{
return;
}
foreach (ToolStripItem item in toolStrip.Items) {
ApplyLanguage(item);
}
return;
}
@ -327,7 +340,7 @@ namespace GreenshotPlugin.Controls {
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
if (section != null) {
// Only update the language, so get the actual value and than repopulate
Enum currentValue = (Enum)comboxBox.GetSelectedEnum();
Enum currentValue = comboxBox.GetSelectedEnum();
comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
comboxBox.SetValue(currentValue);
}
@ -341,7 +354,7 @@ namespace GreenshotPlugin.Controls {
/// <param name="typeToGetFieldsFor"></param>
/// <returns></returns>
private static FieldInfo[] GetCachedFields(Type typeToGetFieldsFor) {
FieldInfo[] fields = null;
FieldInfo[] fields;
if (!reflectionCache.TryGetValue(typeToGetFieldsFor, out fields)) {
fields = typeToGetFieldsFor.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
reflectionCache.Add(typeToGetFieldsFor, fields);
@ -353,17 +366,17 @@ namespace GreenshotPlugin.Controls {
/// Apply all the language settings to the "Greenshot" Controls on this form
/// </summary>
protected void ApplyLanguage() {
string langString = null;
SuspendLayout();
try {
// Set title of the form
string langString;
if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) {
Text = langString;
}
// Reset the text values for all GreenshotControls
foreach (FieldInfo field in GetCachedFields(GetType())) {
Object controlObject = field.GetValue(this);
object controlObject = field.GetValue(this);
if (controlObject == null) {
LOG.DebugFormat("No value: {0}", field.Name);
continue;
@ -398,7 +411,7 @@ namespace GreenshotPlugin.Controls {
/// Apply the language text to supplied control
/// </summary>
protected void ApplyLanguage(Control applyTo, string languageKey) {
string langString = null;
string langString;
if (!string.IsNullOrEmpty(languageKey)) {
if (!Language.TryGetString(languageKey, out langString)) {
LOG.WarnFormat("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name);
@ -422,18 +435,12 @@ namespace GreenshotPlugin.Controls {
/// </summary>
protected void FillFields() {
foreach (FieldInfo field in GetCachedFields(GetType())) {
Object controlObject = field.GetValue(this);
if (controlObject == null) {
continue;
}
var controlObject = field.GetValue(this);
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
if (configBindable == null) {
continue;
}
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
if (!string.IsNullOrEmpty(configBindable?.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
if (section != null) {
IniValue iniValue = null;
IniValue iniValue;
if (!section.Values.TryGetValue(configBindable.PropertyName, out iniValue)) {
LOG.DebugFormat("Wrong property '{0}' configured for field '{1}'",configBindable.PropertyName,field.Name);
continue;
@ -445,7 +452,7 @@ namespace GreenshotPlugin.Controls {
checkBox.Enabled = !iniValue.IsFixed;
continue;
}
RadioButton radíoButton = controlObject as RadioButton;
RadioButton radíoButton = controlObject as RadioButton;
if (radíoButton != null) {
radíoButton.Checked = (bool)iniValue.Value;
radíoButton.Enabled = !iniValue.IsFixed;
@ -477,11 +484,11 @@ namespace GreenshotPlugin.Controls {
}
}
}
OnFieldsFilled();
OnFieldsFilled();
}
protected virtual void OnFieldsFilled() {
}
protected virtual void OnFieldsFilled() {
}
/// <summary>
/// Store all GreenshotControl values to the configuration
@ -489,19 +496,13 @@ namespace GreenshotPlugin.Controls {
protected void StoreFields() {
bool iniDirty = false;
foreach (FieldInfo field in GetCachedFields(GetType())) {
Object controlObject = field.GetValue(this);
if (controlObject == null) {
continue;
}
var controlObject = field.GetValue(this);
IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
if (configBindable == null) {
continue;
}
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
if (!string.IsNullOrEmpty(configBindable?.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName)) {
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
if (section != null) {
IniValue iniValue = null;
IniValue iniValue;
if (!section.Values.TryGetValue(configBindable.PropertyName, out iniValue)) {
continue;
}
@ -511,7 +512,7 @@ namespace GreenshotPlugin.Controls {
iniDirty = true;
continue;
}
RadioButton radioButton = controlObject as RadioButton;
RadioButton radioButton = controlObject as RadioButton;
if (radioButton != null) {
iniValue.Value = radioButton.Checked;
iniDirty = true;
@ -519,12 +520,12 @@ namespace GreenshotPlugin.Controls {
}
TextBox textBox = controlObject as TextBox;
if (textBox != null) {
HotkeyControl hotkeyControl = controlObject as HotkeyControl;
if (hotkeyControl != null) {
iniValue.Value = hotkeyControl.ToString();
iniDirty = true;
continue;
}
HotkeyControl hotkeyControl = controlObject as HotkeyControl;
if (hotkeyControl != null) {
iniValue.Value = hotkeyControl.ToString();
iniDirty = true;
continue;
}
iniValue.UseValueOrDefault(textBox.Text);
iniDirty = true;
continue;
@ -533,7 +534,6 @@ namespace GreenshotPlugin.Controls {
if (comboxBox != null) {
iniValue.Value = comboxBox.GetSelectedEnum();
iniDirty = true;
continue;
}
}

View file

@ -33,16 +33,8 @@ namespace GreenshotPlugin.Controls {
set;
}
private string sectionName = "Core";
[Category("Greenshot"), DefaultValue("Core"), Description("Specifies the Ini-Section to map this control with.")]
public string SectionName {
get {
return sectionName;
}
set {
sectionName = value;
}
}
public string SectionName { get; set; } = "Core";
[Category("Greenshot"), DefaultValue(null), Description("Specifies the property name to map the configuration.")]
public string PropertyName {

View file

@ -37,17 +37,17 @@ namespace GreenshotPlugin.Controls {
/// See: http://www.codeproject.com/KB/buttons/hotkeycontrol.aspx
/// But is modified to fit in Greenshot, and have localized support
/// </summary>
public class HotkeyControl : GreenshotTextBox {
private static readonly ILog LOG = LogManager.GetLogger(typeof(HotkeyControl));
public sealed class HotkeyControl : GreenshotTextBox {
private static readonly ILog Log = LogManager.GetLogger(typeof(HotkeyControl));
private static readonly EventDelay eventDelay = new EventDelay(TimeSpan.FromMilliseconds(600).Ticks);
private static readonly bool isWindows7OrOlder = Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1;
private static readonly EventDelay EventDelay = new EventDelay(TimeSpan.FromMilliseconds(600).Ticks);
private static readonly bool IsWindows7OrOlder = Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1;
// Holds the list of hotkeys
private static readonly IDictionary<int, HotKeyHandler> keyHandlers = new Dictionary<int, HotKeyHandler>();
private static int hotKeyCounter = 1;
private static readonly IDictionary<int, HotKeyHandler> KeyHandlers = new Dictionary<int, HotKeyHandler>();
private static int _hotKeyCounter = 1;
private const uint WM_HOTKEY = 0x312;
private static IntPtr hotkeyHWND;
private static IntPtr _hotkeyHwnd;
// static HotkeyControl() {
// StringBuilder keyName = new StringBuilder();
@ -96,20 +96,20 @@ namespace GreenshotPlugin.Controls {
// ArrayLists used to enforce the use of proper modifiers.
// Shift+A isn't a valid hotkey, for instance, as it would screw up when the user is typing.
private readonly ArrayList needNonShiftModifier;
private readonly ArrayList needNonAltGrModifier;
private readonly ArrayList _needNonShiftModifier;
private readonly ArrayList _needNonAltGrModifier;
private readonly ContextMenu dummy = new ContextMenu();
private readonly ContextMenu _dummy = new ContextMenu();
/// <summary>
/// Used to make sure that there is no right-click menu available
/// </summary>
public override ContextMenu ContextMenu {
get {
return dummy;
return _dummy;
}
set {
base.ContextMenu = dummy;
base.ContextMenu = _dummy;
}
}
@ -130,7 +130,7 @@ namespace GreenshotPlugin.Controls {
/// Creates a new HotkeyControl
/// </summary>
public HotkeyControl() {
ContextMenu = dummy; // Disable right-clicking
ContextMenu = _dummy; // Disable right-clicking
Text = "None";
// Handle events that occurs when keys are pressed
@ -139,8 +139,8 @@ namespace GreenshotPlugin.Controls {
KeyDown += HotkeyControl_KeyDown;
// Fill the ArrayLists that contain all invalid hotkey combinations
needNonShiftModifier = new ArrayList();
needNonAltGrModifier = new ArrayList();
_needNonShiftModifier = new ArrayList();
_needNonAltGrModifier = new ArrayList();
PopulateModifierLists();
}
@ -151,41 +151,41 @@ namespace GreenshotPlugin.Controls {
private void PopulateModifierLists() {
// Shift + 0 - 9, A - Z
for (Keys k = Keys.D0; k <= Keys.Z; k++) {
needNonShiftModifier.Add((int)k);
_needNonShiftModifier.Add((int)k);
}
// Shift + Numpad keys
for (Keys k = Keys.NumPad0; k <= Keys.NumPad9; k++) {
needNonShiftModifier.Add((int)k);
_needNonShiftModifier.Add((int)k);
}
// Shift + Misc (,;<./ etc)
for (Keys k = Keys.Oem1; k <= Keys.OemBackslash; k++) {
needNonShiftModifier.Add((int)k);
_needNonShiftModifier.Add((int)k);
}
// Shift + Space, PgUp, PgDn, End, Home
for (Keys k = Keys.Space; k <= Keys.Home; k++) {
needNonShiftModifier.Add((int)k);
_needNonShiftModifier.Add((int)k);
}
// Misc keys that we can't loop through
needNonShiftModifier.Add((int)Keys.Insert);
needNonShiftModifier.Add((int)Keys.Help);
needNonShiftModifier.Add((int)Keys.Multiply);
needNonShiftModifier.Add((int)Keys.Add);
needNonShiftModifier.Add((int)Keys.Subtract);
needNonShiftModifier.Add((int)Keys.Divide);
needNonShiftModifier.Add((int)Keys.Decimal);
needNonShiftModifier.Add((int)Keys.Return);
needNonShiftModifier.Add((int)Keys.Escape);
needNonShiftModifier.Add((int)Keys.NumLock);
needNonShiftModifier.Add((int)Keys.Scroll);
needNonShiftModifier.Add((int)Keys.Pause);
_needNonShiftModifier.Add((int)Keys.Insert);
_needNonShiftModifier.Add((int)Keys.Help);
_needNonShiftModifier.Add((int)Keys.Multiply);
_needNonShiftModifier.Add((int)Keys.Add);
_needNonShiftModifier.Add((int)Keys.Subtract);
_needNonShiftModifier.Add((int)Keys.Divide);
_needNonShiftModifier.Add((int)Keys.Decimal);
_needNonShiftModifier.Add((int)Keys.Return);
_needNonShiftModifier.Add((int)Keys.Escape);
_needNonShiftModifier.Add((int)Keys.NumLock);
_needNonShiftModifier.Add((int)Keys.Scroll);
_needNonShiftModifier.Add((int)Keys.Pause);
// Ctrl+Alt + 0 - 9
for (Keys k = Keys.D0; k <= Keys.D9; k++) {
needNonAltGrModifier.Add((int)k);
_needNonAltGrModifier.Add((int)k);
}
}
@ -205,7 +205,6 @@ namespace GreenshotPlugin.Controls {
// Clear the current hotkey
if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) {
ResetHotkey();
return;
} else {
_modifiers = e.Modifiers;
_hotkey = e.KeyCode;
@ -227,7 +226,6 @@ namespace GreenshotPlugin.Controls {
if (_hotkey == Keys.None && ModifierKeys == Keys.None) {
ResetHotkey();
return;
}
}
@ -301,18 +299,11 @@ namespace GreenshotPlugin.Controls {
}
}
/// <summary>
/// Helper function
/// </summary>
private void Redraw() {
Redraw(false);
}
/// <summary>
/// Redraws the TextBox when necessary.
/// </summary>
/// <param name="bCalledProgramatically">Specifies whether this function was called by the Hotkey/HotkeyModifiers properties or by the user.</param>
private void Redraw(bool bCalledProgramatically) {
private void Redraw(bool bCalledProgramatically = false) {
// No hotkey set
if (_hotkey == Keys.None) {
Text = "";
@ -328,10 +319,10 @@ namespace GreenshotPlugin.Controls {
// Only validate input if it comes from the user
if (bCalledProgramatically == false) {
// No modifier or shift only, AND a hotkey that needs another modifier
if ((_modifiers == Keys.Shift || _modifiers == Keys.None) && needNonShiftModifier.Contains((int)_hotkey)) {
if ((_modifiers == Keys.Shift || _modifiers == Keys.None) && _needNonShiftModifier.Contains((int)_hotkey)) {
if (_modifiers == Keys.None) {
// Set Ctrl+Alt as the modifier unless Ctrl+Alt+<key> won't work...
if (needNonAltGrModifier.Contains((int)_hotkey) == false) {
if (_needNonAltGrModifier.Contains((int)_hotkey) == false) {
_modifiers = Keys.Alt | Keys.Control;
} else {
// ... in that case, use Shift+Alt instead.
@ -346,7 +337,7 @@ namespace GreenshotPlugin.Controls {
}
}
// Check all Ctrl+Alt keys
if ((_modifiers == (Keys.Alt | Keys.Control)) && needNonAltGrModifier.Contains((int)_hotkey)) {
if ((_modifiers == (Keys.Alt | Keys.Control)) && _needNonAltGrModifier.Contains((int)_hotkey)) {
// Ctrl+Alt+4 etc won't work; reset hotkey and tell the user
_hotkey = Keys.None;
Text = "";
@ -373,7 +364,7 @@ namespace GreenshotPlugin.Controls {
}
public static string HotkeyToString(Keys modifierKeyCode, Keys virtualKeyCode) {
return HotkeyModifiersToString(modifierKeyCode) + virtualKeyCode.ToString();
return HotkeyModifiersToString(modifierKeyCode) + virtualKeyCode;
}
public static string HotkeyModifiersToString(Keys modifierKeyCode) {
@ -446,8 +437,8 @@ namespace GreenshotPlugin.Controls {
return key;
}
public static void RegisterHotkeyHWND(IntPtr hWnd) {
hotkeyHWND = hWnd;
public static void RegisterHotkeyHwnd(IntPtr hWnd) {
_hotkeyHwnd = hWnd;
}
public static int RegisterHotKey(string hotkey, HotKeyHandler handler) {
@ -463,7 +454,7 @@ namespace GreenshotPlugin.Controls {
/// <returns>the hotkey number, -1 if failed</returns>
public static int RegisterHotKey(Keys modifierKeyCode, Keys virtualKeyCode, HotKeyHandler handler) {
if (virtualKeyCode == Keys.None) {
LOG.Warn("Trying to register a Keys.none hotkey, ignoring");
Log.Warn("Trying to register a Keys.none hotkey, ignoring");
return 0;
}
// Convert Modifiers to fit HKM_SETHOTKEY
@ -481,37 +472,37 @@ namespace GreenshotPlugin.Controls {
modifiers |= (uint)Modifiers.WIN;
}
// Disable repeating hotkey for Windows 7 and beyond, as described in #1559
if (isWindows7OrOlder) {
if (IsWindows7OrOlder) {
modifiers |= (uint)Modifiers.NO_REPEAT;
}
if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) {
keyHandlers.Add(hotKeyCounter, handler);
return hotKeyCounter++;
if (RegisterHotKey(_hotkeyHwnd, _hotKeyCounter, modifiers, (uint)virtualKeyCode)) {
KeyHandlers.Add(_hotKeyCounter, handler);
return _hotKeyCounter++;
} else {
LOG.Warn(String.Format("Couldn't register hotkey modifier {0} virtualKeyCode {1}", modifierKeyCode, virtualKeyCode));
Log.Warn($"Couldn't register hotkey modifier {modifierKeyCode} virtualKeyCode {virtualKeyCode}");
return -1;
}
}
public static void UnregisterHotkeys() {
foreach(int hotkey in keyHandlers.Keys) {
UnregisterHotKey(hotkeyHWND, hotkey);
foreach(int hotkey in KeyHandlers.Keys) {
UnregisterHotKey(_hotkeyHwnd, hotkey);
}
// Remove all key handlers
keyHandlers.Clear();
KeyHandlers.Clear();
}
public static void UnregisterHotkey(int hotkey) {
bool removeHotkey = false;
foreach(int availableHotkey in keyHandlers.Keys) {
foreach(int availableHotkey in KeyHandlers.Keys) {
if (availableHotkey == hotkey) {
UnregisterHotKey(hotkeyHWND, hotkey);
UnregisterHotKey(_hotkeyHwnd, hotkey);
removeHotkey = true;
}
}
if (removeHotkey) {
// Remove key handler
keyHandlers.Remove(hotkey);
KeyHandlers.Remove(hotkey);
}
}
@ -523,11 +514,11 @@ namespace GreenshotPlugin.Controls {
public static bool HandleMessages(ref Message m) {
if (m.Msg == WM_HOTKEY) {
// Call handler
if (isWindows7OrOlder) {
keyHandlers[(int)m.WParam]();
if (IsWindows7OrOlder) {
KeyHandlers[(int)m.WParam]();
} else {
if (eventDelay.Check()) {
keyHandlers[(int)m.WParam]();
if (EventDelay.Check()) {
KeyHandlers[(int)m.WParam]();
}
}
return true;
@ -537,10 +528,10 @@ namespace GreenshotPlugin.Controls {
public static string GetKeyName(Keys givenKey) {
StringBuilder keyName = new StringBuilder();
const uint NUMPAD = 55;
const uint numpad = 55;
Keys virtualKey = givenKey;
string keyString = "";
string keyString;
// Make VC's to real keys
switch(virtualKey) {
case Keys.Alt:
@ -553,17 +544,17 @@ namespace GreenshotPlugin.Controls {
virtualKey = Keys.LShiftKey;
break;
case Keys.Multiply:
GetKeyNameText(NUMPAD << 16, keyName, 100);
GetKeyNameText(numpad << 16, keyName, 100);
keyString = keyName.ToString().Replace("*","").Trim().ToLower();
if (keyString.IndexOf("(") >= 0) {
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0) {
return "* " + keyString;
}
keyString = keyString.Substring(0,1).ToUpper() + keyString.Substring(1).ToLower();
return keyString + " *";
case Keys.Divide:
GetKeyNameText(NUMPAD << 16, keyName, 100);
GetKeyNameText(numpad << 16, keyName, 100);
keyString = keyName.ToString().Replace("*","").Trim().ToLower();
if (keyString.IndexOf("(") >= 0) {
if (keyString.IndexOf("(", StringComparison.Ordinal) >= 0) {
return "/ " + keyString;
}
keyString = keyString.Substring(0,1).ToUpper() + keyString.Substring(1).ToLower();
@ -578,7 +569,7 @@ namespace GreenshotPlugin.Controls {
case Keys.End: case Keys.Home:
case Keys.Insert: case Keys.Delete:
case Keys.NumLock:
LOG.Debug("Modifying Extended bit");
Log.Debug("Modifying Extended bit");
scanCode |= 0x100; // set extended bit
break;
case Keys.PrintScreen: // PrintScreen

View file

@ -77,10 +77,10 @@ namespace GreenshotPlugin.Controls {
SIZE sourceSize;
DWM.DwmQueryThumbnailSourceSize(_thumbnailHandle, out sourceSize);
int thumbnailHeight = 200;
int thumbnailWidth = (int)(thumbnailHeight * ((float)sourceSize.Width / (float)sourceSize.Height));
int thumbnailWidth = (int)(thumbnailHeight * (sourceSize.Width / (float)sourceSize.Height));
if (parentControl != null && thumbnailWidth > parentControl.Width) {
thumbnailWidth = parentControl.Width;
thumbnailHeight = (int)(thumbnailWidth * ((float)sourceSize.Height / (float)sourceSize.Width));
thumbnailHeight = (int)(thumbnailWidth * (sourceSize.Height / (float)sourceSize.Width));
}
Width = thumbnailWidth;
Height = thumbnailHeight;