Example usage for com.intellij.openapi.command.undo UndoManager getGlobalInstance

List of usage examples for com.intellij.openapi.command.undo UndoManager getGlobalInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.command.undo UndoManager getGlobalInstance.

Prototype

public static UndoManager getGlobalInstance() 

Source Link

Usage

From source file:com.intellij.ide.actions.UndoRedoAction.java

License:Apache License

private static UndoManager getUndoManager(FileEditor editor, DataContext dataContext) {
    Project project = getProject(editor, dataContext);
    return project != null ? UndoManager.getInstance(project) : UndoManager.getGlobalInstance();
}

From source file:com.intellij.psi.formatter.FormatterTestCase.java

License:Open Source License

private void doSanityTestForFile(final File subFile, final List<File> failedFiles, final boolean formatWithPsi)
        throws IOException, IncorrectOperationException {
    if (subFile.isFile() && subFile.getName().endsWith(getFileExtension())) {
        final byte[] bytes = FileUtil.loadFileBytes(subFile);
        final String text = new String(bytes);
        final String fileName = "before." + getFileExtension();
        final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName,
                getFileType(fileName), StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(),
                true);/*  w ww  .  ja  v  a  2 s .c  o m*/

        try {
            CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
                @Override
                public void run() {
                    ApplicationManager.getApplication().runWriteAction(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                if (formatWithPsi) {
                                    performFormatting(file);
                                } else {
                                    performFormattingWithDocument(file);
                                }
                            } catch (Throwable e) {
                                //noinspection CallToPrintStackTrace
                                e.printStackTrace();
                                failedFiles.add(subFile);
                            }
                            //noinspection UseOfSystemOutOrSystemErr
                            System.out.println(subFile.getPath() + ": finished");
                        }
                    });
                }
            }, "", null);
        } finally {
            final VirtualFile virtualFile = file.getVirtualFile();
            if (virtualFile != null) {
                ((UndoManagerImpl) UndoManager.getInstance(getProject()))
                        .clearUndoRedoQueueInTests(virtualFile);
                ((UndoManagerImpl) UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(virtualFile);
            }
        }
    }
}

From source file:com.intellij.testFramework.LightPlatformTestCase.java

License:Apache License

public static void doTearDown(@NotNull final Project project, IdeaTestApplication application,
        boolean checkForEditors) throws Exception {
    DocumentCommitThread.getInstance().clearQueue();
    CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
    checkAllTimersAreDisposed();//from  w  ww .j  av a 2s .  com
    UsefulTestCase.doPostponedFormatting(project);

    LookupManager lookupManager = LookupManager.getInstance(project);
    if (lookupManager != null) {
        lookupManager.hideActiveLookup();
    }
    ((StartupManagerImpl) StartupManager.getInstance(project)).prepareForNextTest();
    InspectionProfileManager.getInstance().deleteProfile(PROFILE);
    assertNotNull("Application components damaged", ProjectManager.getInstance());

    new WriteCommandAction.Simple(project) {
        @Override
        protected void run() throws Throwable {
            if (ourSourceRoot != null) {
                try {
                    final VirtualFile[] children = ourSourceRoot.getChildren();
                    for (VirtualFile child : children) {
                        child.delete(this);
                    }
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            EncodingManager encodingManager = EncodingManager.getInstance();
            if (encodingManager instanceof EncodingManagerImpl)
                ((EncodingManagerImpl) encodingManager).clearDocumentQueue();

            FileDocumentManager manager = FileDocumentManager.getInstance();

            ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flush postponed formatting if any.
            manager.saveAllDocuments();
            if (manager instanceof FileDocumentManagerImpl) {
                ((FileDocumentManagerImpl) manager).dropAllUnsavedDocuments();
            }
        }
    }.execute().throwException();

    assertFalse(PsiManager.getInstance(project).isDisposed());
    if (!ourAssertionsInTestDetected) {
        if (IdeaLogger.ourErrorsOccurred != null) {
            throw IdeaLogger.ourErrorsOccurred;
        }
    }
    PsiDocumentManagerImpl documentManager = clearUncommittedDocuments(project);
    ((HintManagerImpl) HintManager.getInstance()).cleanup();
    DocumentCommitThread.getInstance().clearQueue();

    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
            ((UndoManagerImpl) UndoManager.getGlobalInstance()).dropHistoryInTests();
            ((UndoManagerImpl) UndoManager.getInstance(project)).dropHistoryInTests();

            UIUtil.dispatchAllInvocationEvents();
        }
    });

    TemplateDataLanguageMappings.getInstance(project).cleanupForNextTest();

    ProjectManagerEx.getInstanceEx().closeTestProject(project);
    application.setDataProvider(null);
    ourTestCase = null;
    ((PsiManagerImpl) PsiManager.getInstance(project)).cleanupForNextTest();

    CompletionProgressIndicator.cleanupForNextTest();

    if (checkForEditors) {
        checkEditorsReleased();
    }
    if (isLight(project)) {
        // mark temporarily as disposed so that rogue component trying to access it will fail
        ((ProjectImpl) project).setTemporarilyDisposed(true);
        documentManager.clearUncommittedDocuments();
    }
}

From source file:com.intellij.testFramework.PlatformTestCase.java

License:Apache License

public static void cleanupApplicationCaches(Project project) {
    if (project != null && !project.isDisposed()) {
        UndoManagerImpl globalInstance = (UndoManagerImpl) UndoManager.getGlobalInstance();
        if (globalInstance != null) {
            globalInstance.dropHistoryInTests();
        }/*  w w w. j a va2  s  .  com*/
        ((UndoManagerImpl) UndoManager.getInstance(project)).dropHistoryInTests();

        ((PsiManagerEx) PsiManager.getInstance(project)).getFileManager().cleanupForNextTest();
    }

    LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl) LocalFileSystem.getInstance();
    if (localFileSystem != null) {
        localFileSystem.cleanupForNextTest();
    }

    LocalHistoryImpl.getInstanceImpl().cleanupForNextTest();
}