Java Code Examples for com.intellij.openapi.actionSystem.DataContext
The following examples show how to use
com.intellij.openapi.actionSystem.DataContext. These examples are extracted from open source projects.
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 Project: consulo Source File: KillRingSaveAction.java License: Apache License 2.0 | 6 votes |
@Override public void execute(final Editor editor, final DataContext dataContext) { SelectionModel selectionModel = editor.getSelectionModel(); if (!selectionModel.hasSelection()) { return; } final int start = selectionModel.getSelectionStart(); final int end = selectionModel.getSelectionEnd(); if (start >= end) { return; } KillRingUtil.copyToKillRing(editor, start, end, false); if (myRemove) { ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) { @Override public void run() { editor.getDocument().deleteString(start, end); } }); } }
Example 2
Source Project: consulo Source File: InlineRefactoringActionHandler.java License: Apache License 2.0 | 6 votes |
@Override public void invoke(@Nonnull final Project project, Editor editor, PsiFile file, DataContext dataContext) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); PsiElement element = dataContext.getData(LangDataKeys.PSI_ELEMENT); if (element == null) { element = BaseRefactoringAction.getElementAtCaret(editor, file); } if (element != null) { for(InlineActionHandler handler: Extensions.getExtensions(InlineActionHandler.EP_NAME)) { if (handler.canInlineElementInEditor(element, editor)) { handler.inlineElement(project, editor, element); return; } } if (invokeInliner(editor, element)) return; String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.method.or.local.name")); CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, null); } }
Example 3
Source Project: jetbrains-plugin-graph-database-support Source File: TreeMouseAdapter.java License: Apache License 2.0 | 6 votes |
@Override public void mouseClicked(MouseEvent e) { Tree tree = (Tree) e.getComponent(); TreePath pathForLocation = tree.getPathForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { Optional.ofNullable(pathForLocation) .flatMap(p -> cast(p.getLastPathComponent(), PatchedDefaultMutableTreeNode.class)) .flatMap(n -> cast(n.getUserObject(), LinkLabel.class)) .ifPresent(LinkLabel::doClick); } else if (SwingUtilities.isRightMouseButton(e)) { DataContext dataContext = DataManager.getInstance().getDataContext(tree); contextMenuService.getContextMenu(pathForLocation) .ifPresent(dto -> dto.showPopup(dataContext)); } }
Example 4
Source Project: aem-ide-tooling-4-intellij Source File: ImportFromServerAction.java License: Apache License 2.0 | 6 votes |
@Override protected void execute(@NotNull Project project, @NotNull DataContext dataContext, final ProgressHandler progressHandler) { VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if(virtualFiles != null) { switch(virtualFiles.length) { case 0: //AS TODO: Alert User about unselected folder break; case 1: doImport(project, virtualFiles[0]); break; default: //AS TODO: Alert user about too many selected folders } } }
Example 5
Source Project: azure-devops-intellij Source File: SelectWorkItemsAction.java License: MIT License | 6 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent) { final DataContext dc = anActionEvent.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dc); final Refreshable panel = CheckinProjectPanel.PANEL_KEY.getData(dc); final CommitMessageI commitMessageI = (panel instanceof CommitMessageI) ? (CommitMessageI) panel : VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(dc); if (commitMessageI != null && project != null) { String commitMessage = ""; // Attempt to append the message instead of overwriting it if (commitMessageI instanceof CommitChangeListDialog) { commitMessage = ((CommitChangeListDialog) commitMessageI).getCommitMessage(); } SelectWorkItemsDialog dialog = new SelectWorkItemsDialog(project); if (dialog.showAndGet()) { if (StringUtils.isNotEmpty(commitMessage)) { commitMessage += "\n" + dialog.getComment(); } else { commitMessage = dialog.getComment(); } commitMessageI.setCommitMessage(commitMessage); } } }
Example 6
Source Project: consulo Source File: XDebuggerUtilImpl.java License: Apache License 2.0 | 6 votes |
@Nonnull public static Collection<XSourcePosition> getAllCaretsPositions(@Nonnull Project project, DataContext context) { Editor editor = getEditor(project, context); if (editor == null) { return Collections.emptyList(); } final Document document = editor.getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); Collection<XSourcePosition> res = new ArrayList<XSourcePosition>(); List<Caret> carets = editor.getCaretModel().getAllCarets(); for (Caret caret : carets) { int line = caret.getLogicalPosition().line; XSourcePositionImpl position = XSourcePositionImpl.create(file, line); if (position != null) { res.add(position); } } return res; }
Example 7
Source Project: bamboo-soy Source File: EnterHandler.java License: Apache License 2.0 | 6 votes |
@Override public Result postProcessEnter( @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) { if (file.getFileType() != SoyFileType.INSTANCE) { return Result.Continue; } int caretOffset = editor.getCaretModel().getOffset(); PsiElement element = file.findElementAt(caretOffset); Document document = editor.getDocument(); int lineNumber = document.getLineNumber(caretOffset) - 1; int lineStartOffset = document.getLineStartOffset(lineNumber); String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset)); if (element instanceof PsiComment && element.getTextOffset() < caretOffset) { handleEnterInComment(element, file, editor); } else if (lineTextBeforeCaret.startsWith("/*")) { insertText(file, editor, " * \n ", 3); } return Result.Continue; }
Example 8
Source Project: intellij Source File: GenerateDeployableJarTaskProvider.java License: Apache License 2.0 | 6 votes |
@Override public boolean executeTask( DataContext context, RunConfiguration configuration, ExecutionEnvironment env, Task task) { Label target = getTarget(configuration); if (target == null) { return false; } try { File outputJar = getDeployableJar(configuration, env, target); LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(outputJar)); ((ApplicationConfiguration) configuration).setVMParameters("-cp " + outputJar.getPath()); return true; } catch (ExecutionException e) { ExecutionUtil.handleExecutionError( env.getProject(), env.getExecutor().getToolWindowId(), env.getRunProfile(), e); } return false; }
Example 9
Source Project: StringManipulation Source File: AbstractStringManipAction.java License: Apache License 2.0 | 6 votes |
protected String transformSelection(Editor editor, Map<String, Object> actionContext, DataContext dataContext, String selectedText, T additionalParam) { String[] textParts = selectedText.split("\n"); for (int i = 0; i < textParts.length; i++) { if (!StringUtils.isBlank(textParts[i])) { textParts[i] = transformByLine(actionContext, textParts[i]); } } String join = StringUtils.join(textParts, '\n'); if (selectedText.endsWith("\n")) { return join + "\n"; } return join; }
Example 10
Source Project: consulo Source File: XDebuggerTreeActionBase.java License: Apache License 2.0 | 6 votes |
@Nonnull public static List<XValueNodeImpl> getSelectedNodes(DataContext dataContext) { XDebuggerTree tree = XDebuggerTree.getTree(dataContext); if (tree == null) return Collections.emptyList(); TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length == 0) { return Collections.emptyList(); } List<XValueNodeImpl> result = new ArrayList<>(); for (TreePath path : paths) { Object lastPathComponent = path.getLastPathComponent(); if(lastPathComponent instanceof XValueNodeImpl) { result.add((XValueNodeImpl)lastPathComponent); } } return result; }
Example 11
Source Project: StringManipulation Source File: AbstractStringManipAction.java License: Apache License 2.0 | 6 votes |
protected void executeMyWriteActionPerCaret(Editor editor, Caret caret, Map<String, Object> actionContext, DataContext dataContext, T additionalParam) { final SelectionModel selectionModel = editor.getSelectionModel(); String selectedText = selectionModel.getSelectedText(); if (selectedText == null) { selectSomethingUnderCaret(editor, dataContext, selectionModel); selectedText = selectionModel.getSelectedText(); if (selectedText == null) { return; } } String s = transformSelection(editor, actionContext, dataContext, selectedText, additionalParam); s = s.replace("\r\n", "\n"); s = s.replace("\r", "\n"); editor.getDocument().replaceString(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), s); }
Example 12
Source Project: consulo Source File: FilePathRelativeToSourcepathMacro.java License: Apache License 2.0 | 6 votes |
@Override public String expand(final DataContext dataContext) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return null; } VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE); if (file == null) { return null; } final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(file); if (sourceRoot == null) { return null; } return FileUtil.getRelativePath(getIOFile(sourceRoot), getIOFile(file)); }
Example 13
Source Project: lsp4intellij Source File: LSPRenameHandler.java License: Apache License 2.0 | 5 votes |
@Override public boolean isAvailableOnDataContext(DataContext dataContext) { PsiElement element = PsiElementRenameHandler.getElement(dataContext); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); return editor != null && file != null && isAvailable(element, editor, file); }
Example 14
Source Project: consulo Source File: CopyPasteDelegator.java License: Apache License 2.0 | 5 votes |
private boolean isDefaultPasteEnabled(final DataContext dataContext) { Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return false; } if (DumbService.isDumb(project)) return false; Object target = dataContext.getData(LangDataKeys.PASTE_TARGET_PSI_ELEMENT); if (target == null) { return false; } PsiElement[] elements = PsiCopyPasteManager.getInstance().getElements(new boolean[]{false}); if (elements == null) { return false; } // disable cross-project paste for (PsiElement element : elements) { PsiManager manager = element.getManager(); if (manager == null || manager.getProject() != project) { return false; } } return true; }
Example 15
Source Project: consulo Source File: Macro.java License: Apache License 2.0 | 5 votes |
@Nullable protected static VirtualFile getVirtualDirOrParent(DataContext dataContext) { VirtualFile vFile = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE); if (vFile != null && !vFile.isDirectory()) { vFile = vFile.getParent(); } return vFile; }
Example 16
Source Project: StringManipulation Source File: AbstractCaseConvertingAction.java License: Apache License 2.0 | 5 votes |
private boolean genericHandling(Editor editor, DataContext dataContext, SelectionModel selectionModel, PsiFile psiFile) { int caretOffset = editor.getCaretModel().getOffset(); PsiElement elementAtCaret = PsiUtilBase.getElementAtCaret(editor); if (elementAtCaret instanceof PsiPlainText) { return super.selectSomethingUnderCaret(editor, dataContext, selectionModel); } else if (elementAtCaret instanceof PsiWhiteSpace) { elementAtCaret = PsiUtilBase.getElementAtOffset(psiFile, caretOffset - 1); } if (elementAtCaret == null || elementAtCaret instanceof PsiWhiteSpace) { return super.selectSomethingUnderCaret(editor, dataContext, selectionModel); } else { TextRange textRange = elementAtCaret.getTextRange(); if (textRange.getLength() == 0) { return super.selectSomethingUnderCaret(editor, dataContext, selectionModel); } selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset()); String selectedText = selectionModel.getSelectedText(); if (selectedText != null && selectedText.contains("\n")) { selectionModel.removeSelection(); return super.selectSomethingUnderCaret(editor, dataContext, selectionModel); } if (StringUtil.isQuoted(selectedText)) { selectionModel.setSelection(selectionModel.getSelectionStart() + 1, selectionModel.getSelectionEnd() - 1); } if (caretOffset < selectionModel.getSelectionStart()) { editor.getCaretModel().moveToOffset(selectionModel.getSelectionStart()); } if (caretOffset > selectionModel.getSelectionEnd()) { editor.getCaretModel().moveToOffset(selectionModel.getSelectionEnd()); } return true; } }
Example 17
Source Project: consulo Source File: Macro.java License: Apache License 2.0 | 5 votes |
public void cachePreview(DataContext dataContext) { try{ myCachedPreview = expand(dataContext); } catch(ExecutionCancelledException e){ myCachedPreview = ""; } }
Example 18
Source Project: intellij-haxe Source File: ExtractInterfaceHandler.java License: Apache License 2.0 | 5 votes |
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) { if (elements.length != 1) return; myProject = project; myClass = (PsiClass)elements[0]; if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myClass)) return; final ExtractInterfaceDialog dialog = new ExtractInterfaceDialog(myProject, myClass); if (!dialog.showAndGet() || !dialog.isExtractSuperclass()) { return; } final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); ExtractSuperClassUtil.checkSuperAccessible(dialog.getTargetDirectory(), conflicts, myClass); if (!ExtractSuperClassUtil.showConflicts(dialog, conflicts, myProject)) return; CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { myInterfaceName = dialog.getExtractedSuperName(); mySelectedMembers = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class); myTargetDir = dialog.getTargetDirectory(); myJavaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy()); try { doRefactoring(); } catch (IncorrectOperationException e) { LOG.error(e); } } }); } }, REFACTORING_NAME, null); }
Example 19
Source Project: consulo Source File: SelectAllAction.java License: 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 20
Source Project: consulo Source File: LookupActionHandler.java License: Apache License 2.0 | 5 votes |
@Override public void doExecute(@Nonnull Editor editor, Caret caret, DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isAvailableToUser()) { Project project = editor.getProject(); if (project != null && lookup != null) { LookupManager.getInstance(project).hideActiveLookup(); } myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); executeInLookup(lookup, dataContext, caret); }
Example 21
Source Project: consulo Source File: ModuleProfileNameMacro.java License: Apache License 2.0 | 5 votes |
@Override public String expand(DataContext dataContext) { final Module module = dataContext.getData(LangDataKeys.MODULE); if(module == null) { return null; } ModuleRootManager rootManager = ModuleRootManager.getInstance(module); return rootManager.getCurrentLayerName(); }
Example 22
Source Project: consulo Source File: ExecutionManagerImpl.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void runBeforeTask(@Nonnull List<BeforeRunTask> beforeRunTasks, int index, long executionSessionId, @Nonnull ExecutionEnvironment environment, @Nonnull UIAccess uiAccess, @Nonnull DataContext dataContext, @Nonnull RunConfiguration runConfiguration, @Nonnull AsyncResult<Void> finishResult) { if (beforeRunTasks.size() == index) { finishResult.setDone(); return; } if (myProject.isDisposed()) { return; } BeforeRunTask task = beforeRunTasks.get(index); BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId()); if (provider == null) { LOG.warn("Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'"); runBeforeTask(beforeRunTasks, index + 1, executionSessionId, environment, uiAccess, dataContext, runConfiguration, finishResult); return; } myApplication.executeOnPooledThread(() -> { ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build(); taskEnvironment.setExecutionId(executionSessionId); taskEnvironment.putUserData(EXECUTION_SESSION_ID_KEY, executionSessionId); AsyncResult<Void> result = provider.executeTaskAsync(uiAccess, dataContext, runConfiguration, taskEnvironment, task); result.doWhenDone(() -> runBeforeTask(beforeRunTasks, index + 1, executionSessionId, environment, uiAccess, dataContext, runConfiguration, finishResult)); result.doWhenRejected((Runnable)finishResult::setRejected); }); }
Example 23
Source Project: consulo Source File: XAddToWatchesFromEditorActionHandler.java License: Apache License 2.0 | 5 votes |
@Override protected void perform(@Nonnull XDebugSession session, DataContext dataContext) { final String text = getTextToEvaluate(dataContext, session); if (text == null) return; ((XDebugSessionImpl)session).getSessionTab().getWatchesView().addWatchExpression(XExpressionImpl.fromText(text), -1, true); }
Example 24
Source Project: consulo Source File: MoveHandler.java License: Apache License 2.0 | 5 votes |
/** * called by an Action in AtomicAction when refactoring is invoked from Editor */ @Override public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) { int offset = editor.getCaretModel().getOffset(); editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); PsiElement element = file.findElementAt(offset); while(true){ if (element == null) { String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("the.caret.should.be.positioned.at.the.class.method.or.field.to.be.refactored")); CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, null); return; } if (tryToMoveElement(element, project, dataContext, null, editor)) { return; } final TextRange range = element.getTextRange(); if (range != null) { int relative = offset - range.getStartOffset(); final PsiReference reference = element.findReferenceAt(relative); if (reference != null) { final PsiElement refElement = reference.resolve(); if (refElement != null && tryToMoveElement(refElement, project, dataContext, reference, editor)) return; } } element = element.getParent(); } }
Example 25
Source Project: consulo Source File: CommitCompletionContributor.java License: Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY); if (dataContext != null) { result.stopHere(); if (parameters.getInvocationCount() > 0) { ChangeList[] lists = dataContext.getData(VcsDataKeys.CHANGE_LISTS); if (lists != null) { String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters); CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix)); for (ChangeList list : lists) { for (Change change : list.getChanges()) { VirtualFile virtualFile = change.getVirtualFile(); if (virtualFile != null) { LookupElementBuilder element = LookupElementBuilder.create(virtualFile.getName()). withIcon(VirtualFilePresentation.getAWTIcon(virtualFile)); insensitive.addElement(element); } } } } } } } }
Example 26
Source Project: consulo Source File: EditorWriteActionHandler.java License: Apache License 2.0 | 5 votes |
/** * @deprecated Use/override * {@link #executeWriteAction(Editor, Caret, DataContext)} * instead. */ @RequiredWriteAction public void executeWriteAction(Editor editor, DataContext dataContext) { if (inExecution) { return; } try { inExecution = true; executeWriteAction(editor, editor.getCaretModel().getCurrentCaret(), dataContext); } finally { inExecution = false; } }
Example 27
Source Project: buck Source File: BuckCommandBeforeRunTaskProvider.java License: Apache License 2.0 | 5 votes |
@Override public Promise<Boolean> configureTask( @NotNull DataContext context, @NotNull RunConfiguration configuration, @NotNull BuckCommandBeforeRunTask task) { Project project = configuration.getProject(); final BuckCommandToolEditorDialog dialog = new BuckCommandToolEditorDialog(project); dialog.setArguments(task.getArguments()); if (dialog.showAndGet()) { task.setArguments(dialog.getArguments()); Promises.resolvedPromise(true); } return Promises.resolvedPromise(false); }
Example 28
Source Project: consulo Source File: SelectWordAtCaretAction.java License: Apache License 2.0 | 5 votes |
@Override public void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { SelectionModel selectionModel = editor.getSelectionModel(); Document document = editor.getDocument(); if (EditorUtil.isPasswordEditor(editor)) { selectionModel.setSelection(0, document.getTextLength()); return; } int lineNumber = editor.getCaretModel().getLogicalPosition().line; int caretOffset = editor.getCaretModel().getOffset(); if (lineNumber >= document.getLineCount()) { return; } boolean camel = editor.getSettings().isCamelWords(); List<TextRange> ranges = new ArrayList<TextRange>(); int textLength = document.getTextLength(); if (caretOffset == textLength) caretOffset--; if (caretOffset < 0) return; SelectWordUtil.addWordOrLexemeSelection(camel, editor, caretOffset, ranges); if (ranges.isEmpty()) return; final TextRange selectionRange = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); TextRange minimumRange = new TextRange(0, document.getTextLength()); for (TextRange range : ranges) { if (range.contains(selectionRange) && !range.equals(selectionRange)) { if (minimumRange.contains(range)) { minimumRange = range; } } } selectionModel.setSelection(minimumRange.getStartOffset(), minimumRange.getEndOffset()); }
Example 29
Source Project: intellij Source File: BlazeRenderErrorContributor.java License: Apache License 2.0 | 5 votes |
@Override public RenderErrorContributor getContributor( @Nullable EditorDesignSurface surface, RenderResult result, @Nullable DataContext dataContext) { return new BlazeRenderErrorContributor(surface, result, dataContext); }
Example 30
Source Project: react-templates-plugin Source File: RTMergerTreeStructureProvider.java License: MIT License | 5 votes |
@Override public void performPaste(@NotNull DataContext dataContext) { RTFile[] rtFiles = RTFile.DATA_KEY.getData(dataContext); if (rtFiles != null) { System.out.println(rtFiles.length); } }