-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dustincjensen/customized-key-bindings
Customized key bindings
- Loading branch information
Showing
13 changed files
with
698 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<configSections> | ||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | ||
<section name="Snapper.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> | ||
</sectionGroup> | ||
</configSections> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /> | ||
</startup> | ||
<userSettings> | ||
<Snapper.Properties.Settings> | ||
<setting name="SwapMonitor" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="BottomLeft" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="Bottom" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="BottomRight" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="Left" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="Mid" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="Right" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="TopLeft" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="Top" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="TopRight" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
</Snapper.Properties.Settings> | ||
</userSettings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Snapper.Common | ||
{ | ||
public class ViewModelBase : INotifyPropertyChanged | ||
{ | ||
protected ViewModelBase() {} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Snapper | ||
{ | ||
public enum KeyBindEnum | ||
{ | ||
SwapMonitor, | ||
BottomLeft, | ||
Bottom, | ||
BottomRight, | ||
Left, | ||
Mid, | ||
Right, | ||
TopLeft, | ||
Top, | ||
TopRight | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace Snapper | ||
{ | ||
public static class KeyBindSettings | ||
{ | ||
public static Tuple<ModifierKeys, Key> GetSetting(KeyBindEnum purpose) | ||
{ | ||
var keyCombo = (string)Properties.Settings.Default[purpose.ToString()]; | ||
var keyStrings = keyCombo.Split(','); | ||
var possibleKey = Key.None; | ||
var modifierKeys = ModifierKeys.None; | ||
|
||
foreach (var keyString in keyStrings) | ||
{ | ||
Key tmpKey; | ||
ModifierKeys tmpModifier; | ||
|
||
Enum.TryParse(keyString, out tmpKey); | ||
Enum.TryParse(keyString, out tmpModifier); | ||
|
||
if (tmpKey != Key.None) | ||
{ | ||
possibleKey = tmpKey; | ||
} | ||
else if (tmpModifier != ModifierKeys.None) | ||
{ | ||
modifierKeys = modifierKeys | tmpModifier; | ||
} | ||
} | ||
|
||
return (possibleKey == Key.None && modifierKeys == ModifierKeys.None) | ||
// Return a default for this keybind. | ||
? _GetDefaultKeyBind(purpose) | ||
// Or the specified one in the settings file | ||
: new Tuple<ModifierKeys, Key>(modifierKeys, possibleKey); | ||
} | ||
|
||
private static Tuple<ModifierKeys, Key> _GetDefaultKeyBind(KeyBindEnum purpose) | ||
{ | ||
Key key; | ||
|
||
switch (purpose) | ||
{ | ||
case KeyBindEnum.BottomLeft: | ||
key = Key.NumPad1; | ||
break; | ||
case KeyBindEnum.Bottom: | ||
key = Key.NumPad2; | ||
break; | ||
case KeyBindEnum.BottomRight: | ||
key = Key.NumPad3; | ||
break; | ||
case KeyBindEnum.Left: | ||
key = Key.NumPad4; | ||
break; | ||
case KeyBindEnum.Mid: | ||
key = Key.NumPad5; | ||
break; | ||
case KeyBindEnum.Right: | ||
key = Key.NumPad6; | ||
break; | ||
case KeyBindEnum.TopLeft: | ||
key = Key.NumPad7; | ||
break; | ||
case KeyBindEnum.Top: | ||
key = Key.NumPad8; | ||
break; | ||
case KeyBindEnum.TopRight: | ||
key = Key.NumPad9; | ||
break; | ||
case KeyBindEnum.SwapMonitor: | ||
key = Key.NumPad0; | ||
break; | ||
default: | ||
key = Key.NumPad0; | ||
break; | ||
} | ||
|
||
return new Tuple<ModifierKeys, Key>(ModifierKeys.Control | ModifierKeys.Alt, key); | ||
} | ||
|
||
public static void SetSetting(string value, KeyBindEnum purpose) | ||
{ | ||
switch (purpose) | ||
{ | ||
case KeyBindEnum.BottomLeft: | ||
Properties.Settings.Default.BottomLeft = value; | ||
break; | ||
case KeyBindEnum.Bottom: | ||
Properties.Settings.Default.Bottom = value; | ||
break; | ||
case KeyBindEnum.BottomRight: | ||
Properties.Settings.Default.BottomRight = value; | ||
break; | ||
case KeyBindEnum.Left: | ||
Properties.Settings.Default.Left = value; | ||
break; | ||
case KeyBindEnum.Mid: | ||
Properties.Settings.Default.Mid = value; | ||
break; | ||
case KeyBindEnum.Right: | ||
Properties.Settings.Default.Right = value; | ||
break; | ||
case KeyBindEnum.TopLeft: | ||
Properties.Settings.Default.TopLeft = value; | ||
break; | ||
case KeyBindEnum.Top: | ||
Properties.Settings.Default.Top = value; | ||
break; | ||
case KeyBindEnum.TopRight: | ||
Properties.Settings.Default.TopRight = value; | ||
break; | ||
case KeyBindEnum.SwapMonitor: | ||
Properties.Settings.Default.SwapMonitor = value; | ||
break; | ||
} | ||
Properties.Settings.Default.Save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.