com.intellij.psi.util.PsiElementFilter#com.intellij.openapi.actionSystem.CommonDataKeys源码实例Demo

下面列出了com.intellij.psi.util.PsiElementFilter#com.intellij.openapi.actionSystem.CommonDataKeys 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Intellij-Plugin   文件: CustomRenameHandler.java
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();
}
 
源代码2 项目: consulo   文件: ToggleDockModeAction.java
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);
  }
}
 
源代码3 项目: consulo   文件: ChooseRunConfigurationPopup.java
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);
      }
    });
  }
}
 
源代码4 项目: litho   文件: ResolveRedSymbolsAction.java
@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);
      });
}
 
源代码5 项目: SlackStorm   文件: SlackSettings.java
@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());
        }
    }
}
 
源代码6 项目: consulo   文件: MacroManager.java
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());
}
 
源代码7 项目: consulo   文件: UnshelveWithDialogAction.java
@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();
}
 
源代码8 项目: consulo   文件: NavBarUpdateQueue.java
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);
  }
}
 
源代码9 项目: consulo   文件: CloseAllEditorsAction.java
@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);
}
 
源代码10 项目: consulo   文件: QuickEvaluateAction.java
@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;
}
 
源代码11 项目: RIBs   文件: GenerateAction.java
/**
 * 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;
}
 
源代码12 项目: consulo   文件: ColorAndFontOptions.java
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;
}
 
源代码13 项目: consulo   文件: BaseToolWindowToggleAction.java
@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);
}
 
@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);
}
 
源代码15 项目: consulo   文件: FileTextRule.java
@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();
}
 
源代码16 项目: flutter-intellij   文件: OpenAndroidModule.java
@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);
}
 
源代码17 项目: consulo   文件: TextEndAction.java
@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();
    }
  }
}
 
源代码18 项目: consulo   文件: TextEditorComponent.java
@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;
}
 
源代码19 项目: consulo   文件: ToggleBookmarkAction.java
@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"));
}
 
源代码20 项目: consulo   文件: ExternalActionUtil.java
@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);
}
 
源代码21 项目: consulo   文件: RollbackDialogAction.java
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");
  }

}
 
源代码22 项目: consulo   文件: AbstractPopup.java
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);
    }
  }
}
 
源代码23 项目: consulo   文件: LossyEncodingInspection.java
@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);
}
 
源代码24 项目: consulo   文件: AbstractMemberSelectionTable.java
@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());
    }
  }
}
 
@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);
}
 
源代码26 项目: consulo   文件: BaseIndentEnterHandler.java
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;
}
 
源代码27 项目: LayoutMaster   文件: ActionKit.java
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);
}
 
源代码28 项目: intellij   文件: OpenCorrespondingBuildFile.java
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
  VirtualFile vf = e.getData(CommonDataKeys.VIRTUAL_FILE);
  if (vf == null) {
    return;
  }
  navigateToTargetOrFile(project, vf);
}
 
源代码29 项目: consulo   文件: TextComponentEditorAction.java
@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;
}
 
源代码30 项目: consulo   文件: CheckForUpdateAction.java
@Override
@RequiredUIAccess
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);

  actionPerformed(project, consulo.ide.updateSettings.UpdateSettings.getInstance());
}