PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XInsert/src/ShowDialogCommand.java

#
Java | 94 lines | 46 code | 12 blank | 36 comment | 14 complexity | 8b3ba7a82f8affdfa15486edff363e88 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. *
  3. * ShowDialogCommand.java
  4. * Copyright (C) 2001 Dominic Stolerman
  5. * dstolerman@jedit.org
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or 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. import org.gjt.sp.jedit.View;
  22. /**
  23. *
  24. * @author Dominic Stolerman
  25. */
  26. public class ShowDialogCommand extends Object implements Command {
  27. /** Creates a new ShowDialogCommand */
  28. public ShowDialogCommand(String command) {
  29. this.command = command;
  30. }
  31. public void run(ScriptContext sc) {
  32. View parent = sc.getView();
  33. XTreeNode node = sc.getNode();
  34. String _command = command;
  35. // System.out.println("_command=" + _command);
  36. boolean giveOpt = (_command.charAt(_command.length() -1) == '?');
  37. String key = _command.substring(1, XScripter.findWordEnd(_command, 2, null));
  38. // System.out.println("key=" + key);
  39. _command = _command.substring(key.length() + 1, giveOpt ? _command.length() - 1 : _command.length()).trim();
  40. // System.out.println("_command=" + _command);
  41. if(_command.startsWith("%set")) {
  42. _command = _command.substring(4).trim();
  43. if(_command.startsWith("$"))
  44. node.addVariable(key, XScripter.getSubstituteFor(parent,_command, node));
  45. else {
  46. _command = Utilities.replace(_command, "\\$", "$");
  47. node.addVariable(key, _command);
  48. }
  49. return;
  50. }
  51. String[] opts = Utilities.findStrings(_command);
  52. String message;
  53. String[] _opts;
  54. if(opts != null && opts.length > 0) {
  55. message = opts[0];
  56. _opts = new String[opts.length - 1];
  57. System.arraycopy(opts, 1, _opts, 0, _opts.length);
  58. opts = null;
  59. }
  60. else {
  61. message = "Please enter a value for " + key + ":";
  62. _opts = new String[0];
  63. }
  64. if(_opts.length == 0)
  65. node.addVariable(key, XScripter.showInputDialog(parent, message, key, XScripter.getSubstituteFor(parent, key, node)));
  66. else if(_opts.length == 1)
  67. node.addVariable(key, XScripter.showInputDialog(parent, message, key, _opts[0]));
  68. else {
  69. String val = XScripter.showComboDialog(parent, message, key, _opts, XScripter.getSubstituteFor(parent, key, node), giveOpt);
  70. // System.out.println("key=" + key + " value=" + val);
  71. node.addVariable(key, val);
  72. }
  73. }
  74. private final String command;
  75. }