Search in sources :

Example 1 with TodoFileNode

use of com.intellij.ide.todo.nodes.TodoFileNode in project intellij-community by JetBrains.

the class TodoPanel method getData.

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        TreePath path = myTree.getSelectionPath();
        if (path == null) {
            return null;
        }
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object userObject = node.getUserObject();
        if (!(userObject instanceof NodeDescriptor)) {
            return null;
        }
        Object element = ((NodeDescriptor) userObject).getElement();
        if (!(element instanceof TodoFileNode || element instanceof TodoItemNode)) {
            // allow user to use F4 only on files an TODOs
            return null;
        }
        TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
        if (pointer != null) {
            return new OpenFileDescriptor(myProject, pointer.getValue().getTodoItem().getFile().getVirtualFile(), pointer.getValue().getRangeMarker().getStartOffset());
        } else {
            return null;
        }
    } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
        final PsiFile file = getSelectedFile();
        return file != null ? file.getVirtualFile() : null;
    } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        return getSelectedElement();
    } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        PsiFile file = getSelectedFile();
        if (file != null) {
            return new VirtualFile[] { file.getVirtualFile() };
        } else {
            return VirtualFile.EMPTY_ARRAY;
        }
    } else if (PlatformDataKeys.HELP_ID.is(dataId)) {
        //noinspection HardCodedStringLiteral
        return "find.todoList";
    }
    return super.getData(dataId);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TodoFileNode(com.intellij.ide.todo.nodes.TodoFileNode) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiFile(com.intellij.psi.PsiFile) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode)

Aggregations

TodoFileNode (com.intellij.ide.todo.nodes.TodoFileNode)1 TodoItemNode (com.intellij.ide.todo.nodes.TodoItemNode)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiFile (com.intellij.psi.PsiFile)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1