comparison dwtx/jface/bindings/keys/KeyBinding.d @ 16:e0f0aaf75edd

PopupDialog, bindings and actions
author Frank Benoit <benoit@tionex.de>
date Tue, 01 Apr 2008 08:00:31 +0200
parents
children ea8ff534f622
comparison
equal deleted inserted replaced
15:db8940420ed8 16:e0f0aaf75edd
1 /*******************************************************************************
2 * Copyright (c) 2004, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.jface.bindings.keys.KeyBinding;
14
15 import dwtx.jface.bindings.keys.KeySequence;
16
17 import dwtx.core.commands.ParameterizedCommand;
18 import dwtx.jface.bindings.Binding;
19 import dwtx.jface.bindings.TriggerSequence;
20
21 import dwt.dwthelper.utils;
22
23 /**
24 * <p>
25 * A keyboard shortcut. This is a binding between some keyboard input and the
26 * triggering of a command. This object is immutable.
27 * </p>
28 *
29 * @since 3.1
30 */
31 public final class KeyBinding : Binding {
32
33 /**
34 * The key sequence which triggers this binding. This sequence is never
35 * <code>null</code>.
36 */
37 private const KeySequence keySequence;
38
39 /**
40 * Constructs a new instance of <code>KeyBinding</code>.
41 *
42 * @param keySequence
43 * The key sequence which should trigger this binding. This value
44 * must not be <code>null</code>. It also must be a complete,
45 * non-empty key sequence.
46 * @param command
47 * The parameterized command to which this binding applies; this
48 * value may be <code>null</code> if the binding is meant to
49 * "unbind" a previously defined binding.
50 * @param schemeId
51 * The scheme to which this binding belongs; this value must not
52 * be <code>null</code>.
53 * @param contextId
54 * The context to which this binding applies; this value must not
55 * be <code>null</code>.
56 * @param locale
57 * The locale to which this binding applies; this value may be
58 * <code>null</code> if it applies to all locales.
59 * @param platform
60 * The platform to which this binding applies; this value may be
61 * <code>null</code> if it applies to all platforms.
62 * @param windowManager
63 * The window manager to which this binding applies; this value
64 * may be <code>null</code> if it applies to all window
65 * managers. This value is currently ignored.
66 * @param type
67 * The type of binding. This should be either <code>SYSTEM</code>
68 * or <code>USER</code>.
69 */
70 public this(KeySequence keySequence,
71 ParameterizedCommand command, String schemeId,
72 String contextId, String locale, String platform,
73 String windowManager, int type) {
74 super(command, schemeId, contextId, locale, platform, windowManager,
75 type);
76
77 if (keySequence is null) {
78 throw new NullPointerException("The key sequence cannot be null"); //$NON-NLS-1$
79 }
80
81 if (!keySequence.isComplete()) {
82 throw new IllegalArgumentException(
83 "Cannot bind to an incomplete key sequence"); //$NON-NLS-1$
84 }
85
86 if (keySequence.isEmpty()) {
87 throw new IllegalArgumentException(
88 "Cannot bind to an empty key sequence"); //$NON-NLS-1$
89 }
90
91 this.keySequence = keySequence;
92 }
93
94 /**
95 * Returns the key sequence which triggers this binding. The key sequence
96 * will not be <code>null</code>, empty or incomplete.
97 *
98 * @return The key sequence; never <code>null</code>.
99 */
100 public final KeySequence getKeySequence() {
101 return keySequence;
102 }
103
104 /*
105 * (non-Javadoc)
106 *
107 * @see dwtx.jface.bindings.Binding#getTriggerSequence()
108 */
109 public TriggerSequence getTriggerSequence() {
110 return getKeySequence();
111 }
112 }