use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class ChangeSignatureProcessorBase method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
RefactoringTransaction transaction = getTransaction();
final ChangeInfo changeInfo = myChangeInfo;
final RefactoringElementListener elementListener = transaction == null ? null : transaction.getElementListener(changeInfo.getMethod());
final String fqn = CopyReferenceAction.elementToFqn(changeInfo.getMethod());
if (fqn != null) {
UndoableAction action = new BasicUndoableAction() {
@Override
public void undo() {
if (elementListener instanceof UndoRefactoringElementListener) {
((UndoRefactoringElementListener) elementListener).undoElementMovedOrRenamed(changeInfo.getMethod(), fqn);
}
}
@Override
public void redo() {
}
};
UndoManager.getInstance(myProject).undoableActionPerformed(action);
}
try {
doChangeSignature(changeInfo, usages);
final PsiElement method = changeInfo.getMethod();
LOG.assertTrue(method.isValid());
if (elementListener != null && changeInfo.isNameChanged()) {
elementListener.elementRenamed(method);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class CommandMerger method flushCurrentCommand.
void flushCurrentCommand() {
if (hasActions()) {
if (!myAdditionalAffectedDocuments.isEmpty()) {
DocumentReference[] refs = myAdditionalAffectedDocuments.toArray(new DocumentReference[myAdditionalAffectedDocuments.size()]);
myCurrentActions.add(new BasicUndoableAction(refs) {
@Override
public void undo() {
}
@Override
public void redo() {
}
});
}
myManager.getUndoStacksHolder().addToStacks(new UndoableGroup(myCommandName, isGlobal(), myManager, myStateBefore, myStateAfter, myCurrentActions, myUndoConfirmationPolicy, isTransparent(), myValid));
}
reset();
}
use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method annotateExternally.
private void annotateExternally(@NotNull final VirtualFile root, @NotNull final PsiModifierListOwner listOwner, @NotNull final Project project, @NotNull final String packageName, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @Nullable final PsiNameValuePair[] value) {
List<XmlFile> xmlFiles = findExternalAnnotationsXmlFiles(listOwner);
final XmlFile existingXml = findXmlFileInRoot(xmlFiles, root);
if (existingXml != null && !FileModificationService.getInstance().preparePsiElementForWrite(existingXml)) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
return;
}
final Set<PsiFile> annotationFiles = xmlFiles == null ? new THashSet<>() : new THashSet<>(xmlFiles);
new WriteCommandAction(project) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
if (existingXml != null) {
annotateExternally(listOwner, annotationFQName, existingXml, fromFile, value);
} else {
XmlFile newXml = createAnnotationsXml(root, packageName);
if (newXml == null) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
} else {
annotationFiles.add(newXml);
cacheExternalAnnotations(packageName, fromFile, new SmartList<>(annotationFiles));
annotateExternally(listOwner, annotationFQName, newXml, fromFile, value);
}
}
UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction() {
@Override
public void undo() {
dropCache();
notifyChangedExternally();
}
@Override
public void redo() {
dropCache();
notifyChangedExternally();
}
});
}
}.execute();
}
use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class CCSubtaskPlaceholderAction method performAnswerPlaceholderAction.
@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
Editor editor = state.getEditor();
final int offset = editor.getCaretModel().getOffset();
TaskFile taskFile = state.getTaskFile();
int subtaskIndex = state.getTaskFile().getTask().getActiveSubtaskIndex();
AnswerPlaceholder existingPlaceholder = StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders());
if (existingPlaceholder == null) {
return;
}
AnswerPlaceholderSubtaskInfo info = getInfo(state, subtaskIndex, existingPlaceholder);
if (info == null) {
return;
}
EduUtils.runUndoableAction(state.getProject(), getTitle(), new BasicUndoableAction(state.getEditor().getDocument()) {
@Override
public void undo() throws UnexpectedUndoException {
undoAction(existingPlaceholder, subtaskIndex, info);
StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
}
@Override
public void redo() throws UnexpectedUndoException {
redoAction(existingPlaceholder, subtaskIndex, info);
StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
}
});
}
Aggregations