1 21 22 package org.armedbear.j; 23 24 import java.util.List ; 25 26 public final class ExecuteCommandDialog extends InputDialog 27 { 28 private ExecuteCommandDialog(Editor editor, String title, String historyKey) 29 { 30 super(editor, "Command:", title, null); 31 History history = new History(historyKey); 32 setHistory(history); 33 setDefaultValue(history.getPrevious()); 34 } 35 36 protected final List getCompletions(String prefix) 37 { 38 return CommandTable.getCompletionsForPrefix(prefix); 39 } 40 41 public static void whereIs() 42 { 43 final Editor editor = Editor.currentEditor(); 44 ExecuteCommandDialog d = new ExecuteCommandDialog(editor, "Where is...", "whereIs.input"); 45 editor.centerDialog(d); 46 d.show(); 47 editor.repaintNow(); 48 String input = d.getInput(); 49 if (input == null) 50 return; 51 input = input.trim(); 52 if (input.length() == 0) 53 return; 54 whereIs(input); 55 } 56 57 public static void whereIs(String s) 58 { 59 final Editor editor = Editor.currentEditor(); 60 final Buffer buffer = editor.getBuffer(); 61 editor.setWaitCursor(); 62 Command command = CommandTable.getCommand(s); 64 final String commandName = command != null ? command.getName() : s; 65 List list = KeyMap.getGlobalKeyMap().listKeys(commandName); 66 list.addAll(buffer.getKeyMapForMode().listKeys(commandName)); 67 FastStringBuffer sb = new FastStringBuffer(commandName); 68 if (list.size() == 0) { 69 sb.append(" is not mapped"); 70 } else if (list.size() == 1) { 71 sb.append(" is mapped to "); 72 sb.append((String )list.get(0)); 73 } else { 74 sb.append(" is mapped to:"); 75 sb.append(System.getProperty("line.separator")); 76 for (int i = 0; i < list.size(); i++) { 77 sb.append(System.getProperty("line.separator")); 78 sb.append(" "); 79 sb.append((String ) list.get(i)); 80 } 81 } 82 editor.setDefaultCursor(); 83 MessageDialog.showMessageDialog(editor, sb.toString(), "Where is..."); 84 } 85 } 86 | Popular Tags |