diff options
author | Alan McGovern <alan@xamarin.com> | 2014-09-08 19:02:52 +0400 |
---|---|---|
committer | Alan McGovern <alan@xamarin.com> | 2014-09-08 19:07:13 +0400 |
commit | ece7fad1964f45650b6350cb603d9cda5462fec8 (patch) | |
tree | 70ac27b3c7e9a2601913945e16e9e0f4fc1d0509 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands | |
parent | 4263095256092824de66299fd505d9fe0bf98ac1 (diff) | |
parent | 53a1cba36671954c46ae00d33cfe65bcaa97edcc (diff) |
Merge remote-tracking branch 'origin/master' into xs6
Conflicts:
main/external/xwt
version-checks
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/Command.cs | 62 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/KeyBindingManager.cs | 52 |
2 files changed, 94 insertions, 20 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/Command.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/Command.cs index 5bac1ff279..9a0a69b78d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/Command.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/Command.cs @@ -95,10 +95,39 @@ namespace MonoDevelop.Components.Commands KeyBindingChanged (this, new KeyBindingChangedEventArgs (this, oldKeyBinding)); } } - + + string[] alternateAccelKeys; + KeyBinding[] alternateKeyBindings; + static readonly KeyBinding[] emptyBindings = new KeyBinding[0]; + + public string[] AlternateAccelKeys { + get { return alternateAccelKeys; } + set { + var oldKeybindings = alternateKeyBindings; + if (value == null || value.Length == 0) { + alternateKeyBindings = null; + } else { + alternateKeyBindings = new KeyBinding[value.Length]; + for (int i = 0; i < value.Length; i++) { + KeyBinding b; + KeyBinding.TryParse (value[i], out b); + alternateKeyBindings [i] = b; + } + } + alternateAccelKeys = value; + if (AlternateKeyBindingChanged != null) + AlternateKeyBindingChanged (this, new AlternateKeyBindingChangedEventArgs (this, oldKeybindings)); + } + } + public KeyBinding KeyBinding { get { return binding; } } + + public KeyBinding[] AlternateKeyBindings { + get { return alternateKeyBindings ?? emptyBindings; } + } + public bool DisabledVisible { get { return disabledVisible; } @@ -116,26 +145,49 @@ namespace MonoDevelop.Components.Commands } public event KeyBindingChangedEventHandler KeyBindingChanged; + public event EventHandler<AlternateKeyBindingChangedEventArgs> AlternateKeyBindingChanged; } - public class KeyBindingChangedEventArgs { + public class KeyBindingChangedEventArgs : EventArgs + { public KeyBindingChangedEventArgs (Command command, KeyBinding oldKeyBinding) { OldKeyBinding = oldKeyBinding; Command = command; } - + public Command Command { get; private set; } - + public KeyBinding OldKeyBinding { get; private set; } - + public KeyBinding NewKeyBinding { get { return Command.KeyBinding; } } } + + public class AlternateKeyBindingChangedEventArgs : EventArgs + { + public AlternateKeyBindingChangedEventArgs (Command command, KeyBinding[] oldKeyBinding) + { + OldKeyBinding = oldKeyBinding; + Command = command; + } + + public Command Command { + get; private set; + } + + public KeyBinding[] OldKeyBinding { + get; private set; + } + + public KeyBinding[] NewKeyBinding { + get { return Command.AlternateKeyBindings; } + } + } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/KeyBindingManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/KeyBindingManager.cs index ced8041eb8..b4a590202b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/KeyBindingManager.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/KeyBindingManager.cs @@ -644,7 +644,17 @@ namespace MonoDevelop.Components.Commands { SetBinding (args.Command, args.OldKeyBinding, args.NewKeyBinding); } - + + void OnAlternateKeyBindingChanged (object sender, AlternateKeyBindingChangedEventArgs args) + { + var upperBound = Math.Max (args.NewKeyBinding != null ? args.NewKeyBinding.Length : 0, args.OldKeyBinding != null ? args.OldKeyBinding.Length : 0); + for (int i = 0; i < upperBound; i++) { + SetBinding (args.Command, + args.OldKeyBinding != null && i < args.OldKeyBinding.Length ? args.OldKeyBinding[i] : null, + args.NewKeyBinding != null && i < args.NewKeyBinding.Length ? args.NewKeyBinding[i] : null ); + } + } + public bool CommandIsRegistered (Command command) { return commands.Contains (command); @@ -658,36 +668,48 @@ namespace MonoDevelop.Components.Commands } SetBinding (command, null, command.KeyBinding); + foreach (var binding in command.AlternateKeyBindings) { + SetBinding (command, null, binding); + } + command.KeyBindingChanged += OnKeyBindingChanged; + command.AlternateKeyBindingChanged += OnAlternateKeyBindingChanged; commands.Add (command); } - + + public void UnregisterCommand (Command command) { - List<Command> list; - int refs; - if (!commands.Contains (command)) { Console.WriteLine ("WARNING: trying to unregister unknown command {0}", command); return; } command.KeyBindingChanged -= OnKeyBindingChanged; + command.AlternateKeyBindingChanged -= OnAlternateKeyBindingChanged; commands.Remove (command); - - if (command.KeyBinding == null) - return; - list = bindings[command.KeyBinding]; + RemoveKeyBinding (command, command.KeyBinding); + foreach (var altBinding in command.AlternateKeyBindings) { + RemoveKeyBinding (command, altBinding); + } + } + + void RemoveKeyBinding (Command command, KeyBinding bindingToRemove) + { + if (bindingToRemove == null) + return; + var list = bindings [bindingToRemove]; + int refs; list.Remove (command); if (list.Count == 0) - bindings.Remove (command.KeyBinding); - - if (!command.KeyBinding.Chord.IsEmpty && chords.ContainsKey (command.KeyBinding.Chord)) { - if ((refs = chords[command.KeyBinding.Chord] - 1) == 0) - chords.Remove (command.KeyBinding.Chord); + bindings.Remove (bindingToRemove); + + if (!bindingToRemove.Chord.IsEmpty && chords.ContainsKey (bindingToRemove.Chord)) { + if ((refs = chords [bindingToRemove.Chord] - 1) == 0) + chords.Remove (bindingToRemove.Chord); else - chords[command.KeyBinding.Chord] = refs; + chords [bindingToRemove.Chord] = refs; } } |