Search in sources :

Example 6 with UndoManager

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);
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager)

Example 7 with UndoManager

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())));
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) UndoManager(com.intellij.openapi.command.undo.UndoManager) Document(com.intellij.openapi.editor.Document)

Example 8 with UndoManager

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);
    }
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager)

Example 9 with UndoManager

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());
    }
}
Also used : UndoManager(com.intellij.openapi.command.undo.UndoManager)

Example 10 with UndoManager

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);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) FileEditor(com.intellij.openapi.fileEditor.FileEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager) Presentation(com.intellij.openapi.actionSystem.Presentation)

Aggregations

UndoManager (com.intellij.openapi.command.undo.UndoManager)12 Project (com.intellij.openapi.project.Project)4 FileEditor (com.intellij.openapi.fileEditor.FileEditor)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Template (com.intellij.codeInsight.template.Template)1 TemplateEditingAdapter (com.intellij.codeInsight.template.TemplateEditingAdapter)1 TemplateManager (com.intellij.codeInsight.template.TemplateManager)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Application (com.intellij.openapi.application.Application)1 AbnormalCommandTerminationException (com.intellij.openapi.command.AbnormalCommandTerminationException)1 DocumentReference (com.intellij.openapi.command.undo.DocumentReference)1 GlobalUndoableAction (com.intellij.openapi.command.undo.GlobalUndoableAction)1 UndoableAction (com.intellij.openapi.command.undo.UndoableAction)1 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Document (com.intellij.openapi.editor.Document)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 PsiFile (com.intellij.psi.PsiFile)1 Charset (java.nio.charset.Charset)1