public static void setCommands(MenuType type, String data) { List<CommandMenuItem> parsed = parse(data); commands.put(type, parsed); }
public static List<CommandMenuItem> parse(String input) { List<CommandMenuItem> result = new LinkedList<>(); if (input == null || input.isEmpty()) { return result; } String[] lines = input.split("\n"); String submenuName = null; for (String line : lines) { CommandMenuItem submenu; CommandMenuItem separator; CommandMenuItem item; if ((submenu = parseSubmenu(line)) != null) { submenuName = submenu.getLabel(); result.add(submenu); } else if ((separator = parseSeparator(line, submenuName)) != null) { result.add(separator); } else if ((item = parseCommand(line, submenuName)) != null) { result.add(item); } else { result.addAll(addCustomCommands(line, submenuName)); } } return result; }
String number = matcher.group(2); String factor = matcher.group(3); item = createTimeoutItem(number, factor, submenu, pos, key); } else { String command = matcher.group(4); item = createItem(command, submenu, pos, key); result.add(makeItem(null, null, submenu, -1, null)); sep = false;
private static CommandMenuItem createTimeoutItem(String number, String factor, String subMenu, int pos, String key) { int time = Integer.parseInt(number); String label; if (!factor.isEmpty()) { time *= getFactor(factor); label = number + factor; } else { label = timeFormat(time); } String command = "/timeout $1 "+time+" $2-"; return makeItem(label, command, subMenu, pos, key); }
public ChannelContextMenu(ContextMenuListener listener) { this.listener = listener; addItem("channelInfo", Language.getString("menubar.dialog.channelInfo")); addItem("channelAdmin", Language.getString("menubar.dialog.channelAdmin")); addSeparator(); ContextMenuHelper.addStreamsOptions(this, 1, false); addSeparator(); addItem("hostchannel", Language.getString("channelCm.hostChannel"), MISC_MENU); addSeparator(MISC_MENU); addItem("joinHostedChannel", Language.getString("channelCm.joinHosted"), MISC_MENU); addItem("copy", Language.getString("channelCm.copyStreamname"), MISC_MENU); addSeparator(MISC_MENU); addItem("chatRules", Language.getString("channelCm.dialog.chatRules"), MISC_MENU); addSeparator(MISC_MENU); addItem("follow", Language.getString("channelCm.follow"), MISC_MENU); addItem("unfollow", Language.getString("channelCm.unfollow"), MISC_MENU); addSeparator(MISC_MENU); addItem("srcOpen", Language.getString("channelCm.speedruncom"), MISC_MENU); addSeparator(); addItem("closeChannel", Language.getString("channelCm.closeChannel")); CommandMenuItems.addCommands(CommandMenuItems.MenuType.CHANNEL, this); }
private static CommandMenuItem createItem(String command, String subMenu, int pos, String key) { String label = Helper.replaceUnderscoreWithSpace(command); return makeItem(label, "/"+command+" $1-", subMenu, pos, key); }
m.addItem("unfollow", Language.getString("channelCm.unfollow"), miscSubmenu); CommandMenuItems.addCommands(CommandMenuItems.MenuType.STREAMS, m);
private static CommandMenuItem parseCommand(String line, String currentSubmenu) { Matcher m = PATTERN.matcher(line); if (!m.matches()) { return null; } String label = m.group(1).trim(); int pos = m.group(2) == null ? -1 : Integer.parseInt(m.group(2)); String key = m.group(3); String command = m.group(4).trim(); //System.out.println("'"+label+"' '"+key+"' '"+command+"'"); if (!label.startsWith(".")) { currentSubmenu = null; } else { label = label.substring(1).trim(); } return makeItem(label, command, currentSubmenu, pos, key); }
public static void main(String[] args) { List<CommandMenuItem> items = parse("/slap\n" + "[Joshimuz]\n" + " FAQ=FAQ: http://blahblah\n" + "Message=/openUrl http://twitch.tv/inbox/compose?target=$$1"); for (CommandMenuItem item : items) { System.out.println(item); } System.out.println(true || false && false); }
CommandMenuItems.addCommands(CommandMenuItems.MenuType.USER, this);
@Override public String test(Window parent, Component component, int x, int y, String value) { StringBuilder errors = new StringBuilder(); List<CommandMenuItem> items = CommandMenuItems.parse(value); for (CommandMenuItem item : items) { if (item.getCommand() != null && item.getCommand().hasError()) { errors.append("<p style='font-family:monospaced;'>"); errors.append("Error in command '").append(item.getLabel()).append("': "); errors.append(formatCommandInfo(item.getCommand().getError())); errors.append("</p>"); } } String output = "No errors found."; if (errors.length() > 0) { output = errors.toString(); } GuiUtil.showNonModalMessage(parent, "Custom Commands", output, JOptionPane.INFORMATION_MESSAGE, true); return null; } };
noKeyLabels = true; List<CommandMenuItem> items = CommandMenuItems.parse(setting); for (CommandMenuItem item : items) { if (item.getCommand() == null) {
@Test public void testParse() { assertEquals(CommandMenuItems.parse(null), new ArrayList<>()); assertEquals(CommandMenuItems.parse(""), new ArrayList<>()); expected1.add(new CommandMenuItem("Uptime", CustomCommand.parse("Stream Uptime: $(streamuptime)"), null, -1, null)); assertEquals(CommandMenuItems.parse(input1), expected1);
addItem("", "(I hope you enjoy my abusing of a popup menu as an info list.)", readme); int errorCount = 0; List<CommandMenuItem> items = CommandMenuItems.parse(value); for (CommandMenuItem item : items) { if (item.getCommand() != null && item.getCommand().getError() != null) {