2121import javax .sound .sampled .AudioSystem ;
2222import javax .sound .sampled .Clip ;
2323import java .awt .*;
24- import java .awt .event .KeyEvent ;
2524import java .io .IOException ;
25+ import java .util .Collection ;
2626import java .util .logging .Level ;
2727import java .util .logging .Logger ;
2828
29+ import static java .awt .event .KeyEvent .*;
30+
2931/**
3032 * Created by breandan on 10/23/2015.
3133 */
@@ -54,6 +56,7 @@ public ASRControlLoop(CustomLiveSpeechRecognizer recognizer) {
5456 public static final String SHRINK = "shrink" ;
5557 public static final String PRESS = "press" ;
5658 public static final String DELETE = "delete" ;
59+ public static final String DEBUG = "debug" ;
5760 public static final String ENTER = "enter" ;
5861 public static final String ESCAPE = "escape" ;
5962 public static final String TAB = "tab" ;
@@ -105,6 +108,7 @@ private String getResultFromRecognizer() {
105108 logger .info ("\t Top H: " + result .getResult () + " / " + result .getResult ().getBestToken () + " / " + result .getResult ().getBestPronunciationResult ());
106109 logger .info ("\t Top 3H: " + result .getNbest (3 ));
107110
111+ Collection <String > c = result .getNbest (3 );
108112 return result .getHypothesis ();
109113 }
110114
@@ -119,7 +123,7 @@ private void applyAction(String c) {
119123 } else if (c .endsWith (RECENT )) {
120124 ideService .invokeAction (IdeActions .ACTION_RECENT_FILES );
121125 } else if (c .endsWith (TERMINAL )) {
122- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_F12 );
126+ pressKeystroke (VK_ALT , VK_F12 );
123127 }
124128 } else if (c .startsWith (NAVIGATE )) {
125129 ideService .invokeAction ("GotoDeclaration" );
@@ -130,53 +134,67 @@ private void applyAction(String c) {
130134 ideService .invokeAction ("Idear.WhereAmI" );
131135 } else if (c .startsWith ("focus" )) {
132136 if (c .endsWith (EDITOR )) {
133- pressKeystroke (KeyEvent . VK_ESCAPE );
137+ pressKeystroke (VK_ESCAPE );
134138 } else if (c .endsWith (PROJECT )) {
135- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_1 );
139+ pressKeystroke (VK_ALT , VK_1 );
136140 } else if (c .endsWith ("symbols" )) {
137141 ideService .invokeAction ("AceJumpAction" );
142+ ideService .type (VK_SPACE );
138143 ideService .type (("" + recognizeNumber ()).toCharArray ());
139144 }
145+ } else if (c .startsWith (GOTO )) {
146+
140147 } else if (c .startsWith (EXPAND )) {
141- pressKeystroke (KeyEvent .VK_CONTROL , KeyEvent .VK_W );
148+ // ActionManager instance = ActionManager.getInstance();
149+ // AnAction a = instance.getAction("EditorSelectWord");
150+ // AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(),
151+ // ActionPlaces.UNKNOWN, a.getTemplatePresentation(), instance, 0);
152+ // a.actionPerformed(event);
153+ ideService .invokeAction ("EditorSelectWord" );
142154 } else if (c .startsWith (SHRINK )) {
143- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_SHIFT , KeyEvent . VK_W );
155+ pressKeystroke (VK_CONTROL , VK_SHIFT , VK_W );
144156 } else if (c .startsWith ("press" )) {
145157 if (c .contains ("delete" )) {
146- pressKeystroke (KeyEvent . VK_DELETE );
147- } else if (c .contains ("return" )) {
148- pressKeystroke (KeyEvent . VK_ENTER );
158+ pressKeystroke (VK_DELETE );
159+ } else if (c .contains ("return" ) || c . contains ( "enter" ) ) {
160+ pressKeystroke (VK_ENTER );
149161 } else if (c .contains (ESCAPE )) {
150- pressKeystroke (KeyEvent . VK_ESCAPE );
162+ pressKeystroke (VK_ESCAPE );
151163 } else if (c .contains (TAB )) {
152- pressKeystroke (KeyEvent . VK_TAB );
164+ pressKeystroke (VK_TAB );
153165 } else if (c .contains (UNDO )) {
154- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_Z );
166+ pressKeystroke (VK_CONTROL , VK_Z );
155167 }
156168 } else if (c .startsWith ("following" )) {
157169 if (c .endsWith ("line" )) {
158- pressKeystroke (KeyEvent . VK_DOWN );
170+ pressKeystroke (VK_DOWN );
159171 } else if (c .endsWith ("page" )) {
160- pressKeystroke (KeyEvent . VK_PAGE_DOWN );
172+ pressKeystroke (VK_PAGE_DOWN );
161173 } else if (c .endsWith ("method" )) {
162- pressKeystroke (KeyEvent .VK_ALT , KeyEvent .VK_DOWN );
174+ pressKeystroke (VK_ALT , VK_DOWN );
175+ } else if (c .endsWith ("tab" )) {
176+ pressKeystroke (VK_CONTROL , VK_TAB );
177+ } else if (c .endsWith ("page" )) {
178+ pressKeystroke (VK_PAGE_DOWN );
163179 }
164180 } else if (c .startsWith ("previous" )) {
165181 if (c .endsWith ("line" )) {
166- pressKeystroke (KeyEvent . VK_UP );
182+ pressKeystroke (VK_UP );
167183 } else if (c .endsWith ("page" )) {
168- pressKeystroke (KeyEvent . VK_PAGE_UP );
184+ pressKeystroke (VK_PAGE_UP );
169185 } else if (c .endsWith ("method" )) {
170- pressKeystroke (KeyEvent .VK_ALT , KeyEvent .VK_UP );
186+ pressKeystroke (VK_ALT , VK_UP );
187+ } else if (c .endsWith ("page" )) {
188+ pressKeystroke (VK_PAGE_UP );
171189 }
172190 } else if (c .startsWith ("extract this" )) {
173191 if (c .endsWith ("method" )) {
174- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_ALT , KeyEvent . VK_M );
192+ pressKeystroke (VK_CONTROL , VK_ALT , VK_M );
175193 } else if (c .endsWith ("parameter" )) {
176- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_ALT , KeyEvent . VK_P );
194+ pressKeystroke (VK_CONTROL , VK_ALT , VK_P );
177195 }
178196 } else if (c .startsWith ("inspect code" )) {
179- pressKeystroke (KeyEvent . VK_ALT , KeyEvent . VK_SHIFT , KeyEvent . VK_I );
197+ pressKeystroke (VK_ALT , VK_SHIFT , VK_I );
180198 } else if (c .startsWith ("speech pause" )) {
181199 pauseSpeech ();
182200 } else if (c .startsWith (OK_IDEA ) || c .startsWith (OKAY_IDEA )) {
@@ -187,16 +205,22 @@ private void applyAction(String c) {
187205 fireGoogleSearch ();
188206 } else if (c .contains ("break point" )) {
189207 if (c .startsWith ("toggle" )) {
190- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_F8 );
208+ pressKeystroke (VK_CONTROL , VK_F8 );
191209 } else if (c .startsWith ("view" )) {
192- pressKeystroke (KeyEvent . VK_CONTROL , KeyEvent . VK_SHIFT , KeyEvent . VK_F8 );
210+ pressKeystroke (VK_CONTROL , VK_SHIFT , VK_F8 );
193211 }
212+ } else if (c .startsWith ("debug" )){
213+ pressKeystroke (VK_SHIFT , VK_F9 );
194214 } else if (c .startsWith ("step" )) {
195215 if (c .endsWith ("over" )) {
196- pressKeystroke (KeyEvent . VK_F8 );
216+ pressKeystroke (VK_F8 );
197217 } else if (c .endsWith ("into" )) {
198- pressKeystroke (KeyEvent .VK_F7 );
218+ pressKeystroke (VK_F7 );
219+ } else if (c .endsWith ("return" )) {
220+ pressKeystroke (VK_SHIFT , VK_F8 );
199221 }
222+ } else if (c .startsWith ("resume" )) {
223+ pressKeystroke (VK_F9 );
200224 } else if (c .startsWith ("tell me a joke" )) {
201225 tellJoke ();
202226 } else if (c .contains ("check" )) {
@@ -338,7 +362,7 @@ public static synchronized void beep() {
338362 try {
339363 Clip clip = AudioSystem .getClip ();
340364 AudioInputStream inputStream = AudioSystem .getAudioInputStream (
341- ASRServiceImpl .class .getResourceAsStream ("/com.jetbrains.idear/sounds/beep.wav" ));
365+ ASRService .class .getResourceAsStream ("/com.jetbrains.idear/sounds/beep.wav" ));
342366 clip .open (inputStream );
343367 clip .start ();
344368 } catch (Exception e ) {
0 commit comments