use of com.intellij.openapi.command.undo.UnexpectedUndoException in project intellij-community by JetBrains.
the class DynamicDialog method doOKAction.
@Override
protected void doOKAction() {
super.doOKAction();
mySettings.setContainingClassName((String) myClassComboBox.getSelectedItem());
mySettings.setStatic(myStaticCheckBox.isSelected());
GrTypeElement typeElement = getEnteredTypeName();
if (typeElement == null) {
mySettings.setType(CommonClassNames.JAVA_LANG_OBJECT);
} else {
PsiType type = typeElement.getType();
if (type instanceof PsiPrimitiveType) {
type = TypesUtil.boxPrimitiveType(type, typeElement.getManager(), ProjectScope.getAllScope(myProject));
}
final String typeQualifiedName = type.getCanonicalText();
if (typeQualifiedName != null) {
mySettings.setType(typeQualifiedName);
} else {
mySettings.setType(type.getPresentableText());
}
}
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(myContext.getContainingFile());
CommandProcessor.getInstance().executeCommand(myProject, () -> {
UndoManager.getInstance(myProject).undoableActionPerformed(new GlobalUndoableAction(document) {
@Override
public void undo() throws UnexpectedUndoException {
final DItemElement itemElement;
if (mySettings.isMethod()) {
final List<ParamInfo> myPairList = mySettings.getParams();
final String[] argumentsTypes = QuickfixUtil.getArgumentsTypes(myPairList);
itemElement = myDynamicManager.findConcreteDynamicMethod(mySettings.getContainingClassName(), mySettings.getName(), argumentsTypes);
} else {
itemElement = myDynamicManager.findConcreteDynamicProperty(mySettings.getContainingClassName(), mySettings.getName());
}
if (itemElement == null) {
Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
return;
}
final DClassElement classElement = myDynamicManager.getClassElementByItem(itemElement);
if (classElement == null) {
Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
return;
}
removeElement(itemElement);
if (classElement.getMethods().isEmpty() && classElement.getProperties().isEmpty()) {
myDynamicManager.removeClassElement(classElement);
}
}
@Override
public void redo() throws UnexpectedUndoException {
addElement(mySettings);
}
});
addElement(mySettings);
}, "Add dynamic element", null);
}
use of com.intellij.openapi.command.undo.UnexpectedUndoException in project intellij-community by JetBrains.
the class CCChangePlaceholderVisibility method performAnswerPlaceholderAction.
@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
AnswerPlaceholder placeholder = state.getAnswerPlaceholder();
if (placeholder == null) {
return;
}
EduUtils.runUndoableAction(state.getProject(), getName(), new BasicUndoableAction(state.getEditor().getDocument()) {
@Override
public void undo() throws UnexpectedUndoException {
setVisible(placeholder, isVisible(), state);
}
@Override
public void redo() throws UnexpectedUndoException {
setVisible(placeholder, !isVisible(), state);
}
}, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
}
use of com.intellij.openapi.command.undo.UnexpectedUndoException in project intellij-community by JetBrains.
the class CCDeleteAnswerPlaceholder method deletePlaceholder.
private static void deletePlaceholder(@NotNull CCState state) {
Project project = state.getProject();
TaskFile taskFile = state.getTaskFile();
AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
EduUtils.runUndoableAction(project, "Delete Answer Placeholder", new CCAddAnswerPlaceholder.AddAction(answerPlaceholder, taskFile, state.getEditor()) {
@Override
public void undo() throws UnexpectedUndoException {
super.redo();
}
@Override
public void redo() throws UnexpectedUndoException {
super.undo();
}
});
}
use of com.intellij.openapi.command.undo.UnexpectedUndoException in project intellij-community by JetBrains.
the class SuppressForTestsScopeFix method doFix.
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) {
addRemoveTestsScope(project, true);
final VirtualFile vFile = descriptor.getPsiElement().getContainingFile().getVirtualFile();
UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction(vFile) {
@Override
public void undo() throws UnexpectedUndoException {
addRemoveTestsScope(project, false);
}
@Override
public void redo() throws UnexpectedUndoException {
addRemoveTestsScope(project, true);
}
});
}
use of com.intellij.openapi.command.undo.UnexpectedUndoException in project intellij-community by JetBrains.
the class UndoableGroup method doUndoOrRedo.
private void doUndoOrRedo(final boolean isUndo) {
final boolean wrapInBulkUpdate = myActions.size() > 50;
// perform undo action by action, setting bulk update flag if possible
// if multiple consecutive actions share a document, then set the bulk flag only once
final UnexpectedUndoException[] exception = { null };
ApplicationManager.getApplication().runWriteAction(() -> {
final Set<DocumentEx> bulkDocuments = new THashSet<>();
try {
for (final UndoableAction action : isUndo ? ContainerUtil.iterateBackward(myActions) : myActions) {
if (wrapInBulkUpdate) {
DocumentEx newDocument = getDocumentToSetBulkMode(action);
if (newDocument == null) {
for (DocumentEx document : bulkDocuments) {
document.setInBulkUpdate(false);
}
bulkDocuments.clear();
} else if (bulkDocuments.add(newDocument)) {
newDocument.setInBulkUpdate(true);
}
}
if (isUndo) {
action.undo();
} else {
action.redo();
}
}
} catch (UnexpectedUndoException e) {
exception[0] = e;
} finally {
for (DocumentEx bulkDocument : bulkDocuments) {
bulkDocument.setInBulkUpdate(false);
}
}
});
if (exception[0] != null)
reportUndoProblem(exception[0], isUndo);
commitAllDocuments();
}
Aggregations