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);
}
}
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");
}
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);
}
}
}
}
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);
}
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);
}
Aggregations