選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AllChannels.java 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.commands.server;
  23. import com.dmdirc.commandparser.BaseCommandInfo;
  24. import com.dmdirc.commandparser.CommandArguments;
  25. import com.dmdirc.commandparser.CommandInfo;
  26. import com.dmdirc.commandparser.CommandType;
  27. import com.dmdirc.commandparser.commands.Command;
  28. import com.dmdirc.commandparser.commands.IntelligentCommand;
  29. import com.dmdirc.commandparser.commands.context.CommandContext;
  30. import com.dmdirc.commandparser.commands.context.ServerCommandContext;
  31. import com.dmdirc.interfaces.CommandController;
  32. import com.dmdirc.interfaces.Connection;
  33. import com.dmdirc.interfaces.GroupChat;
  34. import com.dmdirc.interfaces.InputModel;
  35. import com.dmdirc.interfaces.WindowModel;
  36. import com.dmdirc.ui.input.AdditionalTabTargets;
  37. import com.dmdirc.ui.input.TabCompleterUtils;
  38. import javax.annotation.Nonnull;
  39. import javax.inject.Inject;
  40. /**
  41. * The AllChannels command allows the user to issue a command to all channels on a server.
  42. */
  43. public class AllChannels extends Command implements IntelligentCommand {
  44. /** A command info object for this command. */
  45. public static final CommandInfo INFO = new BaseCommandInfo("allchannels",
  46. "allchannels <command> - executes the command as though it had"
  47. + " been entered on all channels", CommandType.TYPE_SERVER);
  48. /** Tab-completer utilities. */
  49. private final TabCompleterUtils tabCompleterUtils;
  50. /**
  51. * Creates a new instance of this command.
  52. *
  53. * @param controller The controller to use for command information.
  54. */
  55. @Inject
  56. public AllChannels(final CommandController controller,
  57. final TabCompleterUtils tabCompleterUtils) {
  58. super(controller);
  59. this.tabCompleterUtils = tabCompleterUtils;
  60. }
  61. @Override
  62. public void execute(@Nonnull final WindowModel origin,
  63. final CommandArguments args, final CommandContext context) {
  64. final Connection server = ((ServerCommandContext) context).getConnection();
  65. final String command = args.getArgumentsAsString();
  66. for (GroupChat channel : server.getGroupChatManager().getChannels()) {
  67. channel.getWindowModel().getInputModel().map(InputModel::getCommandParser)
  68. .ifPresent(cp -> cp.parseCommand(channel.getWindowModel(), command));
  69. }
  70. }
  71. @Override
  72. public AdditionalTabTargets getSuggestions(final int arg,
  73. final IntelligentCommandContext context) {
  74. return tabCompleterUtils.getIntelligentResults(arg, context, 0);
  75. }
  76. }