restore I surround template: create a copy with rulezz for surround templates, start them in a write action

This commit is contained in:
peter
2011-09-06 19:18:09 +02:00
parent bff5d16471
commit 4ddf6456d8
4 changed files with 12 additions and 22 deletions
@@ -66,7 +66,7 @@ public class SurroundWithHandler implements CodeInsightActionHandler{
}
public boolean startInWriteAction() {
return false;
return true;
}
public static void invoke(final Project project, final Editor editor, PsiFile file, Surrounder surrounder){
@@ -103,28 +103,23 @@ public class SurroundWithTemplateHandler implements CodeInsightActionHandler {
}
public static ArrayList<TemplateImpl> getApplicableTemplates(Editor editor, PsiFile file, boolean selection) {
int offset = editor.getCaretModel().getOffset();
int startOffset = offset;
if (selection && editor.getSelectionModel().hasSelection()) {
final int selStart = editor.getSelectionModel().getSelectionStart();
final int selEnd = editor.getSelectionModel().getSelectionEnd();
startOffset = (offset == selStart) ? selEnd : selStart;
}
file = (PsiFile)file.copy();
final Document document = file.getViewProvider().getDocument();
assert document != null;
if (!selection) {
file = (PsiFile)file.copy();
final Document document = file.getViewProvider().getDocument();
assert document != null;
document.insertString(offset, CompletionUtil.DUMMY_IDENTIFIER_TRIMMED);
PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
int startOffset = editor.getCaretModel().getOffset();
if (selection && editor.getSelectionModel().hasSelection()) {
startOffset = editor.getSelectionModel().getSelectionStart();
document.deleteString(startOffset, editor.getSelectionModel().getSelectionEnd());
}
document.insertString(startOffset, CompletionUtil.DUMMY_IDENTIFIER_TRIMMED);
PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
ArrayList<TemplateImpl> list = new ArrayList<TemplateImpl>();
for (TemplateImpl template : TemplateSettings.getInstance().getTemplates()) {
if (!template.isDeactivated() &&
template.isSelectionTemplate() == selection &&
(TemplateManagerImpl.isApplicable(file, offset, template) ||
(selection && TemplateManagerImpl.isApplicable(file, startOffset, template)))) {
TemplateManagerImpl.isApplicable(file, startOffset, template)) {
list.add(template);
}
}
@@ -486,7 +486,6 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
}
public static boolean isApplicable(PsiFile file, int offset, TemplateImpl template) {
TemplateManager instance = getInstance(file.getProject());
TemplateContext context = template.getTemplateContext();
if (isEnabled(file, offset, null, context)) {
return true;
-4
View File
@@ -39,7 +39,6 @@
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="ASPECTJ" value="true" />
</context>
</template>
<template name="RL" resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.surround.with.read.lock"
@@ -49,7 +48,6 @@
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="ASPECTJ" value="true" />
</context>
</template>
<template name="WL" resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.surround.with.write.lock"
@@ -59,7 +57,6 @@
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="ASPECTJ" value="true" />
</context>
</template>
<template name="I" value="for ($ELEMENT_TYPE$ $VAR$ : $SELECTION$) {&#10; $END$&#10;}&#10;"
@@ -70,7 +67,6 @@
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="ASPECTJ" value="true" />
</context>
</template>
</templateSet>