MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / installHotkey

Method installHotkey

ij/src/main/java/ij/plugin/Hotkeys.java:31–86  ·  view source on GitHub ↗
(String arg)

Source from the content-addressed store, hash-verified

29 }
30
31 void installHotkey(String arg) {
32 boolean byName = arg.equals("install2");
33 String[] commands = byName?null:getAllCommands();
34 String[] shortcuts = getAvailableShortcuts();
35 String nCommands = commands!=null?" ("+commands.length+")":"";
36 GenericDialog gd = new GenericDialog("Add Shortcut"+nCommands);
37 gd.addChoice("Shortcut:", shortcuts, shortcuts[0]);
38 if (byName)
39 gd.addStringField("Command:", "", 20);
40 else
41 gd.addChoice("Command:", commands, command);
42 gd.showDialog();
43 if (gd.wasCanceled())
44 return;
45 shortcut = gd.getNextChoice();
46 if (byName) {
47 command = gd.getNextString();
48 Hashtable cmds = Menus.getCommands();
49 if (cmds==null || cmds.get(command)==null) {
50 String command2 = command;
51 if (cmds.get(command)==null)
52 command = command+" ";
53 if (cmds.get(command)==null) {
54 command = command2 + "...";
55 if (cmds.get(command)==null) {
56 command = command2;
57 IJ.error("Command not found:\n \n "+ "\""+command+"\"");
58 return;
59 }
60 }
61 }
62 } else {
63 command = gd.getNextChoice();
64 Hashtable cmds = Menus.getCommands();
65 if (command.contains("[") && cmds!=null && cmds.get(command)==null) {
66 if (cmds.get(command+"]")!=null)
67 command += "]";
68 }
69 }
70 String plugin = "ij.plugin.Hotkeys("+"\""+command+"\")";
71 int err = Menus.installPlugin(plugin,Menus.SHORTCUTS_MENU,"*"+command,shortcut,IJ.getInstance());
72 switch (err) {
73 case Menus.COMMAND_IN_USE:
74 IJ.showMessage(TITLE, "The command \"" + command + "\" is already installed.");
75 break;
76 case Menus.INVALID_SHORTCUT:
77 IJ.showMessage(TITLE, "The shortcut must be a single character or F1-F24.");
78 break;
79 case Menus.SHORTCUT_IN_USE:
80 IJ.showMessage("The \""+shortcut+"\" shortcut is in use.");
81 break;
82 default:
83 shortcut = "";
84 break;
85 }
86 }
87
88 void removeHotkey() {

Callers 1

runMethod · 0.95

Calls 15

getAllCommandsMethod · 0.95
getAvailableShortcutsMethod · 0.95
addChoiceMethod · 0.95
addStringFieldMethod · 0.95
showDialogMethod · 0.95
wasCanceledMethod · 0.95
getNextChoiceMethod · 0.95
getNextStringMethod · 0.95
getCommandsMethod · 0.95
errorMethod · 0.95
installPluginMethod · 0.95
getInstanceMethod · 0.95

Tested by

no test coverage detected