Example usage for com.intellij.openapi.actionSystem PlatformDataKeys CUT_PROVIDER

List of usage examples for com.intellij.openapi.actionSystem PlatformDataKeys CUT_PROVIDER

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem PlatformDataKeys CUT_PROVIDER.

Prototype

DataKey CUT_PROVIDER

To view the source code for com.intellij.openapi.actionSystem PlatformDataKeys CUT_PROVIDER.

Click Source Link

Usage

From source file:com.android.tools.idea.uibuilder.palette.NlOldPalettePanel.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return new ActionHandler();
    }//w w  w.ja va 2  s .c o m
    return null;
}

From source file:com.android.tools.idea.uibuilder.property.NlPropertiesPanel.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return this;
    }//from www .  ja v a2 s.  c  o  m
    return null;
}

From source file:com.android.tools.idea.uibuilder.surface.DesignSurface.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
        return myFileEditorDelegate.get();
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return new DesignSurfaceActionHandler(this);
    }// www.  j av  a  2  s. co  m
    return null;
}

From source file:com.intellij.ide.actions.CutAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    CutProvider provider = PlatformDataKeys.CUT_PROVIDER.getData(dataContext);
    if (provider == null) {
        return;//w ww. jav a  2s. co  m
    }
    provider.performCut(dataContext);
}

From source file:com.intellij.ide.actions.CutAction.java

License:Apache License

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    CutProvider provider = PlatformDataKeys.CUT_PROVIDER.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    presentation.setEnabled(/*from   w  ww.j av a2s. com*/
            project != null && project.isOpen() && provider != null && provider.isCutEnabled(dataContext));
    if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) {
        presentation.setVisible(provider.isCutVisible(dataContext));
    } else {
        presentation.setVisible(true);
    }
}

From source file:com.intellij.ide.commander.CommanderPanel.java

License:Apache License

public final Object getDataImpl(final String dataId) {
    if (myBuilder == null)
        return null;
    final Object selectedValue = getSelectedValue();
    if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement selectedElement = getSelectedElement();
        return selectedElement != null && selectedElement.isValid() ? selectedElement : null;
    }/*from w ww.  j av  a  2  s. c  o  m*/
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return filterInvalidElements(getSelectedElements());
    }
    if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
        final AbstractTreeNode parentNode = myBuilder.getParentNode();
        final Object element = parentNode != null ? parentNode.getValue() : null;
        return element instanceof PsiElement && ((PsiElement) element).isValid() ? element : null;
    }
    if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        return getNavigatables();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCopyProvider() : null;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCutProvider() : null;
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getPasteProvider() : null;
    }
    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return myDeleteElementProvider;
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        return selectedValue instanceof Module ? selectedValue : null;
    }
    if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof ModuleGroup ? new ModuleGroup[] { (ModuleGroup) selectedValue } : null;
    }
    if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof LibraryGroupElement
                ? new LibraryGroupElement[] { (LibraryGroupElement) selectedValue }
                : null;
    }
    if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof NamedLibraryElement
                ? new NamedLibraryElement[] { (NamedLibraryElement) selectedValue }
                : null;
    }

    if (myProjectTreeStructure != null) {
        return myProjectTreeStructure.getDataFromProviders(getSelectedNodes(), dataId);
    }

    return null;
}

From source file:com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel.java

License:Apache License

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
    }/*from  w  ww  .j  a v a  2  s  .c o  m*/
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        final FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil
                .getSelectedNodeDescriptors(myTree);
        return selectedNodeDescriptors.length == 1 ? selectedNodeDescriptors[0].getElement() : null;
    }
    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        final List<Navigatable> selectedElements = getSelectedElements(Navigatable.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new Navigatable[selectedElements.size()]);
    }

    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return "reference.toolWindows.favorites";
    }
    if (LangDataKeys.NO_NEW_ACTION.is(dataId)) {
        return Boolean.TRUE;
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        PsiElement[] elements = getSelectedPsiElements();
        if (elements.length != 1) {
            return null;
        }
        return elements[0] != null && elements[0].isValid() ? elements[0] : null;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        final PsiElement[] elements = getSelectedPsiElements();
        ArrayList<PsiElement> result = new ArrayList<PsiElement>();
        for (PsiElement element : elements) {
            if (element.isValid()) {
                result.add(element);
            }
        }
        return result.isEmpty() ? null : PsiUtilCore.toPsiElementArray(result);
    }

    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }

    if (LangDataKeys.TARGET_PSI_ELEMENT.is(dataId)) {
        return null;
    }

    if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
        Module[] selected = getSelectedModules();
        return selected != null && selected.length == 1 ? selected[0] : null;
    }
    if (LangDataKeys.MODULE_CONTEXT_ARRAY.is(dataId)) {
        return getSelectedModules();
    }

    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        final Object[] elements = getSelectedNodeElements();
        return elements != null && elements.length >= 1 && elements[0] instanceof Module
                ? myDeleteModuleProvider
                : myDeletePSIElementProvider;
    }
    if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
        final List<ModuleGroup> selectedElements = getSelectedElements(ModuleGroup.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new ModuleGroup[selectedElements.size()]);
    }
    if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
        final List<LibraryGroupElement> selectedElements = getSelectedElements(LibraryGroupElement.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new LibraryGroupElement[selectedElements.size()]);
    }
    if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
        final List<NamedLibraryElement> selectedElements = getSelectedElements(NamedLibraryElement.class);
        return selectedElements.isEmpty() ? null
                : selectedElements.toArray(new NamedLibraryElement[selectedElements.size()]);
    }
    if (CONTEXT_FAVORITES_ROOTS_DATA_KEY.is(dataId)) {
        List<FavoritesTreeNodeDescriptor> result = new ArrayList<FavoritesTreeNodeDescriptor>();
        FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil
                .getSelectedNodeDescriptors(myTree);
        for (FavoritesTreeNodeDescriptor selectedNodeDescriptor : selectedNodeDescriptors) {
            if (FavoritesTreeUtil.getProvider(myFavoritesManager, selectedNodeDescriptor) != null) {
                continue;
            }
            FavoritesTreeNodeDescriptor root = selectedNodeDescriptor.getFavoritesRoot();
            if (root != null && root.getElement() instanceof FavoritesListNode) {
                result.add(selectedNodeDescriptor);
            }
        }
        return result.toArray(new FavoritesTreeNodeDescriptor[result.size()]);
    }
    if (FAVORITES_TREE_KEY.is(dataId)) {
        return myTree;
    }
    if (FAVORITES_TREE_BUILDER_KEY.is(dataId)) {
        return myBuilder;
    }
    if (FAVORITES_LIST_NAME_DATA_KEY.is(dataId)) {
        final FavoritesTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
        Set<String> selectedNames = new HashSet<String>();
        for (FavoritesTreeNodeDescriptor descriptor : descriptors) {
            FavoritesListNode node = FavoritesTreeUtil.extractParentList(descriptor);
            if (node != null) {
                selectedNames.add(node.getValue());
            }
        }

        if (selectedNames.size() == 1) {
            return selectedNames.iterator().next();
        }
        return null;
    }
    FavoritesTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
    if (descriptors.length > 0) {
        List<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
        for (FavoritesTreeNodeDescriptor descriptor : descriptors) {
            nodes.add(descriptor.getElement());
        }
        return myFavoritesTreeStructure.getDataFromProviders(nodes, dataId);
    }
    return null;
}

From source file:com.intellij.ide.impl.DataManagerImpl.java

License:Apache License

private void registerRules() {
    myDataConstantToRuleMap.put(PlatformDataKeys.COPY_PROVIDER.getName(), new CopyProviderRule());
    myDataConstantToRuleMap.put(PlatformDataKeys.CUT_PROVIDER.getName(), new CutProviderRule());
    myDataConstantToRuleMap.put(PlatformDataKeys.PASTE_PROVIDER.getName(), new PasteProviderRule());
    myDataConstantToRuleMap.put(PlatformDataKeys.FILE_TEXT.getName(), new FileTextRule());
    myDataConstantToRuleMap.put(PlatformDataKeys.FILE_EDITOR.getName(), new FileEditorRule());
    myDataConstantToRuleMap.put(CommonDataKeys.NAVIGATABLE_ARRAY.getName(), new NavigatableArrayRule());
    myDataConstantToRuleMap.put(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE.getName(), new InactiveEditorRule());
}

From source file:com.intellij.ide.navigationToolbar.NavBarPanel.java

License:Apache License

@Override
@Nullable//from w w  w . ja  v  a  2  s.  co m
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return !myProject.isDisposed() ? myProject : null;
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        final Module module = getSelectedElement(Module.class);
        if (module != null && !module.isDisposed())
            return module;
        final PsiElement element = getSelectedElement(PsiElement.class);
        if (element != null) {
            return ModuleUtilCore.findModuleForPsiElement(element);
        }
        return null;
    }
    if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
        final PsiDirectory directory = getSelectedElement(PsiDirectory.class);
        if (directory != null) {
            final VirtualFile dir = directory.getVirtualFile();
            if (ProjectRootsUtil.isModuleContentRoot(dir, myProject)) {
                return ModuleUtilCore.findModuleForPsiElement(directory);
            }
        }
        return null;
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement element = getSelectedElement(PsiElement.class);
        return element != null && element.isValid() ? element : null;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        final List<PsiElement> elements = getSelectedElements(PsiElement.class);
        if (elements == null || elements.isEmpty())
            return null;
        List<PsiElement> result = new ArrayList<PsiElement>();
        for (PsiElement element : elements) {
            if (element != null && element.isValid()) {
                result.add(element);
            }
        }
        return result.isEmpty() ? null : result.toArray(new PsiElement[result.size()]);
    }

    if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        PsiElement[] psiElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
        if (psiElements == null)
            return null;
        Set<VirtualFile> files = new LinkedHashSet<VirtualFile>();
        for (PsiElement element : psiElements) {
            PsiFile file = element.getContainingFile();
            if (file != null) {
                final VirtualFile virtualFile = file.getVirtualFile();
                if (virtualFile != null) {
                    files.add(virtualFile);
                }
            } else if (element instanceof PsiFileSystemItem) {
                files.add(((PsiFileSystemItem) element).getVirtualFile());
            }
        }
        return !files.isEmpty() ? VfsUtilCore.toVirtualFileArray(files) : null;
    }

    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        final List<Navigatable> elements = getSelectedElements(Navigatable.class);
        return elements == null || elements.isEmpty() ? null
                : elements.toArray(new Navigatable[elements.size()]);
    }

    if (PlatformDataKeys.CONTEXT_COMPONENT.is(dataId)) {
        return this;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return getSelectedElement(Module.class) != null ? myDeleteModuleProvider
                : new DeleteHandler.DefaultDeleteProvider();
    }

    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }

    return null;
}

From source file:com.intellij.ide.scopeView.ScopeTreeViewPanel.java

License:Apache License

@Nullable
public Object getData(String dataId) {
    if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
        final TreePath selectionPath = myTree.getSelectionPath();
        if (selectionPath != null) {
            PackageDependenciesNode node = (PackageDependenciesNode) selectionPath.getLastPathComponent();
            if (node instanceof ModuleNode) {
                return ((ModuleNode) node).getModule();
            }/*w w  w . j a  v  a  2 s .c  om*/
        }
    }
    if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
        final TreePath selectionPath = myTree.getSelectionPath();
        if (selectionPath != null) {
            PackageDependenciesNode node = (PackageDependenciesNode) selectionPath.getLastPathComponent();
            return node != null && node.isValid() ? node.getPsiElement() : null;
        }
    }
    final TreePath[] treePaths = myTree.getSelectionPaths();
    if (treePaths != null) {
        if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
            Set<PsiElement> psiElements = new HashSet<PsiElement>();
            for (TreePath treePath : treePaths) {
                final PackageDependenciesNode node = (PackageDependenciesNode) treePath.getLastPathComponent();
                if (node.isValid()) {
                    final PsiElement psiElement = node.getPsiElement();
                    if (psiElement != null) {
                        psiElements.add(psiElement);
                    }
                }
            }
            return psiElements.isEmpty() ? null : PsiUtilBase.toPsiElementArray(psiElements);
        }
    }
    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        if (getSelectedModules() != null) {
            return myDeleteModuleProvider;
        }
        return myDeletePSIElementProvider;
    }
    if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
        final TreePath selectionPath = myTree.getSelectionPath();
        if (selectionPath != null) {
            final Object pathComponent = selectionPath.getLastPathComponent();
            if (pathComponent instanceof DirectoryNode) {
                return ((DirectoryNode) pathComponent).getTargetDirectory();
            }
        }
    }
    return null;
}