79
78
this(view,copy.bindings);
82
//{{{ addKeyBinding() method
84
* Adds a key binding to this input handler. The key binding is
85
* a list of white space separated key strokes of the form
86
* <i>[modifiers+]key</i> where modifier is C for Control, A for Alt,
87
* or S for Shift, and key is either a character (a-z) or a field
88
* name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
89
* @param keyBinding The key binding
90
* @param action The action
91
* @since jEdit 4.2pre1
93
public void addKeyBinding(String keyBinding, String action)
95
addKeyBinding(keyBinding,(Object)action);
98
//{{{ addKeyBinding() method
100
* Adds a key binding to this input handler. The key binding is
101
* a list of white space separated key strokes of the form
102
* <i>[modifiers+]key</i> where modifier is C for Control, A for Alt,
103
* or S for Shift, and key is either a character (a-z) or a field
104
* name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
105
* @param keyBinding The key binding
106
* @param action The action
108
public void addKeyBinding(String keyBinding, EditAction action)
110
addKeyBinding(keyBinding,(Object)action);
113
//{{{ addKeyBinding() method
115
* Adds a key binding to this input handler. The key binding is
116
* a list of white space separated key strokes of the form
117
* <i>[modifiers+]key</i> where modifier is C for Control, A for Alt,
118
* or S for Shift, and key is either a character (a-z) or a field
119
* name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
120
* @param keyBinding The key binding
121
* @param action The action
122
* @since jEdit 4.3pre1
124
public void addKeyBinding(String keyBinding, Object action)
126
Hashtable current = bindings;
128
String prefixStr = null;
130
StringTokenizer st = new StringTokenizer(keyBinding);
131
while(st.hasMoreTokens())
133
String keyCodeStr = st.nextToken();
134
if(prefixStr == null)
135
prefixStr = keyCodeStr;
137
prefixStr = prefixStr + " " + keyCodeStr;
139
KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(keyCodeStr);
140
if(keyStroke == null)
143
if(st.hasMoreTokens())
145
Object o = current.get(keyStroke);
146
if(o instanceof Hashtable)
147
current = (Hashtable)o;
150
Hashtable hash = new Hashtable();
151
hash.put(PREFIX_STR,prefixStr);
153
current.put(keyStroke,o);
154
current = (Hashtable)o;
158
current.put(keyStroke,action);
162
//{{{ removeKeyBinding() method
164
* Removes a key binding from this input handler. This is not yet
166
* @param keyBinding The key binding
168
public void removeKeyBinding(String keyBinding)
170
Hashtable current = bindings;
172
StringTokenizer st = new StringTokenizer(keyBinding);
173
while(st.hasMoreTokens())
175
String keyCodeStr = st.nextToken();
176
KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(keyCodeStr);
177
if(keyStroke == null)
180
if(st.hasMoreTokens())
182
Object o = current.get(keyStroke);
183
if(o instanceof Hashtable)
184
current = ((Hashtable)o);
187
// we have binding foo
188
// but user asks to remove foo bar?
189
current.remove(keyStroke);
194
// user asks to remove non-existent
199
current.remove(keyStroke);
203
//{{{ removeAllKeyBindings() method
205
* Removes all key bindings from this input handler.
207
public void removeAllKeyBindings()
212
//{{{ getKeyBinding() method
214
* Returns either an edit action, or a hashtable if the specified key
216
* @param keyBinding The key binding
217
* @since jEdit 3.2pre5
219
public Object getKeyBinding(String keyBinding)
221
Hashtable current = bindings;
222
StringTokenizer st = new StringTokenizer(keyBinding);
224
while(st.hasMoreTokens())
226
KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(
228
if(keyStroke == null)
231
if(st.hasMoreTokens())
233
Object o = current.get(keyStroke);
234
if(o instanceof Hashtable)
236
if(!st.hasMoreTokens())
239
current = (Hashtable)o;
246
return current.get(keyStroke);
253
81
//{{{ isPrefixActive() method
255
83
* Returns if a prefix key has been pressed.
257
86
public boolean isPrefixActive()
259
88
return bindings != currentBindings
260
89
|| super.isPrefixActive();
263
//{{{ setBindings() method
265
* Replace the set of key bindings.
266
* @since jEdit 4.3pre1
268
public void setBindings(Hashtable bindings)
270
this.bindings = this.currentBindings = bindings;
273
92
//{{{ setCurrentBindings() method
274
94
public void setCurrentBindings(Hashtable bindings)
276
96
view.getStatus().setMessage((String)bindings.get(PREFIX_STR));