use of com.intellij.openapi.command.undo.UndoableAction 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.UndoableAction 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();
}
use of com.intellij.openapi.command.undo.UndoableAction in project android by JetBrains.
the class AndroidDbManager method processAddOrRemove.
public void processAddOrRemove(final AndroidDataSource dataSource, final boolean add) {
final Project project = myDbFacade.getProject();
final UndoableAction action = new GlobalUndoableAction() {
public void undo() throws UnexpectedUndoException {
if (add) {
removeDataSourceInner(project, dataSource);
} else {
addDataSourceInner(project, dataSource);
}
}
public void redo() throws UnexpectedUndoException {
if (add) {
addDataSourceInner(project, dataSource);
} else {
removeDataSourceInner(project, dataSource);
}
}
};
final String commandName = add ? DatabaseMessages.message("command.name.add.data.source") : DatabaseMessages.message("command.name.remove.data.source");
new WriteCommandAction(project, commandName) {
protected void run(@NotNull final Result result) throws Throwable {
action.redo();
UndoManager.getInstance(project).undoableActionPerformed(action);
}
@Override
protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
return UndoConfirmationPolicy.REQUEST_CONFIRMATION;
}
}.execute();
}
Aggregations