Search in sources :

Example 6 with CommandProcessor

use of com.intellij.openapi.command.CommandProcessor in project intellij-community by JetBrains.

the class PomModelImpl method startTransaction.

private void startTransaction(@NotNull PomTransaction transaction) {
    final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    if (progressIndicator != null)
        progressIndicator.startNonCancelableSection();
    final PsiDocumentManagerBase manager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(myProject);
    final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
    final PsiElement changeScope = transaction.getChangeScope();
    final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
    if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
        PsiUtilCore.ensureValid(containingFileByTree);
    }
    boolean physical = changeScope.isPhysical();
    if (physical && synchronizer.toProcessPsiEvent()) {
        // so it's important to throw something outside event processing
        if (isDocumentUncommitted(containingFileByTree)) {
            throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
        }
        CommandProcessor commandProcessor = CommandProcessor.getInstance();
        if (!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
            throw new IncorrectOperationException("Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
        }
    }
    if (containingFileByTree != null) {
        ((SmartPointerManagerImpl) SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
        if (containingFileByTree instanceof PsiFileImpl) {
            ((PsiFileImpl) containingFileByTree).beforeAstChange();
        }
    }
    BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl) PsiManager.getInstance(myProject), changeScope, true);
    Document document = containingFileByTree == null ? null : physical ? manager.getDocument(containingFileByTree) : manager.getCachedDocument(containingFileByTree);
    if (document != null) {
        synchronizer.startTransaction(myProject, document, changeScope);
    }
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) Document(com.intellij.openapi.editor.Document) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CommandProcessor(com.intellij.openapi.command.CommandProcessor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) SmartPointerManagerImpl(com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl)

Example 7 with CommandProcessor

use of com.intellij.openapi.command.CommandProcessor in project intellij-community by JetBrains.

the class DocumentTest method testModificationInsideCommandAssertion.

public void testModificationInsideCommandAssertion() {
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    assertTrue(!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null);
    final Document doc = new DocumentImpl("xxx");
    mustThrow(() -> doc.insertString(1, "x"));
    mustThrow(() -> doc.deleteString(1, 2));
    mustThrow(() -> doc.replaceString(1, 2, "s"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.insertString(1, "s"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.deleteString(1, 2));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.replaceString(1, 2, "xxx"));
    WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.setText("sss"));
    DocumentImpl console = new DocumentImpl("xxxx", true);
    // need no stinking command
    console.insertString(1, "s");
    console.deleteString(1, 2);
    console.replaceString(1, 2, "xxx");
    console.setText("sss");
}
Also used : CommandProcessor(com.intellij.openapi.command.CommandProcessor) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 8 with CommandProcessor

use of com.intellij.openapi.command.CommandProcessor in project intellij-community by JetBrains.

the class IdeaLogger method logErrorHeader.

private void logErrorHeader() {
    final String info = ourApplicationInfoProvider.getInfo();
    if (info != null) {
        myLogger.error(info);
    }
    if (ourCompilationTimestamp != null) {
        myLogger.error("Internal version. Compiled " + ourCompilationTimestamp);
    }
    myLogger.error("JDK: " + System.getProperties().getProperty("java.version", "unknown"));
    myLogger.error("VM: " + System.getProperties().getProperty("java.vm.name", "unknown"));
    myLogger.error("Vendor: " + System.getProperties().getProperty("java.vendor", "unknown"));
    myLogger.error("OS: " + System.getProperties().getProperty("os.name", "unknown"));
    ApplicationImpl application = (ApplicationImpl) ApplicationManager.getApplication();
    if (application != null && application.isComponentsCreated() && !application.isDisposed()) {
        final String lastPreformedActionId = ourLastActionId;
        if (lastPreformedActionId != null) {
            myLogger.error("Last Action: " + lastPreformedActionId);
        }
        CommandProcessor commandProcessor = CommandProcessor.getInstance();
        if (commandProcessor != null) {
            final String currentCommandName = commandProcessor.getCurrentCommandName();
            if (currentCommandName != null) {
                myLogger.error("Current Command: " + currentCommandName);
            }
        }
    }
}
Also used : ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) CommandProcessor(com.intellij.openapi.command.CommandProcessor)

Example 9 with CommandProcessor

use of com.intellij.openapi.command.CommandProcessor in project intellij-community by JetBrains.

the class NextSplitAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    final CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, () -> {
        final FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(project);
        manager.setCurrentWindow(manager.getNextWindow(manager.getCurrentWindow()));
    }, IdeBundle.message("command.go.to.next.split"), null);
}
Also used : Project(com.intellij.openapi.project.Project) CommandProcessor(com.intellij.openapi.command.CommandProcessor) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)

Example 10 with CommandProcessor

use of com.intellij.openapi.command.CommandProcessor in project intellij-community by JetBrains.

the class CloseAllEditorsAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, () -> {
        final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
        if (window != null) {
            final VirtualFile[] files = window.getFiles();
            for (final VirtualFile file : files) {
                window.closeFile(file);
            }
            return;
        }
        FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
        VirtualFile selectedFile = fileEditorManager.getSelectedFiles()[0];
        VirtualFile[] openFiles = fileEditorManager.getSiblings(selectedFile);
        for (final VirtualFile openFile : openFiles) {
            fileEditorManager.closeFile(openFile);
        }
    }, IdeBundle.message("command.close.all.editors"), null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CommandProcessor(com.intellij.openapi.command.CommandProcessor) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Aggregations

CommandProcessor (com.intellij.openapi.command.CommandProcessor)22 Project (com.intellij.openapi.project.Project)8 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)3 FindManager (com.intellij.find.FindManager)2 Editor (com.intellij.openapi.editor.Editor)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)2 Content (com.intellij.ui.content.Content)2 MessageView (com.intellij.ui.content.MessageView)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 EditorGotoLineNumberDialog (com.intellij.ide.util.EditorGotoLineNumberDialog)1 GotoLineNumberDialog (com.intellij.ide.util.GotoLineNumberDialog)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)1 CommandAdapter (com.intellij.openapi.command.CommandAdapter)1 CommandEvent (com.intellij.openapi.command.CommandEvent)1 Document (com.intellij.openapi.editor.Document)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 EditorComposite (com.intellij.openapi.fileEditor.impl.EditorComposite)1