You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Input.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  3. * Simon Mott
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.commandparser.commands.global;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.WritableFrameContainer;
  26. import com.dmdirc.commandparser.CommandArguments;
  27. import com.dmdirc.commandparser.CommandManager;
  28. import com.dmdirc.commandparser.commands.GlobalCommand;
  29. import com.dmdirc.commandparser.commands.IntelligentCommand;
  30. import com.dmdirc.ui.input.AdditionalTabTargets;
  31. /**
  32. * The input command allows you to maniplulate text in a windows inputField.
  33. *
  34. * @author Simon
  35. * @since 0.6.4
  36. */
  37. public class Input extends GlobalCommand implements IntelligentCommand {
  38. /**
  39. * Creates a new instance of Input.
  40. */
  41. public Input() {
  42. super();
  43. CommandManager.registerCommand(this);
  44. }
  45. /** {@inheritDoc} */
  46. @Override
  47. public void execute(final FrameContainer<?> origin, final boolean isSilent,
  48. final CommandArguments args) {
  49. if (args.getArguments().length == 0) {
  50. showUsage(origin, isSilent, "input",
  51. "[--clear] <text to insert into inputfield");
  52. return;
  53. } else if (args.getArguments().length == 1
  54. && "--clear".equals(args.getArgumentsAsString(0))) {
  55. ((WritableFrameContainer<?>) origin).getFrame()
  56. .getInputHandler().clearInputField();
  57. } else {
  58. ((WritableFrameContainer<?>) origin).getFrame()
  59. .getInputHandler().addToInputField(args.getArgumentsAsString());
  60. }
  61. }
  62. /** {@inheritDoc} */
  63. @Override
  64. public String getName() {
  65. return "input";
  66. }
  67. /** {@inheritDoc} */
  68. @Override
  69. public boolean showInHelp() {
  70. return true;
  71. }
  72. /** {@inheritDoc} */
  73. @Override
  74. public String getHelp() {
  75. return "input [--clear] <text to insert into inputfield> - Adds text to" +
  76. " the active window's input field";
  77. }
  78. /** {@inheritDoc} */
  79. @Override
  80. public AdditionalTabTargets getSuggestions(final int arg,
  81. final IntelligentCommandContext context) {
  82. final AdditionalTabTargets res = new AdditionalTabTargets();
  83. if (arg == 0) {
  84. res.add("--clear");
  85. }
  86. return res;
  87. }
  88. }