// {{{ literalBeanShellReplace() method private static String literalBeanShellReplace(View view, JEditBuffer buffer, CharSequence found) throws Exception { replaceNS.setVariable("buffer", buffer); replaceNS.setVariable("_0", found); Object obj = BeanShell.runCachedBlock(replaceMethod, view, replaceNS); replaceNS.setVariable("_0", null, false); // Not really necessary because it is already cleared in the end of // BeanShell.runCachedBlock() replaceNS.setVariable("buffer", null, false); if (obj == null) return ""; else return obj.toString(); } // }}}
// {{{ regexpBeanShellReplace() method private static String regexpBeanShellReplace( View view, JEditBuffer buffer, SearchMatcher.Match occur) throws Exception { replaceNS.setVariable("buffer", buffer, false); for (int i = 0; i < occur.substitutions.length; i++) { replaceNS.setVariable("_" + i, occur.substitutions[i]); } Object obj = BeanShell.runCachedBlock(replaceMethod, view, replaceNS); for (int i = 0; i < occur.substitutions.length; i++) { replaceNS.setVariable("_" + i, null, false); } // Not really necessary because it is already cleared in the end of // BeanShell.runCachedBlock() replaceNS.setVariable("buffer", null, false); if (obj == null) return ""; else return obj.toString(); } // }}}
// {{{ isSelected() method public boolean isSelected(Component comp) { if (isSelected == null) return false; NameSpace global = BeanShell.getNameSpace(); try { View view = GUIUtilities.getView(comp); // undocumented hack to allow browser actions to work. // XXX - clean up in 4.3 global.setVariable("_comp", comp); return Boolean.TRUE.equals( BeanShell.runCachedBlock( isSelected.get(), view, new NameSpace(BeanShell.getNameSpace(), "BeanShellAction.isSelected()"))); } catch (Throwable e) { Log.log(Log.ERROR, this, e); // dialogs f**k things up if a menu is visible, etc! // new BeanShellErrorDialog(view,e); // so that in the future we don't see streams of // exceptions isSelected = null; return false; } finally { try { global.setVariable("_comp", null); } catch (UtilEvalError err) { Log.log(Log.ERROR, this, err); } } } // }}}