public boolean navigateSelectedElement() { final Ref<Boolean> succeeded = new Ref<Boolean>(); final CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( myProject, new Runnable() { public void run() { final AbstractTreeNode selectedNode = getSelectedNode(); if (selectedNode != null) { if (selectedNode.canNavigateToSource()) { myPopup.cancel(); selectedNode.navigate(true); succeeded.set(true); } else { succeeded.set(false); } } else { succeeded.set(false); } IdeDocumentHistory.getInstance(myProject).includeCurrentCommandAsNavigation(); } }, "Navigate", null); return succeeded.get(); }
public long assertIntentionApplication(final String intentionId, final String source) { long _xblockexpression = (long) 0; { final PsiFile file = this.configureByText(source); final IntentionAction intention = this.myFixture.findSingleIntention(intentionId); CommandProcessor _instance = CommandProcessor.getInstance(); Project _project = this.getProject(); final Runnable _function = new Runnable() { @Override public void run() { Application _application = ApplicationManager.getApplication(); final Runnable _function = new Runnable() { @Override public void run() { Project _project = file.getProject(); Editor _editor = XtendLibraryManagerTest.this.getEditor(); intention.invoke(_project, _editor, file); Project _project_1 = XtendLibraryManagerTest.this.getProject(); PsiDocumentManager _instance = PsiDocumentManager.getInstance(_project_1); _instance.commitAllDocuments(); } }; _application.runWriteAction(_function); } }; _instance.executeCommand(_project, _function, "", ""); _xblockexpression = this.myFixture.checkHighlighting(); } return _xblockexpression; }
private boolean disposeSelf() { myDisposeInProgress = true; final CommandProcessor commandProcessor = CommandProcessor.getInstance(); final Ref<Boolean> canClose = new Ref<Boolean>(Boolean.TRUE); for (final Project project : ProjectManagerEx.getInstanceEx().getOpenProjects()) { try { commandProcessor.executeCommand( project, new Runnable() { public void run() { canClose.set(ProjectUtil.closeAndDispose(project)); } }, ApplicationBundle.message("command.exit"), null); } catch (Throwable e) { LOG.error(e); } if (!canClose.get()) { myDisposeInProgress = false; return false; } } Disposer.dispose(this); Disposer.assertIsEmpty(); return true; }
protected void assertIntentionApplication( final String intentionId, final String source, final String after) { final PsiFile file = this.configureByText(source); final IntentionAction intention = this.myFixture.findSingleIntention(intentionId); CommandProcessor _instance = CommandProcessor.getInstance(); Project _project = this.getProject(); final Runnable _function = new Runnable() { @Override public void run() { Application _application = ApplicationManager.getApplication(); final Runnable _function = new Runnable() { @Override public void run() { Project _project = file.getProject(); Editor _editor = IntentionsTest.this.getEditor(); intention.invoke(_project, _editor, file); Project _project_1 = IntentionsTest.this.getProject(); PsiDocumentManager _instance = PsiDocumentManager.getInstance(_project_1); _instance.commitAllDocuments(); } }; _application.runWriteAction(_function); } }; _instance.executeCommand(_project, _function, "", ""); Editor _editor = this.myFixture.getEditor(); Document _document = _editor.getDocument(); String _text = _document.getText(); TestCase.assertEquals(after, _text); }
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<String, String>(); predefinedVarValues.put(TemplateImpl.ARG, argument); } templateState.start(template, processor, predefinedVarValues); }, CodeInsightBundle.message("insert.code.template.command"), null); }
private static void copyClassesImpl( final String copyClassName, final Project project, final Map<PsiFile, PsiClass[]> classes, final HashMap<PsiFile, String> map, final Object targetDirectory, final PsiDirectory defaultTargetDirectory, final String commandName, final boolean selectInActivePanel, final boolean openInEditor) { final boolean[] result = new boolean[] {false}; Runnable command = () -> { final Runnable action = () -> { try { PsiDirectory target; if (targetDirectory instanceof PsiDirectory) { target = (PsiDirectory) targetDirectory; } else { target = ((MoveDestination) targetDirectory) .getTargetDirectory(defaultTargetDirectory); } Collection<PsiFile> files = doCopyClasses(classes, map, copyClassName, target, project); if (files != null) { if (openInEditor) { for (PsiFile file : files) { CopyHandler.updateSelectionInActiveProjectView( file, project, selectInActivePanel); } EditorHelper.openFilesInEditor(files.toArray(new PsiFile[files.size()])); } result[0] = true; } } catch (final IncorrectOperationException ex) { ApplicationManager.getApplication() .invokeLater( () -> Messages.showMessageDialog( project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon())); } }; ApplicationManager.getApplication().runWriteAction(action); }; CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(project, command, commandName, null); if (result[0]) { ToolWindowManager.getInstance(project) .invokeLater(() -> ToolWindowManager.getInstance(project).activateEditorComponent()); } }
/** * Emulates pressing <code>Enter</code> 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( @NotNull final Editor editor, @NotNull 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 = new Runnable() { @Override public void run() { 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; }
private static void openMessagesView( @NotNull final RailsErrorViewPanel errorTreeView, @NotNull final Project myProject, @NotNull final String tabDisplayName) { CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand( myProject, new Runnable() { public void run() { final MessageView messageView = ServiceManager.getService(myProject, MessageView.class); final Content content = ContentFactory.SERVICE .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); }