protected static void doWrap( final String selection, final String abbreviation, final CustomTemplateCallback callback) { final ZenCodingGenerator defaultGenerator = findApplicableDefaultGenerator(callback.getContext(), true); assert defaultGenerator != null; ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { CommandProcessor.getInstance() .executeCommand( callback.getProject(), new Runnable() { public void run() { callback.fixInitialState(true); ZenCodingNode node = parse(abbreviation, callback, defaultGenerator); assert node != null; PsiElement context = callback.getContext(); ZenCodingGenerator generator = findApplicableGenerator(node, context, true); List<ZenCodingFilter> filters = getFilters(node, context); EditorModificationUtil.deleteSelectedText(callback.getEditor()); PsiDocumentManager.getInstance(callback.getProject()) .commitAllDocuments(); expand(node, generator, filters, selection, callback); } }, CodeInsightBundle.message("insert.code.template.command"), null); } }); }
public boolean isApplicable(PsiFile file, int offset, boolean wrapping) { WebEditorOptions webEditorOptions = WebEditorOptions.getInstance(); if (!webEditorOptions.isZenCodingEnabled()) { return false; } if (file == null) { return false; } PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments(); PsiElement element = CustomTemplateCallback.getContext(file, offset); return findApplicableDefaultGenerator(element, wrapping) != null; }
private static void expand( String key, @NotNull CustomTemplateCallback callback, String surroundedText, @NotNull ZenCodingGenerator defaultGenerator) { ZenCodingNode node = parse(key, callback, defaultGenerator); assert node != null; if (surroundedText == null) { if (node instanceof TemplateNode) { if (key.equals(((TemplateNode) node).getTemplateToken().getKey()) && callback.findApplicableTemplates(key).size() > 1) { callback.startTemplate(); return; } } callback.deleteTemplateKey(key); } PsiElement context = callback.getContext(); ZenCodingGenerator generator = findApplicableGenerator(node, context, false); List<ZenCodingFilter> filters = getFilters(node, context); expand(node, generator, filters, surroundedText, callback); }
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) { ZenCodingGenerator generator = findApplicableDefaultGenerator(callback.getContext(), false); if (generator == null) return null; return generator.computeTemplateKey(callback); }
public static boolean checkTemplateKey(String inputString, CustomTemplateCallback callback) { ZenCodingGenerator generator = findApplicableDefaultGenerator(callback.getContext(), true); assert generator != null; return checkTemplateKey(inputString, callback, generator); }
public void expand(String key, @NotNull CustomTemplateCallback callback) { ZenCodingGenerator defaultGenerator = findApplicableDefaultGenerator(callback.getContext(), false); assert defaultGenerator != null; expand(key, callback, null, defaultGenerator); }