com.intellij.openapi.actionSystem.CommonDataKeys Java Examples
The following examples show how to use
com.intellij.openapi.actionSystem.CommonDataKeys.
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: CustomRenameHandler.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (element == null) element = psiElement; psiElement = element; String text = element.toString(); //Finding text from annotation if (isMethod(element)) { List<String> values = StepUtil.getGaugeStepAnnotationValues((PsiMethod) element); if (values.size() == 0) { return; } else if (values.size() == 1) text = values.get(0); else if (values.size() > 1) { Messages.showWarningDialog("Refactoring for steps having aliases are not supported", "Warning"); return; } } else if (isStep(element)) { text = ((SpecStepImpl) element).getStepValue().getStepAnnotationText(); } else if (isConcept(element)) { text = removeIdentifiers(((ConceptStepImpl) element).getStepValue().getStepAnnotationText()); } final RefactoringDialog form = new RefactoringDialog(this.editor.getProject(), file, this.editor, text); form.show(); }
Example #2
Source File: ToggleDockModeAction.java From consulo with Apache License 2.0 | 6 votes |
public void setSelected(AnActionEvent event, boolean flag) { Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { return; } ToolWindowManager windowManager = ToolWindowManager.getInstance(project); String id = windowManager.getActiveToolWindowId(); if (id == null) { return; } ToolWindow toolWindow = windowManager.getToolWindow(id); ToolWindowType type = toolWindow.getType(); if (ToolWindowType.DOCKED == type) { toolWindow.setType(ToolWindowType.SLIDING, null); } else if (ToolWindowType.SLIDING == type) { toolWindow.setType(ToolWindowType.DOCKED, null); } }
Example #3
Source File: ChooseRunConfigurationPopup.java From consulo with Apache License 2.0 | 6 votes |
static void execute(final ItemWrapper itemWrapper, final Executor executor) { if (executor == null) { return; } final DataContext dataContext = DataManager.getInstance().getDataContext(); final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { itemWrapper.perform(project, executor, dataContext); } }); } }
Example #4
Source File: ResolveRedSymbolsAction.java From litho with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { // Verified nonNull in #update final Project project = e.getProject(); final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); final PsiJavaFile psiFile = (PsiJavaFile) e.getData(CommonDataKeys.PSI_FILE); final Editor editor = e.getData(CommonDataKeys.EDITOR); Map<String, String> eventMetadata = new HashMap<>(); resolveRedSymbols( psiFile, virtualFile, editor, project, eventMetadata, finished -> { eventMetadata.put(EventLogger.KEY_TYPE, "action"); eventMetadata.put(EventLogger.KEY_RESULT, finished ? "success" : "fail"); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_RED_SYMBOLS, eventMetadata); }); }
Example #5
Source File: SlackSettings.java From SlackStorm with GNU General Public License v2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); List<String> channelsId = SlackStorage.getInstance().getChannelsId(); if (channelsId.size() > 0) { String channelToRemove = Messages.showEditableChooseDialog( "Select the channel to remove", SlackChannel.getSettingsDescription(), SlackStorage.getSlackIcon(), channelsId.toArray(new String[channelsId.size()]), channelsId.get(0), null ); if (channelsId.contains(channelToRemove)) { SlackStorage.getInstance().removeChannelByDescription(channelToRemove); Messages.showMessageDialog(project, "Channel \"" + channelToRemove + "\" removed.", "Information", Messages.getInformationIcon()); } } }
Example #6
Source File: MacroManager.java From consulo with Apache License 2.0 | 6 votes |
private static DataContext getCorrectContext(DataContext dataContext) { if (dataContext.getData(PlatformDataKeys.FILE_EDITOR) != null) { return dataContext; } Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return dataContext; } FileEditorManager editorManager = FileEditorManager.getInstance(project); VirtualFile[] files = editorManager.getSelectedFiles(); if (files.length == 0) { return dataContext; } FileEditor fileEditor = editorManager.getSelectedEditor(files[0]); return fileEditor == null ? dataContext : DataManager.getInstance().getDataContext(fileEditor.getComponent()); }
Example #7
Source File: UnshelveWithDialogAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final ShelvedChangeList[] changeLists = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY); if (project == null || changeLists == null || changeLists.length != 1) return; FileDocumentManager.getInstance().saveAllDocuments(); final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(changeLists[0].PATH)); if (virtualFile == null) { VcsBalloonProblemNotifier.showOverChangesView(project, "Can not find path file", MessageType.ERROR); return; } if (! changeLists[0].getBinaryFiles().isEmpty()) { VcsBalloonProblemNotifier.showOverChangesView(project, "Binary file(s) would be skipped.", MessageType.WARNING); } final ApplyPatchDifferentiatedDialog dialog = new ApplyPatchDifferentiatedDialog(project, new ApplyPatchDefaultExecutor(project), Collections.<ApplyPatchExecutor>emptyList(), ApplyPatchMode.UNSHELVE, virtualFile); dialog.setHelpId("reference.dialogs.vcs.unshelve"); dialog.show(); }
Example #8
Source File: NavBarUpdateQueue.java From consulo with Apache License 2.0 | 6 votes |
private void requestModelUpdateFromContextOrObject(DataContext dataContext, Object object) { try { final NavBarModel model = myPanel.getModel(); if (dataContext != null) { if (dataContext.getData(CommonDataKeys.PROJECT) != myPanel.getProject() || myPanel.isNodePopupActive()) { requestModelUpdate(null, myPanel.getContextObject(), true); return; } final Window window = SwingUtilities.getWindowAncestor(myPanel); if (window != null && !window.isFocused()) { model.updateModel(DataManager.getInstance().getDataContext(myPanel)); } else { model.updateModel(dataContext); } } else { model.updateModel(object); } queueRebuildUi(); } finally { myModelUpdating.set(false); } }
Example #9
Source File: CloseAllEditorsAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); final EditorWindow editorWindow = event.getData(EditorWindow.DATA_KEY); if (editorWindow != null && editorWindow.inSplitter()) { presentation.setText(IdeBundle.message("action.close.all.editors.in.tab.group")); } else { presentation.setText(IdeBundle.message("action.close.all.editors")); } Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setEnabled(false); return; } presentation.setEnabled(FileEditorManager.getInstance(project).getSelectedFiles().length > 0); }
Example #10
Source File: QuickEvaluateAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean isEnabled(@Nonnull final Project project, final AnActionEvent event) { if (!myHandler.isEnabled(project)) { return false; } Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor == null) { return false; } if (event.getData(EditorGutter.KEY) != null) { return false; } return true; }
Example #11
Source File: GenerateAction.java From RIBs with Apache License 2.0 | 6 votes |
/** * Checked whether or not this action can be enabled. * <p> * <p>Requirements to be enabled: * User must be in a Java source folder. * * @param dataContext to figure out where the user is. * @return {@code true} when the action is available, {@code false} when the action is not * available. */ private boolean isAvailable(DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return false; } final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null || view.getDirectories().length == 0) { return false; } ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiDirectory dir : view.getDirectories()) { if (projectFileIndex.isUnderSourceRootOfType( dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && checkPackageExists(dir)) { return true; } } return false; }
Example #12
Source File: ColorAndFontOptions.java From consulo with Apache License 2.0 | 6 votes |
private static boolean edit(DataContext context, String search, Function<ColorAndFontOptions, SearchableConfigurable> function) { ColorAndFontOptions options = new ColorAndFontOptions(); SearchableConfigurable page = function.apply(options); Configurable[] configurables = options.getConfigurables(); try { if (page != null) { Runnable runnable = search == null ? null : page.enableSearch(search); Window window = UIUtil.getWindow(context.getData(PlatformDataKeys.CONTEXT_COMPONENT)); if (window != null) { ShowSettingsUtil.getInstance().editConfigurable(window, page, runnable); } else { ShowSettingsUtil.getInstance().editConfigurable(context.getData(CommonDataKeys.PROJECT), page, runnable); } } } finally { for (Configurable configurable : configurables) configurable.disposeUIResources(); options.disposeUIResources(); } return page != null; }
Example #13
Source File: BaseToolWindowToggleAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public final void setSelected(AnActionEvent e, boolean state) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { return; } String id = ToolWindowManager.getInstance(project).getActiveToolWindowId(); if (id == null) { return; } ToolWindowManagerEx mgr = ToolWindowManagerEx.getInstanceEx(project); ToolWindowEx toolWindow = (ToolWindowEx)mgr.getToolWindow(id); setSelected(toolWindow, state); }
Example #14
Source File: OpenCommitInBrowserAction.java From azure-devops-intellij with MIT License | 6 votes |
@Override public void actionPerformed(@NotNull final AnActionEvent anActionEvent) { final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT); final VcsFullCommitDetails commit = anActionEvent.getRequiredData(VcsLogDataKeys.VCS_LOG).getSelectedDetails().get(0); final GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForRootQuick(commit.getRoot()); if (gitRepository == null) return; final GitRemote remote = TfGitHelper.getTfGitRemote(gitRepository); // guard for null so findbugs doesn't complain if (remote == null) { return; } final String remoteUrl = remote.getFirstUrl(); if (remoteUrl == null) { return; } final URI urlToBrowseTo = UrlHelper.getCommitURI(remoteUrl, commit.getId().toString()); logger.info("Browsing to url " + urlToBrowseTo.getPath()); BrowserUtil.browse(urlToBrowseTo); }
Example #15
Source File: FileTextRule.java From consulo with Apache License 2.0 | 6 votes |
@Override public String getData(@Nonnull DataProvider dataProvider) { final VirtualFile virtualFile = dataProvider.getDataUnchecked(PlatformDataKeys.VIRTUAL_FILE); if (virtualFile == null) { return null; } final FileType fileType = virtualFile.getFileType(); if (fileType.isBinary() || fileType.isReadOnly()) { return null; } final Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project == null) { return null; } final Document document = FileDocumentManager.getInstance().getDocument(virtualFile); if (document == null) { return null; } return document.getText(); }
Example #16
Source File: OpenAndroidModule.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { final VirtualFile projectFile = findProjectFile(e); if (projectFile == null) { FlutterMessages.showError("Error Opening Android Studio", "Project not found."); return; } final int modifiers = e.getModifiers(); // From ReopenProjectAction. final boolean forceOpenInNewFrame = BitUtil.isSet(modifiers, InputEvent.CTRL_MASK) || BitUtil.isSet(modifiers, InputEvent.SHIFT_MASK) || e.getPlace() == ActionPlaces.WELCOME_SCREEN; VirtualFile sourceFile = e.getData(CommonDataKeys.VIRTUAL_FILE); // Using: //ProjectUtil.openOrImport(projectFile.getPath(), e.getProject(), forceOpenInNewFrame); // presents the user with a really imposing Gradle project import dialog. openOrImportProject(projectFile, e.getProject(), sourceFile, forceOpenInNewFrame); }
Example #17
Source File: TextEndAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void execute(Editor editor, DataContext dataContext) { editor.getCaretModel().removeSecondaryCarets(); int offset = editor.getDocument().getTextLength(); if (editor instanceof DesktopEditorImpl) { editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true)); } else { editor.getCaretModel().moveToOffset(offset); } editor.getSelectionModel().removeSelection(); ScrollingModel scrollingModel = editor.getScrollingModel(); scrollingModel.disableAnimation(); scrollingModel.scrollToCaret(ScrollType.CENTER); scrollingModel.enableAnimation(); Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project != null) { IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project); if (instance != null) { instance.includeCurrentCommandAsNavigation(); } } }
Example #18
Source File: TextEditorComponent.java From consulo with Apache License 2.0 | 6 votes |
@Override public Object getData(@Nonnull final Key<?> dataId) { final Editor e = validateCurrentEditor(); if (e == null || e.isDisposed()) return null; // There's no FileEditorManager for default project (which is used in diff command-line application) if (!myProject.isDisposed() && !myProject.isDefault()) { final Object o = FileEditorManager.getInstance(myProject).getData(dataId, e, e.getCaretModel().getCurrentCaret()); if (o != null) return o; } if (CommonDataKeys.EDITOR == dataId) { return e; } if (CommonDataKeys.VIRTUAL_FILE == dataId) { return myFile.isValid() ? myFile : null; // fix for SCR 40329 } return null; }
Example #19
Source File: ToggleBookmarkAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent event) { DataContext dataContext = event.getDataContext(); final Project project = dataContext.getData(CommonDataKeys.PROJECT); event.getPresentation().setEnabled(project != null && (ToolWindowManager.getInstance(project).isEditorComponentActive() && dataContext.getData(PlatformDataKeys.EDITOR) != null || dataContext.getData(PlatformDataKeys.VIRTUAL_FILE) != null)); event.getPresentation().setText(IdeBundle.message("action.bookmark.toggle")); }
Example #20
Source File: ExternalActionUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static MyInfo getProcessingInfo(@Nonnull DataContext context) { ExternalProjectPojo externalProject = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT); if (externalProject == null) { return MyInfo.EMPTY; } ProjectSystemId externalSystemId = context.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID); if (externalSystemId == null) { return MyInfo.EMPTY; } Project ideProject = context.getData(CommonDataKeys.PROJECT); if (ideProject == null) { return MyInfo.EMPTY; } AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId); ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath()); AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId); return new MyInfo(externalProjectSettings == null ? null : settings, localSettings == null ? null : localSettings, externalProjectSettings == null ? null : externalProject, ideProject, externalSystemId); }
Example #21
Source File: RollbackDialogAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(AnActionEvent e) { Change[] changes = e.getData(VcsDataKeys.CHANGES); Project project = e.getData(CommonDataKeys.PROJECT); boolean enabled = changes != null && project != null; e.getPresentation().setEnabled(enabled); if (enabled) { String operationName = RollbackUtil.getRollbackOperationName(project); e.getPresentation().setText(operationName); e.getPresentation().setDescription(operationName + " selected changes"); } }
Example #22
Source File: AbstractPopup.java From consulo with Apache License 2.0 | 5 votes |
private void installProjectDisposer() { final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (c != null) { final DataContext context = DataManager.getInstance().getDataContext(c); final Project project = context.getData(CommonDataKeys.PROJECT); if (project != null) { myProjectDisposable = () -> { if (!isDisposed()) { Disposer.dispose(this); } }; Disposer.register(project, myProjectDisposable); } } }
Example #23
Source File: LossyEncodingInspection.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static DataContext createDataContext(Editor editor, Component component, VirtualFile selectedFile, Project project) { DataContext parent = DataManager.getInstance().getDataContext(component); DataContext context = SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT, editor == null ? null : editor.getComponent(), parent); DataContext projectContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT, project, context); return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE, selectedFile, projectContext); }
Example #24
Source File: AbstractMemberSelectionTable.java From consulo with Apache License 2.0 | 5 votes |
@Override public void calcData(final Key key, final DataSink sink) { if (key == CommonDataKeys.PSI_ELEMENT) { final Collection<M> memberInfos = getSelectedMemberInfos(); if (memberInfos.size() > 0) { sink.put(CommonDataKeys.PSI_ELEMENT, memberInfos.iterator().next().getMember()); } } }
Example #25
Source File: OpenCommitInBrowserAction.java From azure-devops-intellij with MIT License | 5 votes |
@Override public void update(@NotNull final AnActionEvent anActionEvent) { final Presentation presentation = anActionEvent.getPresentation(); final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); final VcsLog log = anActionEvent.getData(VcsLogDataKeys.VCS_LOG); if (project == null || project.isDisposed() || log == null) { presentation.setEnabledAndVisible(false); return; } final List<VcsFullCommitDetails> commits = log.getSelectedDetails(); if (commits.size() == 0) { presentation.setEnabledAndVisible(false); return; } final VcsFullCommitDetails commit = commits.get(0); final GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRootQuick(commit.getRoot()); if (repository == null || !TfGitHelper.isTfGitRepository(repository)) { presentation.setEnabledAndVisible(false); return; } else if (commits.size() > 1) { // only one for now, leave it visible as a breadcrumb presentation.setVisible(true); presentation.setEnabled(false); return; } presentation.setEnabledAndVisible(true); }
Example #26
Source File: BaseIndentEnterHandler.java From consulo with Apache License 2.0 | 5 votes |
protected Result shouldSkipWithResult(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final DataContext dataContext) { final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return Result.Continue; } if (!file.getViewProvider().getLanguages().contains(myLanguage)) { return Result.Continue; } if (editor.isViewer()) { return Result.Continue; } final Document document = editor.getDocument(); if (!document.isWritable()) { return Result.Continue; } PsiDocumentManager.getInstance(project).commitDocument(document); int caret = editor.getCaretModel().getOffset(); if (caret == 0) { return Result.DefaultSkipIndent; } if (caret <= 0) { return Result.Continue; } return null; }
Example #27
Source File: ActionKit.java From LayoutMaster with Apache License 2.0 | 5 votes |
public static PsiFile getCurrentEditFile(AnActionEvent anActionEvent) { PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE); if (psiFile != null) { return psiFile; } Project project = anActionEvent.getProject(); Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE); if (editor == null || project == null) { return null; } return PsiUtilBase.getPsiFileInEditor(editor, project); }
Example #28
Source File: OpenCorrespondingBuildFile.java From intellij with Apache License 2.0 | 5 votes |
@Override protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) { VirtualFile vf = e.getData(CommonDataKeys.VIRTUAL_FILE); if (vf == null) { return; } navigateToTargetOrFile(project, vf); }
Example #29
Source File: TextComponentEditorAction.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static Editor getEditorFromContext(@Nonnull DataContext dataContext) { final Editor editor = dataContext.getData(CommonDataKeys.EDITOR); if (editor != null) return editor; final Object data = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT); if (data instanceof JTextComponent) { return new TextComponentEditorImpl(dataContext.getData(CommonDataKeys.PROJECT), (JTextComponent) data); } return null; }
Example #30
Source File: CheckForUpdateAction.java From consulo with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); actionPerformed(project, consulo.ide.updateSettings.UpdateSettings.getInstance()); }