Example usage for com.intellij.openapi.command.undo BasicUndoableAction BasicUndoableAction

List of usage examples for com.intellij.openapi.command.undo BasicUndoableAction BasicUndoableAction

Introduction

In this page you can find the example usage for com.intellij.openapi.command.undo BasicUndoableAction BasicUndoableAction.

Prototype

public BasicUndoableAction(VirtualFile @NotNull... files) 

Source Link

Usage

From source file:com.intellij.codeInsight.template.impl.TemplateState.java

License:Apache License

public void start(@NotNull TemplateImpl template, @Nullable final PairProcessor<String, String> processor,
        @Nullable Map<String, String> predefinedVarValues) {
    LOG.assertTrue(!myStarted, "Already started");
    myStarted = true;//w  ww.  j  a  v  a2 s  . com
    myTemplate = template;
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    myProcessor = processor;

    DocumentReference[] refs = myDocument == null ? null
            : new DocumentReference[] { DocumentReferenceManager.getInstance().create(myDocument) };
    UndoManager.getInstance(myProject).undoableActionPerformed(new BasicUndoableAction(refs) {
        @Override
        public void undo() {
            if (myDocument != null) {
                fireTemplateCancelled();
                LookupManager.getInstance(myProject).hideActiveLookup();
                int oldVar = myCurrentVariableNumber;
                setCurrentVariableNumber(-1);
                currentVariableChanged(oldVar);
            }
        }

        @Override
        public void redo() {
            //TODO:
            // throw new UnexpectedUndoException("Not implemented");
        }
    });
    myTemplateIndented = false;
    myCurrentVariableNumber = -1;
    mySegments = new TemplateSegments(myEditor);
    myPrevTemplate = myTemplate;

    //myArgument = argument;
    myPredefinedVariableValues = predefinedVarValues;

    if (template.isInline()) {
        int caretOffset = myEditor.getCaretModel().getOffset();
        myTemplateRange = myDocument.createRangeMarker(caretOffset,
                caretOffset + template.getTemplateText().length());
    } else {
        PsiFile file = getPsiFile();
        preprocessTemplate(file, myEditor.getCaretModel().getOffset(), myTemplate.getTemplateText());
        int caretOffset = myEditor.getCaretModel().getOffset();
        myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset);
    }
    myTemplateRange.setGreedyToLeft(true);
    myTemplateRange.setGreedyToRight(true);

    processAllExpressions(template);
}