01: /*
02: * ExecuteCommandDialog.java
03: *
04: * Copyright (C) 1998-2002 Peter Graves
05: * $Id: ExecuteCommandDialog.java,v 1.1.1.1 2002/09/24 16:08:26 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import java.util.List;
25:
26: public final class ExecuteCommandDialog extends InputDialog {
27: private ExecuteCommandDialog(Editor editor, String title,
28: String historyKey) {
29: super (editor, "Command:", title, null);
30: History history = new History(historyKey);
31: setHistory(history);
32: setDefaultValue(history.getPrevious());
33: }
34:
35: protected final List getCompletions(String prefix) {
36: return CommandTable.getCompletionsForPrefix(prefix);
37: }
38:
39: public static void whereIs() {
40: final Editor editor = Editor.currentEditor();
41: ExecuteCommandDialog d = new ExecuteCommandDialog(editor,
42: "Where is...", "whereIs.input");
43: editor.centerDialog(d);
44: d.show();
45: editor.repaintNow();
46: String input = d.getInput();
47: if (input == null)
48: return;
49: input = input.trim();
50: if (input.length() == 0)
51: return;
52: whereIs(input);
53: }
54:
55: public static void whereIs(String s) {
56: final Editor editor = Editor.currentEditor();
57: final Buffer buffer = editor.getBuffer();
58: editor.setWaitCursor();
59: // If it's a known command, use its canonical name.
60: Command command = CommandTable.getCommand(s);
61: final String commandName = command != null ? command.getName()
62: : s;
63: List list = KeyMap.getGlobalKeyMap().listKeys(commandName);
64: list.addAll(buffer.getKeyMapForMode().listKeys(commandName));
65: FastStringBuffer sb = new FastStringBuffer(commandName);
66: if (list.size() == 0) {
67: sb.append(" is not mapped");
68: } else if (list.size() == 1) {
69: sb.append(" is mapped to ");
70: sb.append((String) list.get(0));
71: } else {
72: sb.append(" is mapped to:");
73: sb.append(System.getProperty("line.separator"));
74: for (int i = 0; i < list.size(); i++) {
75: sb.append(System.getProperty("line.separator"));
76: sb.append(" ");
77: sb.append((String) list.get(i));
78: }
79: }
80: editor.setDefaultCursor();
81: MessageDialog.showMessageDialog(editor, sb.toString(),
82: "Where is...");
83: }
84: }
|