Search in sources :

Example 1 with SelectInContext

use of com.intellij.ide.SelectInContext in project intellij-community by JetBrains.

the class SelectInContextImpl method createContext.

@Nullable
public static SelectInContext createContext(AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    SelectInContext result = createEditorContext(dataContext);
    if (result != null) {
        return result;
    }
    JComponent sourceComponent = getEventComponent(event);
    if (sourceComponent == null) {
        return null;
    }
    SelectInContext selectInContext = SelectInContext.DATA_KEY.getData(dataContext);
    if (selectInContext == null) {
        selectInContext = createPsiContext(event);
    }
    if (selectInContext == null) {
        Navigatable descriptor = CommonDataKeys.NAVIGATABLE.getData(dataContext);
        if (descriptor instanceof OpenFileDescriptor) {
            final VirtualFile file = ((OpenFileDescriptor) descriptor).getFile();
            if (file.isValid()) {
                Project project = CommonDataKeys.PROJECT.getData(dataContext);
                selectInContext = OpenFileDescriptorContext.create(project, file);
            }
        }
    }
    if (selectInContext == null) {
        VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
        Project project = CommonDataKeys.PROJECT.getData(dataContext);
        if (virtualFile != null && project != null) {
            return new VirtualFileSelectInContext(project, virtualFile);
        }
    }
    return selectInContext;
}
Also used : SelectInContext(com.intellij.ide.SelectInContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SelectInContext

use of com.intellij.ide.SelectInContext in project intellij-community by JetBrains.

the class SelectInProjectViewAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ProjectPaneSelectInTarget target = new ProjectPaneSelectInTarget(e.getProject());
    final SelectInContext context = SelectInContextImpl.createContext(e);
    if (context != null) {
        target.selectIn(context, true);
    }
}
Also used : SelectInContext(com.intellij.ide.SelectInContext) ProjectPaneSelectInTarget(com.intellij.ide.impl.ProjectPaneSelectInTarget)

Example 3 with SelectInContext

use of com.intellij.ide.SelectInContext in project intellij-community by JetBrains.

the class SelectInProjectViewAction method update.

@Override
public void update(AnActionEvent e) {
    final Project project = e.getProject();
    if (project != null) {
        final ProjectPaneSelectInTarget target = new ProjectPaneSelectInTarget(project);
        final SelectInContext context = SelectInContextImpl.createContext(e);
        if (context != null && target.canSelect(context)) {
            e.getPresentation().setEnabled(true);
            return;
        }
    }
    e.getPresentation().setEnabled(false);
}
Also used : SelectInContext(com.intellij.ide.SelectInContext) Project(com.intellij.openapi.project.Project) ProjectPaneSelectInTarget(com.intellij.ide.impl.ProjectPaneSelectInTarget)

Aggregations

SelectInContext (com.intellij.ide.SelectInContext)3 ProjectPaneSelectInTarget (com.intellij.ide.impl.ProjectPaneSelectInTarget)2 Project (com.intellij.openapi.project.Project)2 DataContext (com.intellij.openapi.actionSystem.DataContext)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Navigatable (com.intellij.pom.Navigatable)1 Nullable (org.jetbrains.annotations.Nullable)1