PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 65 lines | 32 code | 8 blank | 25 comment | 12 complexity | ba94abb710f456fd8a64f79a6cadc2fc 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. * SubVariableCommand.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.*;
  22. /**
  23. *
  24. * @author Dominic Stolerman
  25. */
  26. public class SubVariableCommand extends Object implements Command {
  27. /** Creates new SubVariableCommand */
  28. public SubVariableCommand(String variable) {
  29. this.variable = variable;
  30. }
  31. public void run(ScriptContext context) {
  32. View parent = context.getView();
  33. XTreeNode node = context.getNode();
  34. String key = variable.substring(2, XScripter.findWordEnd(variable, 3, null));
  35. String value;
  36. boolean isTempValue = true;
  37. if(variable.charAt(0) == '=') {
  38. value = XScripter.getSubstituteFor(parent, key, node);
  39. if (value == null)
  40. value = "";
  41. }
  42. else if(variable.charAt(0) == '?') {
  43. value = XScripter.getSubstituteFor(parent, key, (XTreeNode)node.getParent());
  44. if(value == null) {
  45. value = XScripter.showInputDialog(parent, key, node.getVariable(key));
  46. node.addVariable(key, value);
  47. }
  48. }
  49. else {
  50. value = XScripter.getSubstituteFor(parent, key, node);
  51. if(value == null)
  52. value = key;
  53. }
  54. InsertTextCommand.insertText(value, context);
  55. }
  56. private final String variable;
  57. }