~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DesignerKeyBindings.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System.Collections.ObjectModel;
 
5
using System.Diagnostics;
 
6
using System.Linq;
 
7
using System.Windows.Input;
 
8
 
 
9
namespace ICSharpCode.WpfDesign.Designer.Services
 
10
{       
 
11
        class DesignerKeyBindings : IKeyBindingService
 
12
    {
 
13
        private readonly DesignSurface _surface;
 
14
        private Collection<KeyBinding> _bindings;
 
15
 
 
16
        public DesignerKeyBindings(DesignSurface surface)
 
17
        {
 
18
            Debug.Assert(surface != null);
 
19
            this._surface = surface;
 
20
            _bindings = new Collection<KeyBinding>();
 
21
        }
 
22
 
 
23
        public void RegisterBinding(KeyBinding binding)
 
24
        {
 
25
            if(binding!=null) {
 
26
                _surface.InputBindings.Add(binding);
 
27
                _bindings.Add(binding);
 
28
            }
 
29
        }
 
30
 
 
31
        public void DeregisterBinding(KeyBinding binding)
 
32
        {
 
33
            if(_bindings.Contains(binding)) {
 
34
                _surface.InputBindings.Remove(binding);
 
35
                _bindings.Remove(binding);
 
36
            }
 
37
        }
 
38
 
 
39
        public KeyBinding GetBinding(KeyGesture gesture)
 
40
        {
 
41
            return _bindings.FirstOrDefault(binding => binding.Key == gesture.Key && binding.Modifiers == gesture.Modifiers);
 
42
        }
 
43
 
 
44
        public object Owner{
 
45
            get { return _surface; }
 
46
        }
 
47
 
 
48
    }
 
49
}