@Nullable public Object getData(String dataId) { Object data = myPaletteWindow.getData(dataId); if (data != null) return data; Project project = CommonDataKeys.PROJECT.getData(myPaletteWindow); return myGroup.getData(project, dataId); }
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; PsiDocumentManager.getInstance(project).commitAllDocuments(); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataContext); if (usageTargets != null) { FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext); if (fileEditor != null) { usageTargets[0].findUsagesInEditor(fileEditor); } } else if (editor == null) { Messages.showMessageDialog( project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } else { HintManager.getInstance() .showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error")); } }
private static boolean isEnabled(DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || EditorGutter.KEY.getData(dataContext) != null || Boolean.TRUE.equals(dataContext.getData(CommonDataKeys.EDITOR_VIRTUAL_SPACE))) { return false; } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (editor == null) { UsageTarget[] target = UsageView.USAGE_TARGETS_KEY.getData(dataContext); return target != null && target.length > 0; } else { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { return false; } Language language = PsiUtilBase.getLanguageInEditor(editor, project); if (language == null) { language = file.getLanguage(); } return !(LanguageFindUsages.INSTANCE.forLanguage(language) instanceof EmptyFindUsagesProvider); } }
@RequiredDispatchThread @Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; IdeDocumentHistory.getInstance(project).back(); }
@Nullable @Override public Object getData(@NonNls String dataId) { Object data; DataProvider contentProvider = DataManagerImpl.getDataProviderEx(myContentPanel.getTargetComponent()); if (contentProvider != null) { data = contentProvider.getData(dataId); if (data != null) return data; } if (CommonDataKeys.PROJECT.is(dataId)) { return myProject; } else if (PlatformDataKeys.HELP_ID.is(dataId)) { if (myRequest.getUserData(DiffUserDataKeys.HELP_ID) != null) { return myRequest.getUserData(DiffUserDataKeys.HELP_ID); } else { return "procedures.vcWithIDEA.commonVcsOps.integrateDiffs.resolveConflict"; } } DataProvider requestProvider = myRequest.getUserData(DiffUserDataKeys.DATA_PROVIDER); if (requestProvider != null) { data = requestProvider.getData(dataId); if (data != null) return data; } DataProvider contextProvider = myContext.getUserData(DiffUserDataKeys.DATA_PROVIDER); if (contextProvider != null) { data = contextProvider.getData(dataId); if (data != null) return data; } return null; }
@NotNull @Override public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) { final Editor editor = CommonDataKeys.EDITOR.getData(context); final Project project = CommonDataKeys.PROJECT.getData(context); final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context); if (editor == null || element == null || project == null) { return Collections.emptyList(); } PsiMethod method = null; for (PsiElement e = element; e != null; e = e.getParent()) { if (e instanceof PsiMethod) { method = (PsiMethod) e; break; } } if (method == null) { return Collections.emptyList(); } final List<String> testDataFiles = NavigateToTestDataAction.findTestDataFiles(context); if (testDataFiles == null || testDataFiles.isEmpty()) { return Collections.emptyList(); } return Collections.singletonList(new TestDataRelatedItem(method, editor, testDataFiles)); }
@Override public void execute( final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) { if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; final Document document = editor.getDocument(); if (!FileDocumentManager.getInstance() .requestWriting(document, CommonDataKeys.PROJECT.getData(dataContext))) { return; } DataContext context = dataContext; if (producer != null) { context = new DataContext() { @Override public Object getData(@NonNls String dataId) { return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? producer : dataContext.getData(dataId); } }; } final Project project = editor.getProject(); if (project == null || editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection() || editor.getCaretModel().getCaretCount() > 1) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, context); } return; } final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, context); } return; } document.startGuardedBlockChecking(); try { for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) { if (provider.isPasteEnabled(context)) { provider.performPaste(context); return; } } doPaste(editor, project, file, document, producer); } catch (ReadOnlyFragmentModificationException e) { EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e); } finally { document.stopGuardedBlockChecking(); } }
@Override public void actionPerformed(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = CommonDataKeys.PROJECT.getData(dataContext); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (project == null || editor == null) { presentation.setEnabled(false); return; } PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null || file.getVirtualFile() == null) { presentation.setEnabled(false); return; } boolean hasSelection = editor.getSelectionModel().hasSelection(); LayoutCodeDialog dialog = new LayoutCodeDialog(project, file, hasSelection, HELP_ID); dialog.show(); if (dialog.isOK()) { new FileInEditorProcessor(file, editor, dialog.getRunOptions()).processCode(); } }
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setVisible(false); final DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext); if (isPatternBasedConfiguration(configuration)) { final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext); if (testProxy != null) { final Location location = testProxy.getLocation( project, ((T) configuration).getConfigurationModule().getSearchScope()); if (location != null) { final PsiElement psiElement = location.getPsiElement(); if (psiElement instanceof PsiClass && getPattern((T) configuration) .contains(((PsiClass) psiElement).getQualifiedName())) { presentation.setVisible(true); } } } } } }
@Nullable public Object getData(String dataId) { if (CommonDataKeys.PROJECT.is(dataId)) { return editor != null ? editor.getProject() : null; } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { return editor != null ? editor.getFile() : null; } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) { return editor != null ? new VirtualFile[] {editor.getFile()} : new VirtualFile[] {}; } else if (CommonDataKeys.PSI_FILE.is(dataId)) { return getData(CommonDataKeys.PSI_ELEMENT.getName()); } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) { VirtualFile file = editor != null ? editor.getFile() : null; return file != null && file.isValid() ? PsiManager.getInstance(editor.getProject()).findFile(file) : null; } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) { return editor != null ? new PsiElement[] {(PsiElement) getData(CommonDataKeys.PSI_ELEMENT.getName())} : new PsiElement[] {}; } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) { return this; } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) { return copyPasteSupport.getCutProvider(); } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) { return deleteProvider; } else if (ImageComponentDecorator.DATA_KEY.is(dataId)) { return editor != null ? editor : this; } return null; }
public void actionPerformed(final AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) return; final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext()); FileAssociationsConfigurable.editAssociations(project, file); }
protected GeneralCommandLine createCommandLine() throws ExecutionException { return createFromJavaParameters( getJavaParameters(), CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()), true); }
@Override public void actionPerformed(AnActionEvent e) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); assert project != null; ProjectUtil.closeAndDispose(project); WelcomeFrame.showIfNoProjectOpened(); }
/** @return selected editor or <code>null</code> */ @Nullable private static VirtualFile getFile(final DataContext context) { Project project = CommonDataKeys.PROJECT.getData(context); if (project == null) { return null; } return CommonDataKeys.VIRTUAL_FILE.getData(context); }
public void update(final AnActionEvent e) { final FileGroupInfo fileGroupInfo = new FileGroupInfo(); myHelperAction.setFileIterationListener(fileGroupInfo); myHelperAction.update(e); myGetterStub.setDelegate(fileGroupInfo); if ((e.getPresentation().isEnabled())) { removeAll(); if (myHelperAction.allAreIgnored()) { final DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); SvnVcs vcs = SvnVcs.getInstance(project); final Ref<Boolean> filesOk = new Ref<Boolean>(Boolean.FALSE); final Ref<Boolean> extensionOk = new Ref<Boolean>(Boolean.FALSE); // virtual files parameter is not used -> can pass null SvnPropertyService.doCheckIgnoreProperty( vcs, project, null, fileGroupInfo, fileGroupInfo.getExtensionMask(), filesOk, extensionOk); if (Boolean.TRUE.equals(filesOk.get())) { myRemoveExactAction.setActionText( fileGroupInfo.oneFileSelected() ? fileGroupInfo.getFileName() : SvnBundle.message("action.Subversion.UndoIgnore.text")); add(myRemoveExactAction); } if (Boolean.TRUE.equals(extensionOk.get())) { myRemoveExtensionAction.setActionText(fileGroupInfo.getExtensionMask()); add(myRemoveExtensionAction); } e.getPresentation().setText(SvnBundle.message("group.RevertIgnoreChoicesGroup.text")); } else if (myHelperAction.allCanBeIgnored()) { final String ignoreExactlyName = (fileGroupInfo.oneFileSelected()) ? fileGroupInfo.getFileName() : SvnBundle.message("action.Subversion.Ignore.ExactMatch.text"); myAddExactAction.setActionText(ignoreExactlyName); add(myAddExactAction); if (fileGroupInfo.sameExtension()) { myAddExtensionAction.setActionText(fileGroupInfo.getExtensionMask()); add(myAddExtensionAction); } e.getPresentation().setText(SvnBundle.message("group.IgnoreChoicesGroup.text")); } } }
@Override public void run() { if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) { resetState(); final DataContext dataContext = myContext.getDataContext(); StatusBar.Info.set( null, dataContext == null ? null : CommonDataKeys.PROJECT.getData(dataContext)); } }
@Override public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project != null) { StatisticsService service = StatisticsUploadAssistant.getStatisticsService(); StatisticsResult result = service.send(); Messages.showMessageDialog(result.getDescription(), "Result", PlatformIcons.CUSTOM_FILE_ICON); } }
private static EditorWindow getEditorWindow(DataContext dataContext) { EditorWindow editorWindow = EditorWindow.DATA_KEY.getData(dataContext); if (editorWindow == null) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { editorWindow = FileEditorManagerEx.getInstanceEx(project).getCurrentWindow(); } } return editorWindow; }
public boolean processAction(final InputEvent e, @NotNull ActionProcessor processor) { ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>(); List<AnAction> actions = myContext.getActions(); for (final AnAction action : actions) { Presentation presentation = myPresentationFactory.getPresentation(action); // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard final AnActionEvent actionEvent = processor.createEvent( e, myContext.getDataContext(), ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance()); ActionUtil.performDumbAwareUpdate(action, actionEvent, true); if (dumb && !action.isDumbAware()) { if (!Boolean.FALSE.equals( presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) { nonDumbAwareAction.add(actionEvent); } continue; } if (!presentation.isEnabled()) { continue; } processor.onUpdatePassed(e, action, actionEvent); ((DataManagerImpl.MyDataContext) myContext.getDataContext()) .setEventCount(IdeEventQueue.getInstance().getEventCount(), this); actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent); Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext()); if (component != null && !component.isShowing()) { return true; } processor.performAction(e, action, actionEvent); actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent); return true; } if (!nonDumbAwareAction.isEmpty()) { showDumbModeWarningLaterIfNobodyConsumesEvent( e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()])); } return false; }
public static DebuggerContextImpl getDebuggerContext(DataContext dataContext) { DebuggerTreePanel panel = getPanel(dataContext); if (panel != null) { return panel.getContext(); } else { Project project = CommonDataKeys.PROJECT.getData(dataContext); return project != null ? (DebuggerManagerEx.getInstanceEx(project)).getContext() : DebuggerContextImpl.EMPTY_CONTEXT; } }
protected DialogWrapperPeerImpl( @NotNull DialogWrapper wrapper, @Nullable Project project, boolean canBeParent, @NotNull DialogWrapper.IdeModalityType ideModalityType) { myWrapper = wrapper; myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : null; myWindowManager = null; Application application = ApplicationManager.getApplication(); if (application != null && application.hasComponent(WindowManager.class)) { myWindowManager = (WindowManagerEx) WindowManager.getInstance(); } Window window = null; if (myWindowManager != null) { if (project == null) { //noinspection deprecation project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); } myProject = project; window = myWindowManager.suggestParentWindow(project); if (window == null) { Window focusedWindow = myWindowManager.getMostRecentFocusedWindow(); if (focusedWindow instanceof IdeFrameImpl) { window = focusedWindow; } } if (window == null) { IdeFrame[] frames = myWindowManager.getAllProjectFrames(); for (IdeFrame frame : frames) { if (frame instanceof IdeFrameImpl && ((IdeFrameImpl) frame).isActive()) { window = (IdeFrameImpl) frame; break; } } } } Window owner; if (window != null) { owner = window; } else { if (!isHeadless()) { owner = JOptionPane.getRootFrame(); } else { owner = null; } } createDialog(owner, canBeParent, ideModalityType); }
@RequiredDispatchThread @Override public void update(@NotNull AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); if (project == null || project.isDisposed()) { presentation.setEnabled(false); return; } presentation.setEnabled(IdeDocumentHistory.getInstance(project).isBackAvailable()); }
public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { presentation.setEnabled(false); return; } DebuggerSession debuggerSession = (DebuggerManagerEx.getInstanceEx(project)).getContext().getDebuggerSession(); presentation.setEnabled(debuggerSession != null && debuggerSession.isAttached()); }
@Override public PsiElement getTarget(@NotNull DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return null; PsiElement element = getCurrentElement(dataContext, project); if (element == null) return null; element = HierarchyUtils.getCallHierarchyElement(element); if (element instanceof KtFile) return null; return element; }
public PsiElement getTarget(@NotNull final DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return null; final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (LOG.isDebugEnabled()) { LOG.debug("editor " + editor); } if (editor != null) { final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) return null; final PsiElement targetElement = TargetElementUtilBase.findTargetElement( editor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.LOOKUP_ITEM_ACCEPTED); if (LOG.isDebugEnabled()) { LOG.debug("target element " + targetElement); } if (targetElement instanceof PsiClass) { return targetElement; } final int offset = editor.getCaretModel().getOffset(); PsiElement element = file.findElementAt(offset); while (element != null) { if (LOG.isDebugEnabled()) { LOG.debug("context element " + element); } if (element instanceof PsiFile) { if (!(element instanceof PsiClassOwner)) return null; final PsiClass[] classes = ((PsiClassOwner) element).getClasses(); return classes.length == 1 ? classes[0] : null; } if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass) && !(element instanceof PsiSyntheticClass)) { return element; } element = element.getParent(); } return null; } else { final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); return element instanceof PsiClass ? (PsiClass) element : null; } }
@Override public void actionPerformed(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); LOG.assertTrue(project != null); final T configuration = (T) RunConfiguration.DATA_KEY.getData(dataContext); LOG.assertTrue(configuration != null); final GlobalSearchScope searchScope = configuration.getConfigurationModule().getSearchScope(); final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext); LOG.assertTrue(testProxy != null); final String qualifiedName = ((PsiClass) testProxy.getLocation(project, searchScope).getPsiElement()).getQualifiedName(); getPattern(configuration).remove(qualifiedName); }
@Override public void execute(Editor editor, DataContext dataContext) { Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } PsiFile psiFile = LangDataKeys.PSI_FILE.getData(dataContext); if (psiFile == null) { return; } process(psiFile, editor, project, editor.getCaretModel().getOffset()); }
private boolean inSecondStrokeInProgressState() { KeyEvent e = myContext.getInputEvent(); // when any key is released, we stop waiting for the second stroke if (KeyEvent.KEY_RELEASED == e.getID()) { myFirstKeyStroke = null; setState(KeyState.STATE_INIT); Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); StatusBar.Info.set(null, project); return false; } KeyStroke originalKeyStroke = KeyStroke.getKeyStrokeForEvent(e); KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke); updateCurrentContext( myContext.getFoundComponent(), new KeyboardShortcut(myFirstKeyStroke, keyStroke), myContext.isModalContext()); // consume the wrong second stroke and keep on waiting if (myContext.getActions().isEmpty()) { return true; } // finally user had managed to enter the second keystroke, so let it be processed Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); StatusBarEx statusBar = (StatusBarEx) WindowManager.getInstance().getStatusBar(project); if (processAction(e, myActionProcessor)) { if (statusBar != null) { statusBar.setInfo(null); } return true; } else { return false; } }
@Override public Object getData(@NonNls String dataId) { if (CommonDataKeys.PROJECT.is(dataId)) { return myModel.getProject(); } else if (DIR_DIFF_MODEL.is(dataId)) { return myModel; } else if (DIR_DIFF_TABLE.is(dataId)) { return myTable; } else if (DiffDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { return getNavigatableArray(); } else if (DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE.is(dataId)) { return myPrevNextDifferenceIterable; } return null; }
public void actionPerformed(AnActionEvent e) { final DataContext dc = e.getDataContext(); if ((!isVisible(dc)) || (!isEnabled(dc))) return; final Project project = CommonDataKeys.PROJECT.getData(dc); final Iterable<Pair<VirtualFilePointer, FileStatus>> iterable = e.getRequiredData(VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE); final Label before = (Label) e.getRequiredData(VcsDataKeys.LABEL_BEFORE); final Label after = (Label) e.getRequiredData(VcsDataKeys.LABEL_AFTER); final String selectedUrl = VcsDataKeys.UPDATE_VIEW_SELECTED_PATH.getData(dc); MyDiffRequestChain requestChain = new MyDiffRequestChain(project, iterable, before, after, selectedUrl); DiffManager.getInstance().showDiff(project, requestChain, DiffDialogHints.FRAME); }