PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/BeanShellAction.java

#
Java | 98 lines | 61 code | 14 blank | 23 comment | 7 complexity | 827f13a2339f523b82ac32163a067265 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. * BeanShellAction.java - BeanShell action
  3. * Copyright (C) 2000, 2001 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import java.awt.event.ActionEvent;
  21. import java.awt.*;
  22. public class BeanShellAction extends EditAction
  23. {
  24. public BeanShellAction(String name, String code, String isSelected,
  25. boolean noRepeat, boolean noRecord)
  26. {
  27. super(name);
  28. this.code = code;
  29. this.isSelected = isSelected;
  30. this.noRepeat = noRepeat;
  31. this.noRecord = noRecord;
  32. /* Some characters that we like to use in action names
  33. * ('.', '-') are not allowed in BeanShell identifiers. */
  34. sanitizedName = name.replace('.','_').replace('-','_');
  35. // evaluate isSelected now so that menus don't take a long
  36. // time to first come up
  37. if(isSelected != null)
  38. {
  39. String cachedIsSelectedName = "selected_" + sanitizedName;
  40. cachedIsSelected = BeanShell.cacheBlock(cachedIsSelectedName,
  41. isSelected,true);
  42. }
  43. }
  44. public void invoke(View view)
  45. {
  46. if(cachedCode == null)
  47. {
  48. String cachedCodeName = "action_" + sanitizedName;
  49. cachedCode = BeanShell.cacheBlock(cachedCodeName,code,true);
  50. }
  51. BeanShell.runCachedBlock(cachedCode,view,null);
  52. }
  53. public boolean isToggle()
  54. {
  55. return isSelected != null;
  56. }
  57. public boolean isSelected(View view)
  58. {
  59. if(isSelected == null)
  60. return false;
  61. return Boolean.TRUE.equals(BeanShell.runCachedBlock(cachedIsSelected,
  62. view,null));
  63. }
  64. public boolean noRepeat()
  65. {
  66. return noRepeat;
  67. }
  68. public boolean noRecord()
  69. {
  70. return noRecord;
  71. }
  72. public String getCode()
  73. {
  74. return code.trim();
  75. }
  76. // private members
  77. private boolean noRepeat;
  78. private boolean noRecord;
  79. private String code;
  80. private String isSelected;
  81. private String cachedCode;
  82. private String cachedIsSelected;
  83. private String sanitizedName;
  84. }