2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.ui
.playback
.commands
;
18 import com
.intellij
.openapi
.ui
.playback
.PlaybackRunner
;
19 import com
.intellij
.openapi
.util
.ActionCallback
;
20 import com
.intellij
.openapi
.util
.Pair
;
26 public class KeyCodeTypeCommand
extends AlphaNumericTypeCommand
{
28 public static final String PREFIX
= CMD_PREFIX
+ "type";
29 public static final String CODE_DELIMITER
= ";";
30 public static final String MODIFIER_DELIMITER
= ":";
32 public KeyCodeTypeCommand(String text
, int line
) {
37 public ActionCallback
_execute(PlaybackRunner
.StatusCallback cb
, Robot robot
, boolean directActionCall
) {
38 String text
= getText().substring(PREFIX
.length()).trim();
40 int textDelim
= text
.indexOf(" ");
44 codes
= text
.substring(0, textDelim
);
50 if (codes
.length() + 1 < text
.length()) {
51 unicode
= text
.substring(textDelim
+ 1);
57 String
[] pairs
= codes
.split(CODE_DELIMITER
);
58 for (String eachPair
: pairs
) {
60 String
[] splits
= eachPair
.split(MODIFIER_DELIMITER
);
61 Integer code
= Integer
.valueOf(splits
[0]);
62 Integer modifier
= Integer
.valueOf(splits
[1]);
63 type(robot
, code
.intValue(), modifier
.intValue());
65 catch (NumberFormatException e
) {
66 dumpError(cb
, "Invalid code: " + eachPair
);
67 return new ActionCallback
.Rejected();
72 return new ActionCallback
.Done();
75 public static Pair
<java
.util
.List
<Integer
>, java
.util
.List
<Integer
>> parseKeyCodes(String keyCodesText
) {
76 ArrayList
<Integer
> codes
= new ArrayList
<Integer
>();
77 ArrayList
<Integer
> modifiers
= new ArrayList
<Integer
>();
79 if (keyCodesText
!= null) {
80 String
[] pairs
= keyCodesText
.split(CODE_DELIMITER
);
81 for (String each
: pairs
) {
82 String
[] strings
= each
.split(MODIFIER_DELIMITER
);
83 if (strings
.length
== 2) {
84 codes
.add(Integer
.valueOf(strings
[0]));
85 codes
.add(Integer
.valueOf(strings
[1]));
90 return new Pair
<java
.util
.List
<Integer
>, java
.util
.List
<Integer
>>(codes
, modifiers
);
93 public static String
unparseKeyCodes(Pair
<java
.util
.List
<Integer
>, java
.util
.List
<Integer
>> pairs
) {
94 StringBuffer result
= new StringBuffer();
96 java
.util
.List
<Integer
> codes
= pairs
.getFirst();
97 java
.util
.List
<Integer
> modifiers
= pairs
.getSecond();
99 for (int i
= 0; i
< codes
.size(); i
++) {
100 Integer each
= codes
.get(i
);
101 result
.append(each
.toString());
102 result
.append(MODIFIER_DELIMITER
);
103 result
.append(modifiers
.get(i
));
104 if (i
< codes
.size() - 1) {
105 result
.append(CODE_DELIMITER
);
109 return result
.toString();