use of com.intellij.openapi.command.undo.BasicUndoableAction 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.BasicUndoableAction 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.BasicUndoableAction in project intellij-community by JetBrains.
the class LRUPopupBuilder method changeLanguageWithUndo.
private static void changeLanguageWithUndo(@NotNull Project project, @NotNull final Language t, @NotNull final VirtualFile[] sortedFiles, @NotNull final PerFileMappings<Language> mappings) throws UnexpectedUndoException {
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(sortedFiles);
if (status.hasReadonlyFiles())
return;
final Set<VirtualFile> matchedExtensions = ContainerUtil.newLinkedHashSet();
final Map<VirtualFile, Language> oldMapping = ContainerUtil.newHashMap();
for (VirtualFile file : sortedFiles) {
oldMapping.put(file, mappings.getMapping(file));
if (ScratchUtil.hasMatchingExtension(project, file)) {
matchedExtensions.add(file);
}
}
BasicUndoableAction action = new BasicUndoableAction(sortedFiles) {
@Override
public void undo() throws UnexpectedUndoException {
for (VirtualFile file : sortedFiles) {
mappings.setMapping(file, oldMapping.get(file));
}
}
@Override
public void redo() throws UnexpectedUndoException {
for (VirtualFile file : sortedFiles) {
mappings.setMapping(file, t);
}
}
};
action.redo();
UndoManager.getInstance(project).undoableActionPerformed(action);
for (VirtualFile file : matchedExtensions) {
try {
ScratchUtil.updateFileExtension(project, file);
} catch (IOException ignored) {
}
}
}
use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class RenameUtil method doRename.
public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project, @Nullable final RefactoringElementListener listener) throws IncorrectOperationException {
final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
final String fqn = element instanceof PsiFile ? ((PsiFile) element).getVirtualFile().getPath() : CopyReferenceAction.elementToFqn(element);
if (fqn != null) {
UndoableAction action = new BasicUndoableAction() {
@Override
public void undo() throws UnexpectedUndoException {
if (listener instanceof UndoRefactoringElementListener) {
((UndoRefactoringElementListener) listener).undoElementMovedOrRenamed(element, fqn);
}
}
@Override
public void redo() throws UnexpectedUndoException {
}
};
UndoManager.getInstance(project).undoableActionPerformed(action);
}
processor.renameElement(element, newName, usages, listener);
}
use of com.intellij.openapi.command.undo.BasicUndoableAction in project intellij-community by JetBrains.
the class TemplateState method start.
public void start(@NotNull TemplateImpl template, @Nullable final PairProcessor<String, String> processor, @Nullable Map<String, String> predefinedVarValues) {
LOG.assertTrue(!myStarted, "Already started");
myStarted = true;
final PsiFile file = getPsiFile();
myTemplate = substituteTemplate(file, myEditor.getCaretModel().getOffset(), template);
myProcessor = processor;
DocumentReference[] refs = myDocument != null ? new DocumentReference[] { DocumentReferenceManager.getInstance().create(myDocument) } : null;
UndoManager.getInstance(myProject).undoableActionPerformed(new BasicUndoableAction(refs) {
@Override
public void undo() {
if (!isDisposed()) {
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 (myTemplate.isInline()) {
int caretOffset = myEditor.getCaretModel().getOffset();
myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset + myTemplate.getTemplateText().length());
} else {
preprocessTemplate(file, myEditor.getCaretModel().getOffset(), myTemplate.getTemplateText());
int caretOffset = myEditor.getCaretModel().getOffset();
myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset);
}
myTemplateRange.setGreedyToLeft(true);
myTemplateRange.setGreedyToRight(true);
processAllExpressions(myTemplate);
}
Aggregations