Search in sources :

Example 1 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project buck by facebook.

the class BuckToolWindowFactory method handleClickOnError.

private void handleClickOnError(BuckTreeNodeDetailError node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckTreeNodeFileError) {
        BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);
        String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
        openFileDescriptor.navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeNode(javax.swing.tree.TreeNode) BuckTreeNodeFileError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeFileError) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 2 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class PyTestCase method createRunConfigurationFromContext.

/**
   * Creates run configuration from right click menu
   *
   * @param fixture       test fixture
   * @param expectedClass expected class of run configuration
   * @param <C>           expected class of run configuration
   * @return configuration (if created) or null (otherwise)
   */
@Nullable
public static <C extends RunConfiguration> C createRunConfigurationFromContext(@NotNull final CodeInsightTestFixture fixture, @NotNull final Class<C> expectedClass) {
    final DataContext context = DataManager.getInstance().getDataContext(fixture.getEditor().getComponent());
    for (final RunConfigurationProducer<?> producer : RunConfigurationProducer.EP_NAME.getExtensions()) {
        final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(context));
        if (fromContext == null) {
            continue;
        }
        final C result = PyUtil.as(fromContext.getConfiguration(), expectedClass);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class HgAbstractGlobalAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    final HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
    List<HgRepository> repositories = repositoryManager.getRepositories();
    if (!repositories.isEmpty()) {
        List<HgRepository> selectedRepositories = files != null ? HgActionUtil.collectRepositoriesFromFiles(repositoryManager, Arrays.asList(files)) : ContainerUtil.<HgRepository>emptyList();
        execute(project, repositories, selectedRepositories.isEmpty() ? Collections.singletonList(HgUtil.getCurrentRepository(project)) : selectedRepositories);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 4 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class HgActionUtil method getSelectedRepositoryFromEvent.

@Nullable
@CalledInAwt
public static HgRepository getSelectedRepositoryFromEvent(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return null;
    }
    VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
    return file != null ? repositoryManager.getRepositoryForFileQuick(file) : HgUtil.getCurrentRepository(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class IgnoreActionGroup method update.

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.FALSE);
            final Ref<Boolean> extensionOk = new Ref<>(Boolean.FALSE);
            // virtual files parameter is not used -> can pass null
            SvnPropertyService.doCheckIgnoreProperty(vcs, 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"));
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Ref(com.intellij.openapi.util.Ref) FileGroupInfo(org.jetbrains.idea.svn.ignore.FileGroupInfo) SvnVcs(org.jetbrains.idea.svn.SvnVcs)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)202 Project (com.intellij.openapi.project.Project)71 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)21 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)16 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 DataManager (com.intellij.ide.DataManager)9 Presentation (com.intellij.openapi.actionSystem.Presentation)9 List (java.util.List)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6