use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class UndoRedoAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
UndoManager undoManager = getUndoManager(editor, dataContext);
perform(editor, undoManager);
}
use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class XmlTagInsertHandler method insertIncompleteTag.
public static void insertIncompleteTag(char completionChar, final Editor editor, XmlTag tag) {
XmlElementDescriptor descriptor = tag.getDescriptor();
final Project project = editor.getProject();
TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "");
template.setToIndent(true);
// temp code
PsiFile containingFile = tag.getContainingFile();
boolean htmlCode = HtmlUtil.hasHtml(containingFile) || HtmlUtil.supportsXmlTypedHandlers(containingFile);
template.setToReformat(!htmlCode);
StringBuilder indirectRequiredAttrs = addRequiredAttributes(descriptor, tag, template, containingFile);
final boolean chooseAttributeName = addTail(completionChar, descriptor, htmlCode, tag, template, indirectRequiredAttrs);
templateManager.startTemplate(editor, template, new TemplateEditingAdapter() {
private RangeMarker myAttrValueMarker;
@Override
public void waitingForInput(Template template) {
int offset = editor.getCaretModel().getOffset();
myAttrValueMarker = editor.getDocument().createRangeMarker(offset + 1, offset + 4);
}
@Override
public void templateFinished(final Template template, boolean brokenOff) {
final int offset = editor.getCaretModel().getOffset();
if (chooseAttributeName && offset > 0) {
char c = editor.getDocument().getCharsSequence().charAt(offset - 1);
if (c == '/' || (c == ' ' && brokenOff)) {
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
editor.getDocument().replaceString(offset, offset + 3, ">");
}
}.execute();
}
}
}
@Override
public void templateCancelled(final Template template) {
if (myAttrValueMarker == null) {
return;
}
final UndoManager manager = UndoManager.getInstance(project);
if (manager.isUndoInProgress() || manager.isRedoInProgress()) {
return;
}
if (chooseAttributeName && myAttrValueMarker.isValid()) {
final int startOffset = myAttrValueMarker.getStartOffset();
final int endOffset = myAttrValueMarker.getEndOffset();
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
editor.getDocument().replaceString(startOffset, endOffset, ">");
}
}.execute();
}
}
});
}
Aggregations