use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class CodeInsightTestCase method undo.
protected void undo() {
UndoManager undoManager = UndoManager.getInstance(myProject);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
undoManager.undo(textEditor);
}
use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class QuickFixFactoryImpl method invokeOnTheFlyImportOptimizer.
private static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable, @NotNull final PsiFile file) {
final Project project = file.getProject();
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (document == null)
return;
final long stamp = document.getModificationStamp();
DumbService.getInstance(file.getProject()).smartInvokeLater(() -> {
if (project.isDisposed() || document.getModificationStamp() != stamp)
return;
//no need to optimize imports on the fly during undo/redo
final UndoManager undoManager = UndoManager.getInstance(project);
if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress())
return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
String beforeText = file.getText();
final long oldStamp = document.getModificationStamp();
DocumentUtil.writeInRunUndoTransparentAction(runnable);
if (oldStamp != document.getModificationStamp()) {
String afterText = file.getText();
if (Comparing.strEqual(beforeText, afterText)) {
LOG.error(LogMessageEx.createEvent("Import optimizer hasn't optimized any imports", file.getViewProvider().getVirtualFile().getPath(), AttachmentFactory.createAttachment(file.getViewProvider().getVirtualFile())));
}
}
});
}
use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class ProxyUndoRedoAction method register.
public static void register(@Nullable Project project, @NotNull Editor editor, @NotNull JComponent component) {
UndoManager undoManager = project != null ? UndoManager.getInstance(project) : UndoManager.getGlobalInstance();
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
if (undoManager != null) {
DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, true), component);
DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, false), component);
}
}
use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class QuickEditHandler method documentChanged.
@Override
public void documentChanged(DocumentEvent e) {
UndoManager undoManager = UndoManager.getInstance(myProject);
boolean undoOrRedo = undoManager.isUndoInProgress() || undoManager.isRedoInProgress();
if (undoOrRedo) {
// and check it after action is completed
if (e.getDocument() == myOrigDocument) {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (myOrigCreationStamp > myOrigDocument.getModificationStamp()) {
closeEditor();
}
});
}
} else if (e.getDocument() == myNewDocument) {
commitToOriginal(e);
if (!isValid()) {
ApplicationManager.getApplication().invokeLater(() -> closeEditor(), myProject.getDisposed());
}
} else if (e.getDocument() == myOrigDocument) {
if (myCommittingToOriginal || myAltFullRange != null && myAltFullRange.isValid())
return;
ApplicationManager.getApplication().invokeLater(() -> closeEditor(), myProject.getDisposed());
}
}
use of com.intellij.openapi.command.undo.UndoManager in project intellij-community by JetBrains.
the class UndoRedoAction method update.
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
DataContext dataContext = event.getDataContext();
FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
// do not allow global undo in dialogs
if (editor == null) {
final Boolean isModalContext = PlatformDataKeys.IS_MODAL_CONTEXT.getData(dataContext);
if (isModalContext != null && isModalContext) {
presentation.setEnabled(false);
return;
}
}
UndoManager undoManager = getUndoManager(editor, dataContext);
if (undoManager == null) {
presentation.setEnabled(false);
return;
}
presentation.setEnabled(isAvailable(editor, undoManager));
Pair<String, String> pair = getActionNameAndDescription(editor, undoManager);
presentation.setText(pair.first);
presentation.setDescription(pair.second);
}
Aggregations