~ubuntu-branches/ubuntu/lucid/jedit/lucid

« back to all changes in this revision

Viewing changes to jEdit/org/gjt/sp/jedit/gui/DefaultInputHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Hahler
  • Date: 2008-03-18 22:18:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080318221817-8pvhmkoy8nkdghy2
Tags: 4.3~pre13.dfsg-0ubuntu1
* New upstream bugfix release (LP: #203713)
* debian/control, debian/rules:
  replace icedtea-java7 references with openjdk-6 references (LP: #203636)
* Reworked (and renamed) patches:
  - 01-debian-menu-file.patch: partly applied upstream
  - 02-desktop-file-icon-file.patch: incorporate previous inline change
    (icon path)
* 03-svn-php_mode_fix_special_comment.patch: Fix regression for special
  comments ("/**/") in PHP mode; can be dropped with the next release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import java.awt.event.InputEvent;
27
27
import java.awt.Toolkit;
28
28
import java.util.Hashtable;
29
 
import java.util.StringTokenizer;
30
29
import org.gjt.sp.jedit.*;
31
30
//}}}
32
31
 
34
33
 * The default input handler. It maps sequences of keystrokes into actions
35
34
 * and inserts key typed events into the text area.
36
35
 * @author Slava Pestov
37
 
 * @version $Id: DefaultInputHandler.java 11035 2007-11-12 19:44:17Z kpouer $
 
36
 * @version $Id: DefaultInputHandler.java 11402 2007-12-12 19:41:18Z kpouer $
38
37
 */
39
38
public class DefaultInputHandler extends InputHandler
40
39
{
79
78
                this(view,copy.bindings);
80
79
        } //}}}
81
80
 
82
 
        //{{{ addKeyBinding() method
83
 
        /**
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
92
 
         */
93
 
        public void addKeyBinding(String keyBinding, String action)
94
 
        {
95
 
                addKeyBinding(keyBinding,(Object)action);
96
 
        } //}}}
97
 
 
98
 
        //{{{ addKeyBinding() method
99
 
        /**
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
107
 
         */
108
 
        public void addKeyBinding(String keyBinding, EditAction action)
109
 
        {
110
 
                addKeyBinding(keyBinding,(Object)action);
111
 
        } //}}}
112
 
 
113
 
        //{{{ addKeyBinding() method
114
 
        /**
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
123
 
         */
124
 
        public void addKeyBinding(String keyBinding, Object action)
125
 
        {
126
 
                Hashtable current = bindings;
127
 
 
128
 
                String prefixStr = null;
129
 
 
130
 
                StringTokenizer st = new StringTokenizer(keyBinding);
131
 
                while(st.hasMoreTokens())
132
 
                {
133
 
                        String keyCodeStr = st.nextToken();
134
 
                        if(prefixStr == null)
135
 
                                prefixStr = keyCodeStr;
136
 
                        else
137
 
                                prefixStr = prefixStr + " " + keyCodeStr;
138
 
 
139
 
                        KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(keyCodeStr);
140
 
                        if(keyStroke == null)
141
 
                                return;
142
 
 
143
 
                        if(st.hasMoreTokens())
144
 
                        {
145
 
                                Object o = current.get(keyStroke);
146
 
                                if(o instanceof Hashtable)
147
 
                                        current = (Hashtable)o;
148
 
                                else
149
 
                                {
150
 
                                        Hashtable hash = new Hashtable();
151
 
                                        hash.put(PREFIX_STR,prefixStr);
152
 
                                        o = hash;
153
 
                                        current.put(keyStroke,o);
154
 
                                        current = (Hashtable)o;
155
 
                                }
156
 
                        }
157
 
                        else
158
 
                                current.put(keyStroke,action);
159
 
                }
160
 
        } //}}}
161
 
 
162
 
        //{{{ removeKeyBinding() method
163
 
        /**
164
 
         * Removes a key binding from this input handler. This is not yet
165
 
         * implemented.
166
 
         * @param keyBinding The key binding
167
 
         */
168
 
        public void removeKeyBinding(String keyBinding)
169
 
        {
170
 
                Hashtable current = bindings;
171
 
 
172
 
                StringTokenizer st = new StringTokenizer(keyBinding);
173
 
                while(st.hasMoreTokens())
174
 
                {
175
 
                        String keyCodeStr = st.nextToken();
176
 
                        KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(keyCodeStr);
177
 
                        if(keyStroke == null)
178
 
                                return;
179
 
 
180
 
                        if(st.hasMoreTokens())
181
 
                        {
182
 
                                Object o = current.get(keyStroke);
183
 
                                if(o instanceof Hashtable)
184
 
                                        current = ((Hashtable)o);
185
 
                                else if(o != null)
186
 
                                {
187
 
                                        // we have binding foo
188
 
                                        // but user asks to remove foo bar?
189
 
                                        current.remove(keyStroke);
190
 
                                        return;
191
 
                                }
192
 
                                else
193
 
                                {
194
 
                                        // user asks to remove non-existent
195
 
                                        return;
196
 
                                }
197
 
                        }
198
 
                        else
199
 
                                current.remove(keyStroke);
200
 
                }
201
 
        } //}}}
202
 
 
203
 
        //{{{ removeAllKeyBindings() method
204
 
        /**
205
 
         * Removes all key bindings from this input handler.
206
 
         */
207
 
        public void removeAllKeyBindings()
208
 
        {
209
 
                bindings.clear();
210
 
        } //}}}
211
 
 
212
 
        //{{{ getKeyBinding() method
213
 
        /**
214
 
         * Returns either an edit action, or a hashtable if the specified key
215
 
         * is a prefix.
216
 
         * @param keyBinding The key binding
217
 
         * @since jEdit 3.2pre5
218
 
         */
219
 
        public Object getKeyBinding(String keyBinding)
220
 
        {
221
 
                Hashtable current = bindings;
222
 
                StringTokenizer st = new StringTokenizer(keyBinding);
223
 
 
224
 
                while(st.hasMoreTokens())
225
 
                {
226
 
                        KeyEventTranslator.Key keyStroke = KeyEventTranslator.parseKey(
227
 
                                st.nextToken());
228
 
                        if(keyStroke == null)
229
 
                                return null;
230
 
 
231
 
                        if(st.hasMoreTokens())
232
 
                        {
233
 
                                Object o = current.get(keyStroke);
234
 
                                if(o instanceof Hashtable)
235
 
                                {
236
 
                                        if(!st.hasMoreTokens())
237
 
                                                return o;
238
 
                                        else
239
 
                                                current = (Hashtable)o;
240
 
                                }
241
 
                                else
242
 
                                        return o;
243
 
                        }
244
 
                        else
245
 
                        {
246
 
                                return current.get(keyStroke);
247
 
                        }
248
 
                }
249
 
 
250
 
                return null;
251
 
        } //}}}
252
 
 
253
81
        //{{{ isPrefixActive() method
254
82
        /**
255
83
         * Returns if a prefix key has been pressed.
256
84
         */
 
85
        @Override
257
86
        public boolean isPrefixActive()
258
87
        {
259
88
                return bindings != currentBindings
260
89
                        || super.isPrefixActive();
261
90
        } //}}}
262
91
 
263
 
        //{{{ setBindings() method
264
 
        /**
265
 
         * Replace the set of key bindings.
266
 
         * @since jEdit 4.3pre1
267
 
         */
268
 
        public void setBindings(Hashtable bindings)
269
 
        {
270
 
                this.bindings = this.currentBindings = bindings;
271
 
        } //}}}
272
 
 
273
92
        //{{{ setCurrentBindings() method
 
93
        @Override
274
94
        public void setCurrentBindings(Hashtable bindings)
275
95
        {
276
96
                view.getStatus().setMessage((String)bindings.get(PREFIX_STR));
306
126
                {
307
127
                        if(input != '\0')
308
128
                        {
309
 
                                if (!dryRun) {
 
129
                                if (!dryRun)
 
130
                                {
310
131
                                        setCurrentBindings(bindings);
311
132
                                        invokeReadNextChar(input);
312
133
                                        repeatCount = 1;
315
136
                        }
316
137
                        else
317
138
                        {
318
 
                                if (!dryRun) {
 
139
                                if (!dryRun) 
 
140
                                {
319
141
                                        readNextChar = null;
320
142
                                        view.getStatus().setMessage(null);
321
143
                                }
325
147
                Object o = currentBindings.get(keyStroke);
326
148
                if(o == null)
327
149
                {
328
 
                        if (!dryRun) {
 
150
                        if (!dryRun) 
 
151
                        {
329
152
                                // Don't beep if the user presses some
330
153
                                // key we don't know about unless a
331
154
                                // prefix is active. Otherwise it will
338
161
                                        repeatCount = 1;
339
162
                                        setCurrentBindings(bindings);
340
163
                                }
341
 
                                else if(input != '\0') {
342
 
                                        if (!keyStroke.isFromGlobalContext()) { // let user input be only local
 
164
                                else if(input != '\0') 
 
165
                                {
 
166
                                        if (!keyStroke.isFromGlobalContext()) 
 
167
                                        { // let user input be only local
343
168
                                                userInput(input);
344
169
                                        }
345
 
                                } else  {
 
170
                                } 
 
171
                                else
 
172
                                {
346
173
                                        // this is retarded. excuse me while I drool
347
174
                                        // and make stupid noises
348
175
                                        if(KeyEventWorkaround.isNumericKeypad(keyStroke.key))
353
180
                }
354
181
                else if(o instanceof Hashtable)
355
182
                {
356
 
                        if (!dryRun) {
 
183
                        if (!dryRun) 
 
184
                        {
357
185
                                setCurrentBindings((Hashtable)o);
358
186
                                ShortcutPrefixActiveEvent.firePrefixStateChange(currentBindings, true);
359
187
                                shortcutOn = true;
362
190
                }
363
191
                else if(o instanceof String)
364
192
                {
365
 
                        if (!dryRun) {
 
193
                        if (!dryRun) 
 
194
                        {
366
195
                                setCurrentBindings(bindings);
367
196
                                sendShortcutPrefixOff();
368
197
                                invokeAction((String)o);
371
200
                }
372
201
                else if(o instanceof EditAction)
373
202
                {
374
 
                        if (!dryRun) {
 
203
                        if (!dryRun)
 
204
                        {
375
205
                                setCurrentBindings(bindings);
376
206
                                sendShortcutPrefixOff();
377
207
                                invokeAction((EditAction)o);
378
208
                        }
379
209
                        return true;
380
210
                }
381
 
                if (!dryRun) {
 
211
                if (!dryRun)
 
212
                {
382
213
                        sendShortcutPrefixOff();
383
214
                }
384
215
                return false;
385
216
        } //}}}
386
 
 
387
 
        //{{{ handleKey() methodprotected void sendShortcutPrefixOff()
388
 
        /**
389
 
         *  If 
390
 
         */
391
 
        protected void sendShortcutPrefixOff()
392
 
        {
393
 
                if( shortcutOn)
394
 
                {
395
 
                        ShortcutPrefixActiveEvent.firePrefixStateChange(null, false);
396
 
                        shortcutOn = false;
397
 
                }
398
 
        } //}}}
399
 
        
400
 
        protected boolean shortcutOn=false;
401
217
        
402
218
        //{{{ getSymbolicModifierName() method
403
219
        /**
426
242
        {
427
243
                return KeyEventTranslator.getModifierString(evt);
428
244
        } //}}}
429
 
 
430
 
        //{{{ Private members
431
 
 
432
 
        // Stores prefix name in bindings hashtable
433
 
        public static Object PREFIX_STR = "PREFIX_STR";
434
 
 
435
 
        private Hashtable bindings;
436
 
        private Hashtable currentBindings;
437
 
        //}}}
438
 
 
439
245
}