Java Code Examples for com.intellij.openapi.command.CommandProcessor#executeCommand()
The following examples show how to use
com.intellij.openapi.command.CommandProcessor#executeCommand() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloseAllEditorsAction.java From consulo with Apache License 2.0 | 6 votes |
@Override 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); }
Example 2
Source File: AbstractVcsHelperImpl.java From consulo with Apache License 2.0 | 6 votes |
public void openMessagesView(final VcsErrorViewPanel errorTreeView, final String tabDisplayName) { CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(myProject, new Runnable() { @Override public void run() { final MessageView messageView = MessageView.SERVICE.getInstance(myProject); messageView.runWhenInitialized(new Runnable() { @Override public void run() { final Content content = ContentFactory.getInstance().createContent(errorTreeView, tabDisplayName, true); messageView.getContentManager().addContent(content); Disposer.register(content, errorTreeView); messageView.getContentManager().setSelectedContent(content); removeContents(content, tabDisplayName); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW).activate(null); } }); } }, VcsBundle.message("command.name.open.error.message.view"), null); }
Example 3
Source File: TemplateManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
public void startTemplateWithPrefix(final Editor editor, final TemplateImpl template, final int templateStart, @Nullable final PairProcessor<String, String> processor, @Nullable final String argument) { final int caretOffset = editor.getCaretModel().getOffset(); final TemplateState templateState = initTemplateState(editor); CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(myProject, () -> { editor.getDocument().deleteString(templateStart, caretOffset); editor.getCaretModel().moveToOffset(templateStart); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); Map<String, String> predefinedVarValues = null; if (argument != null) { predefinedVarValues = new HashMap<>(); predefinedVarValues.put(TemplateImpl.ARG, argument); } templateState.start(template, processor, predefinedVarValues); }, CodeInsightBundle.message("insert.code.template.command"), null); }
Example 4
Source File: GotoCustomRegionAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull final AnActionEvent e) { final Project project = e.getProject(); final Editor editor = e.getData(CommonDataKeys.EDITOR); if (Boolean.TRUE.equals(e.getData(PlatformDataKeys.IS_MODAL_CONTEXT))) { return; } if (project != null && editor != null) { if (DumbService.getInstance(project).isDumb()) { DumbService.getInstance(project).showDumbModeNotification(IdeBundle.message("goto.custom.region.message.dumb.mode")); return; } CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(project, () -> { Collection<FoldingDescriptor> foldingDescriptors = getCustomFoldingDescriptors(editor, project); if (foldingDescriptors.size() > 0) { CustomFoldingRegionsPopup regionsPopup = new CustomFoldingRegionsPopup(foldingDescriptors, editor, project); regionsPopup.show(); } else { notifyCustomRegionsUnavailable(editor, project); } }, IdeBundle.message("goto.custom.region.command"), null); } }
Example 5
Source File: SearchAgainAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(final AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR); if (editor == null || project == null) return; CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( project, new Runnable() { @Override public void run() { PsiDocumentManager.getInstance(project).commitAllDocuments(); IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation(); if(FindManager.getInstance(project).findNextUsageInEditor(editor)) { return; } FindUtil.searchAgain(project, editor, e.getDataContext()); } }, IdeBundle.message("command.find.next"), null ); }
Example 6
Source File: SearchBackAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(final AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR); CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( project, new Runnable() { @Override public void run() { PsiDocumentManager.getInstance(project).commitAllDocuments(); if(FindManager.getInstance(project).findPreviousUsageInEditor(editor)) { return; } FindUtil.searchBack(project, editor, e.getDataContext()); } }, IdeBundle.message("command.find.previous"), null ); }
Example 7
Source File: FileStructureDialog.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean navigateSelectedElement() { final Ref<Boolean> succeeded = new Ref<Boolean>(); final CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(myProject, new Runnable() { @Override public void run() { succeeded.set(MyCommanderPanel.super.navigateSelectedElement()); IdeDocumentHistory.getInstance(myProject).includeCurrentCommandAsNavigation(); } }, "Navigate", null); if (succeeded.get()) { close(CANCEL_EXIT_CODE); } return succeeded.get(); }
Example 8
Source File: SettingsPanel.java From json2java4idea with Apache License 2.0 | 5 votes |
public void setPreviewText(@Nonnull String text) { final CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(null, () -> { final Application application = ApplicationManager.getApplication(); application.runWriteAction(() -> { previewDocument.replaceString(INITIAL_OFFSET, previewDocument.getTextLength(), text); final int textLength = previewDocument.getTextLength(); final CaretModel caret = previewEditor.getCaretModel(); if (caret.getOffset() >= textLength) { caret.moveToOffset(textLength); } }); }, null, null); }
Example 9
Source File: NewClassDialog.java From json2java4idea with Apache License 2.0 | 5 votes |
public void setJson(@NotNull String json) { final CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(project, () -> { final Application application = ApplicationManager.getApplication(); application.runWriteAction(() -> { jsonDocument.replaceString(INITIAL_OFFSET, jsonDocument.getTextLength(), json); final int textLength = jsonDocument.getTextLength(); final CaretModel caret = jsonEditor.getCaretModel(); if (caret.getOffset() >= textLength) { caret.moveToOffset(textLength); } }); }, null, null); }
Example 10
Source File: CloseEditorsActionBase.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(final AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(project, () -> { List<Pair<EditorComposite, EditorWindow>> filesToClose = getFilesToClose(e); for (int i = 0; i != filesToClose.size(); ++i) { final Pair<EditorComposite, EditorWindow> we = filesToClose.get(i); we.getSecond().closeFile(we.getFirst().getFile()); } }, IdeBundle.message("command.close.all.unmodified.editors"), null); }
Example 11
Source File: SelectAllAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void execute(final Editor editor, DataContext dataContext) { CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(dataContext.getData(CommonDataKeys.PROJECT), new Runnable() { public void run() { editor.getSelectionModel().setSelection(0, editor.getDocument().getTextLength()); } }, IdeBundle.message("command.select.all"), null); }
Example 12
Source File: PrevSplitAction.java From consulo with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( project, new Runnable(){ public void run() { final FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(project); manager.setCurrentWindow(manager.getPrevWindow(manager.getCurrentWindow())); } }, IdeBundle.message("command.go.to.prev.split"), null ); }
Example 13
Source File: NextSplitAction.java From consulo with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( project, new Runnable(){ public void run() { final FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(project); manager.setCurrentWindow(manager.getNextWindow(manager.getCurrentWindow())); } }, IdeBundle.message("command.go.to.next.split"), null ); }
Example 14
Source File: ExecutionHelper.java From consulo with Apache License 2.0 | 5 votes |
private static void openMessagesView(@Nonnull final ErrorViewPanel errorTreeView, @Nonnull final Project myProject, @Nonnull final String tabDisplayName) { CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(myProject, new Runnable() { @Override public void run() { final MessageView messageView = ServiceManager.getService(myProject, MessageView.class); final Content content = ContentFactory.getInstance().createContent(errorTreeView, tabDisplayName, true); messageView.getContentManager().addContent(content); Disposer.register(content, errorTreeView); messageView.getContentManager().setSelectedContent(content); removeContents(content, myProject, tabDisplayName); } }, "Open message view", null); }
Example 15
Source File: FileStructurePopup.java From consulo with Apache License 2.0 | 5 votes |
private boolean navigateSelectedElement() { AbstractTreeNode selectedNode = getSelectedNode(); if (ApplicationManager.getApplication().isInternal()) { String enteredPrefix = mySpeedSearch.getEnteredPrefix(); String itemText = getSpeedSearchText(selectedNode); if (StringUtil.isNotEmpty(enteredPrefix) && StringUtil.isNotEmpty(itemText)) { LOG.info("Chosen in file structure popup by prefix '" + enteredPrefix + "': '" + itemText + "'"); } } Ref<Boolean> succeeded = new Ref<>(); CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(myProject, () -> { if (selectedNode != null) { if (selectedNode.canNavigateToSource()) { selectedNode.navigate(true); myPopup.cancel(); succeeded.set(true); } else { succeeded.set(false); } } else { succeeded.set(false); } IdeDocumentHistory.getInstance(myProject).includeCurrentCommandAsNavigation(); }, "Navigate", null); return succeeded.get(); }
Example 16
Source File: CodeFormatterFacade.java From consulo with Apache License 2.0 | 4 votes |
/** * Emulates pressing {@code Enter} at current caret position. * * @param editor target editor * @param project target project * @param shifts two-elements array which is expected to be filled with the following info: * 1. The first element holds added lines number; * 2. The second element holds added symbols number; */ private static void emulateEnter(@Nonnull final Editor editor, @Nonnull Project project, int[] shifts) { final DataContext dataContext = prepareContext(editor.getComponent(), project); int caretOffset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); SelectionModel selectionModel = editor.getSelectionModel(); int startSelectionOffset = 0; int endSelectionOffset = 0; boolean restoreSelection = selectionModel.hasSelection(); if (restoreSelection) { startSelectionOffset = selectionModel.getSelectionStart(); endSelectionOffset = selectionModel.getSelectionEnd(); selectionModel.removeSelection(); } int textLengthBeforeWrap = document.getTextLength(); int lineCountBeforeWrap = document.getLineCount(); DataManager.getInstance().saveInDataContext(dataContext, WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY, true); CommandProcessor commandProcessor = CommandProcessor.getInstance(); try { Runnable command = () -> EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext); if (commandProcessor.getCurrentCommand() == null) { commandProcessor.executeCommand(editor.getProject(), command, WRAP_LINE_COMMAND_NAME, null); } else { command.run(); } } finally { DataManager.getInstance().saveInDataContext(dataContext, WRAP_LONG_LINE_DURING_FORMATTING_IN_PROGRESS_KEY, null); } int symbolsDiff = document.getTextLength() - textLengthBeforeWrap; if (restoreSelection) { int newSelectionStart = startSelectionOffset; int newSelectionEnd = endSelectionOffset; if (startSelectionOffset >= caretOffset) { newSelectionStart += symbolsDiff; } if (endSelectionOffset >= caretOffset) { newSelectionEnd += symbolsDiff; } selectionModel.setSelection(newSelectionStart, newSelectionEnd); } shifts[0] = document.getLineCount() - lineCountBeforeWrap; shifts[1] = symbolsDiff; }